BResNet-34 Batch Implementations
This page demonstrates the ResNet-34 batch inference workflow using FHEON: encrypted-domain inference on a batch of CIFAR-100 images, with every ciphertext holding one channel of the whole batch.
Overview
The workflow includes:
Context and Key Generation
Initializes the
FHEONHEControllerwith the ring dimension, number of slots, circuit depth and scaling factors.Generates one key file per stage (
layer1.bin,layer2.bin, …, the input converter and the fully connected layer), each with exactly the rotations of its layers and the bootstrapping keys of its slot count; only the keys of the current stage are loaded during the inference.
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
BResNet34N16.cpp – batch of 16 images
BResNet34N32.cpp – batch of 32 images
BResNet34N64.cpp – batch of 64 images
BResNet34N128.cpp – batch of 128 images
BResNet34N128P2.cpp – batch of 128 images on ring 2^16 (32768 slots), one logits ciphertext per image
BResNet34N256.cpp – batch of 256 images
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: