BResNet-20 Batch Implementations with Joined Keys

This page demonstrates the ResNet-20 batch inference workflow with joined keys: the same network as BResNet-20 Batch Implementations, with all the rotation keys generated once and kept in memory.

Overview

The workflow includes:

  1. Context and Key Generation

    • Initializes the FHEONHEController with the ring dimension, number of slots, circuit depth and scaling factors.

    • Generates all the rotation keys into a single key set that stays in memory for the whole inference: no key file is reloaded between the stages, at the cost of more memory than the per-stage variants.

  2. Batch Data Preparation

    • Reads and preprocesses a batch of CIFAR-10 images.

    • Encrypts one ciphertext per channel (image after image) and converts it to the batch layout (he_batch_inputs_converter_memory_efficient).

  3. ResNet-20 Blocks

    • Convolution blocks, residual blocks with identity shortcuts and stride-2 blocks with 1x1 shortcut convolutions, with the multithreaded FHEONANNStandardBatchThreadedController (see FHEON’s Controllers).

    • Batch ReLU and bootstrapping of all the channels of a layer (batch_bootstrap_function).

  4. Classification

    • Encrypted global average pooling and the fully connected layer for the whole batch.

    • Decrypts the batch results and writes the predicted labels.

Batch Configurations

  • BResNet20N16JoinedKeys.cpp – batch of 16 images, joined keys (source only: not in the CMake target list)

  • BResNet20N64JoinedKeys.cpp – batch of 64 images, joined keys

  • BResNet20N256JoinedKeys.cpp – batch of 256 images, joined keys

Key Functions

The main functions used in the examples include:

  • convolution_block() – Batch 3x3 convolution (he_batch_convolution_optimized), stride 1 or 2.

  • shortcut_convolution_block() – 1x1 stride-2 shortcut convolution (he_batch_convolution_shortcut_optimized).

  • resnet_block() – A basic block: two convolutions with bootstrapping and batch ReLU, the identity or 1x1 shortcut, and the residual sum (he_batch_sum_ciphertexts).

  • fc_layer_block() – Fully connected layer of the whole batch (he_batch_linear), after the global average pooling (he_batch_globalpool).

Full Example Source

You can view and download the full source code of these examples:

BResNet20N16JoinedKeys.cpp

BResNet20N64JoinedKeys.cpp

BResNet20N256JoinedKeys.cpp