narger-ef / LowMemoryFHEResNet20

Source code for the paper "Encrypted Image Classification with Low Memory Footprint using Fully Homomorphic Encryption"
https://eprint.iacr.org/2024/460
MIT License
34 stars 10 forks source link

Add bias of convbn after downsample #12

Closed minnow54426 closed 5 months ago

minnow54426 commented 5 months ago

Hello, I wonder whether bias of convbn can be added after downsample. For example, in block0 of layer2, the convbn1 layer changes the size of image from 32 to 16. According to the code, after A and b is calculated and organized properly, they are multiplied and added before downsample. Whether I can perform the following calculation:

  1. Perform the 16 in and 32 out conv, which transforms the size of image from 32 to 16 with A is integrated with kernel.
  2. Perform downsample, then get a ciphertext which encrypt a vector of length 8192 = 32 * 256.
  3. Deal with b with length 32, such that its length becomes 8192 with 32 blocks and every block with 256 elements, every block's 256 elements are same and the order of blocks is same as original b, then encode dealed b and add it to the conv result, which performed A already. I implemented this but there is something wrong with the result, Is there anything wrong? Thanks very much.