BResNet-34 Batch Implementation with Joined Keys
This page demonstrates the ResNet-34 batch inference workflow with joined keys: the same network as BResNet-34 Batch Implementations, with all the rotation keys generated once and kept in memory.
Overview
The workflow includes:
Context and Key Generation
Initializes the
FHEONHEControllerwith 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.
Batch Data Preparation
Reads and preprocesses a batch of CIFAR-100 images.
Encrypts one ciphertext per channel (image after image) and converts it to the batch layout (
he_batch_inputs_converter_memory_efficient).
ResNet-34 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).
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
BResNet34N16JoinedKeys.cpp – batch of 16 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_memory_efficient), after the global average pooling (he_batch_globalpool).
Full Example Source
You can view and download the full source code of these examples: