TResNet-34 Batch Implementation with Joined Keys

This page demonstrates the TResNet-34 batch inference workflow with joined keys optimization using FHEON. It provides an example of how to perform encrypted-domain batch inference on CIFAR-100 images using ResNet-34 with key joining strategies for improved performance on the deeper architecture but this also comes with a higher memory usage.

Overview

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

  1. Context and Key Generation with Joins

    • Initializes the FHEONHEController with batch-optimized parameters for ResNet-34.

    • Generates and joins rotation keys for complex convolutional operations.

    • Serializes optimized key structures for efficient batch FHE computations.

  2. Batch Data Preparation

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

    • Encrypts batch image data for inference.

  3. TResNet-34 Blocks with Key Optimization

    • Implements convolutional blocks optimized for joined key operations on the deeper architecture.

    • 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-34 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:

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

  • TResNet34N128P2.cpp – Batch processing with N=128 and P=2 parameter variant

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.

  • double_shortcut_convolution_block() – Deep architecture shortcuts with key optimization.

  • 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:

TResNet34N16JoinedKeys.cpp