TResNet-20 Batch Implementations with Joined Keys

This page demonstrates the TResNet-20 batch inference workflow with joined keys optimization using FHEON. It provides exampleS of how to perform encrypted-domain batch inference on CIFAR-10 images using ResNet-20 with key joining strategies for improved performance but higher memory usage.

Overview

This variant extends the standard batch ResNet-20 implementation with joined keys optimization, which combines multiple rotation keys to reduce memory overhead and improve computational efficiency during batch processing.

  1. Context and Key Generation with Joins

    • Initializes the FHEONHEController with batch-optimized parameters.

    • Generates and joins rotation keys for convolutional operations.

    • Serializes optimized key structures for efficient batch FHE computations.

  2. Batch Data Preparation

    • Reads and preprocesses multiple CIFAR-10 images in batch.

    • Encrypts batch image data for inference.

  3. TResNet-20 Blocks with Key Optimization

    • Implements convolutional blocks optimized for joined key operations.

    • Handles shortcut connections using the joined key strategy.

    • Applies batch ReLU and pooling operations on encrypted data.

    • Implements fully connected layers for batch classification.

  4. Batch Inference Loop

    • Processes multiple input images simultaneously with key joining optimizations.

    • Applies the ResNet-20 layers sequentially to the batch.

    • Performs encrypted global average pooling and fully connected classification.

    • Provides improved performance through reduced key overhead.

Key Joining Configurations

Available variants with joined keys optimization:

  • TResNet20N16JoinedKeys.cpp – Batch processing with N=16 and joined key optimization

  • TResNet20N64JoinedKeys.cpp – Batch processing with N=64 and joined key optimization

  • TResNet20N256JoinedKeys.cpp – Batch processing with N=256 and joined key optimization

Key Functions

The main functions used in the example include:

  • convolution_block() – Performs convolutional layer with joined key operations.

  • shortcut_convolution_block() – Handles shortcuts optimized for joined keys.

  • resnet_block() – Combines operations with joined key strategy.

  • fc_layer_block() – Implements fully connected layer with key-optimized operations.

Full Example Source

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

TResNet20N16JoinedKeys.cpp

TResNet20N64JoinedKeys.cpp

TResNet20N256JoinedKeys.cpp