Home

Awesome

Privacy-Preserving Neural Style Transfer

This repo contains the implementation of the Neural Style Transfer algorithm in a privacy-preserving way. We use FHE(Fully Homomorphic Encryption) scheme to perform image style-transfer on encrypted images. This repository consists of -

We have created a FHE-compatible style transfer model from a pre-trained model using Concrete-ML. Concrete-ML uses TFHE encryption scheme internally. To learn the details about the implementaion of privacy-preserving style transfer, please refer to the [Private Style Transfer](Private Style Transfer.ipynb) notebook.

Pre-processing and post-processing steps -

Few of the decisions taken to solve image style transfer problem within FHE/Concrete ML constraints-

Hack used to fix to some bug in Concrete ML/ONNX that can't infer size of x dynamically

While compiling a torch model using Concrete-ML, if we try to infer the shape of the input x and use it as a value, we encounter a weird issue. Somehow, after ONNX export of the model, the value of x.shape is not properly propagated. To fix this issue, we had to manually hard-code variables that use dimension of the input. We have done this for two layers of our model that require upsampling.Here is the code snippet that does the fix -

if x.shape[1] == 32:
    batch_size, channels, height, width = (1, 32, 8, 8)
else:
    batch_size, channels, height, width = (1, 16, 16, 16)