ResNet-20 With Multi-Channel Striding and Slot Management
This example demonstrates the ResNet-20 FHE pipeline with two main features:
Multi-channel striding – downsampling handled through combined convolution + shortcut blocks.
Dynamic slot switching – layers run at different slot sizes by clearing and reloading rotation/bootstrapping keys.
Overview
The workflow includes:
FHE Context and Key Generation
Initialize FHEController and ANNController.
Generate bootstrapping and rotation keys per layer with different slot values.
Data Preparation
Load convolution kernels, shortcut kernels, and fully connected weights.
Encode weights and biases for each block.
Multi-Channel Striding
Strided residual blocks are processed using
secure_double_optimized_convolution_multi_channels()for efficient conv + shortcut handling.
Slot Management
Before each major block (layer group or FC), contexts are cleared and reloaded with the correct slot size. This is adopted after every downsampling block.
Inference Loop
Encrypt CIFAR-10 images.
Apply convolution and residual blocks with striding + shortcut connections.
Dynamically adjust slot counts across layers.
Perform global average pooling and final FC layer for classification.
Key Functions
convolution_block()– Load and encode kernels, run optimized convolution.shortcut_convolution_block()– Encode shortcut kernels for downsampling.double_shortcut_convolution_block()– Perform strided convolution + shortcut in parallel (multi-channel).resnet_block()– Residual block with bootstrap, striding, shortcut, and secure ReLU.fc_layer_block()– Encode and apply the final fully connected layer.
Data Processing Functions
load_weights()– Load convolution kernels.load_fc_weights()– Load FC or shortcut kernels.load_bias()– Load bias vectors.Encoding handled by optimized FHE encoders (per conv/shortcut/FC).
Block Functions
convolution_block(...)– Single convolution + bias.shortcut_convolution_block(...)– Downsample shortcut branch.double_shortcut_convolution_block(...)– Conv + shortcut with striding.resnet_block(...)– Full residual block with ReLU and bootstrap.fc_layer_block(...)– Final FC classification layer.