Giter Site home page Giter Site logo

microsoft / cryptonets Goto Github PK

View Code? Open in Web Editor NEW
281.0 13.0 69.0 35.78 MB

CryptoNets is a demonstration of the use of Neural-Networks over data encrypted with Homomorphic Encryption. Homomorphic Encryptions allow performing operations such as addition and multiplication over data while it is encrypted. Therefore, it allows keeping data private while outsourcing computation (see here and here for more about Homomorphic E

License: MIT License

C# 100.00%
homomorphic-encryptions data-encrypted neural-networks seal

cryptonets's Issues

Question about input image padding

The original CryptoNets paper mentions that padding is applied to the input image for the first network layer. The paper describes this padding as occurring in the upper and left parts of the image. However, it seems like this library adds padding to the lower and right sides instead (even though the padding is set in a field called 'Upperpadding').

Could you please confirm that I am correct in my understanding? I am wondering if I am missing something or if this is just a mistake in the library.

'error budget is zero' exception & noise budget reduction in different encryption parameters

Dear authors,

Thanks very much for your released codes. Could I ask you two questions as follows?

  1. I met the 'error budget is zero' exception in running CryptoNets codes.

  2. Could you help me with how to use CryptoTracker in your codes to track one operation's noise budget reduction? My target is to know the noise budget reduction for each operation under different degrees N and the number of plaintext modulus. Could you kindly give me any ideas on how to implement my target?

Thanks in advance for your response.

CifarCryptoNet Data Processing

I have followed all instructions in README.md to process cifar-10-batches-bin data set. I am able to get the print result as README.md shows. However, there is no operation is seen when I run the program on the Debug version instead of the Release version.

To be sure, I put some fprintf functions to print the multiplication parameters in evaluater.cpp before creating the SEAL package. After that, I noticed the text file, produced for fprintf, exists when I run NeuralNetworksTest and HE Wrapper Tests with Visual Studio. Nevertheless, I cannot see the text file when I follow the DataPreprocess.exe and .\CifarCryptoNets.exe -v commands. Also, results are always the same given by:

Destructor 0
Encryption 0
Plain 0
Decryption 0
Multiplication 0
PlainMultiplication 0
Addition 0
Dispose 0
PlainAddition 0
Subtraction 0
PlainSubtraction 0
Rotation 0
AddMany 0
AddManyItemCount 0
Relinarization 0

These are some output from Release mode:

errs 33/160 accuracy 79.375% prediction 4 label 4 Inference-Time 43.87ms 2^76.939503250388 largest-value
errs 33/161 accuracy 79.503% prediction 2 label 2 Inference-Time 43.86ms 2^76.939503250388 largest-value
errs 33/162 accuracy 79.630% prediction 1 label 1 Inference-Time 44.22ms 2^76.939503250388 largest-value
errs 33/163 accuracy 79.755% prediction 6 label 6 Inference-Time 44.22ms 2^76.939503250388 largest-value
errs 33/164 accuracy 79.878% prediction 6 label 6 Inference-Time 44.22ms 2^76.939503250388 largest-value
errs 34/165 accuracy 79.394% prediction 0 label 8 Inference-Time 44.22ms 2^76.939503250388 largest-value
errs 34/166 accuracy 79.518% prediction 4 label 4 Inference-Time 44.22ms 2^76.939503250388 largest-value

Thanks,

Project not working with SEAL version 3.3.1

The whole project is designed for SEAL 3.2.0. But SEAL library has been recently updated to 3.3.1/3.3.2 either of the 2 version( when i downloaded and installed SEAL from github, NuGet package of SEAL 3.3.1 was created). After following the instructions , i was only able to preprocess the data after building the project since after compiling the project , only DataPreprocess.exe is available (not CrytoNets.exe , BasicExample.exe, Caltech101.exe etc).Also, some dll files were missing.Prior to building it, i had added the Nuget package of SEAL 3.3.1 reference to the project .I had changed the version of the 'HE Wrapper and 'HE Wrapper Tests' to 3.3.1 from 3.2.0 in their 'packages.config' files to see if it helps but it didn't . Can sth
be done regarding this or can i somehow get the SEAL version 3.2.0 to run this project ? Thanks in advance.Below is the pic of whats happening currently
w1
w2
e1
e2
HE wrapper tests
HE wrapper

the scaled mean pool layer of cryptonets

From the description of the cryptonets, we find the input of layer 3 is 5 * 13 * 13,and the output of the layer 3 is also 5 * 13 * 13. But the windows is 1 * 3 * 3, and ther is no padding and stride declaration. why the output of layer 3 is 5 * 13 * 13? why the output of pool layer won`t be smaller?
image

Is there any example of training code with mnist data?

Sorry for this simple question. I resently know about neural networks and then find your great project. Unfortunately, i'm a newcomer to this area and i have a duty to create my own cryptonet with my datasets which are 128*128 grayscale images. So i think maybe an example of training code with mnist data can be helpful. If you have the code, could you please share to me? Thank you very much!

how to add an encrypted PNG image to the code ?

I want to do DL to an encrypted PNG image, I followed the ReadMe. File but I found a problem starting from prepressing data.
how can I add the image to be processed by the code ?
from which file should I start and where to put the image ?

I world be grateful if anyone can help ..
its important to complete my project
thank you

Unable to Datapreprocess CAL dataset

I have executed DataPreprocess.exe for CAL dataset as you said to prepare CAL dataset for LoLa.

(Cryptonet root directory)\bin\x64\Release> .\DataPreprocess.exe CAL 

Then I yielded System.IndexOutOfRangeException.

Unhandled Exception: System.IndexOutOfRangeException: Index out of array range.
   위치: DataPreprocess.GetCAL.Run(String[] args) 파일 C:\Users\ohsai\Desktop\Workspace\CryptoNets\DataPreprocess\GetCAL.cs:줄 0
   위치: DataPreprocess.DataPreprocess.Main(String[] args) 파일 C:\Users\ohsai\Desktop\Workspace\CryptoNets\DataPreprocess\DataPreprocess.cs:줄 18

So I thought additional arguments for the program were necessary, so I looked at the GetCAL.cs to find out that second argument should be .tsv file and third argument should be the folder which contains all the images of Caltech-101 dataset.

So I have downloaded Caltech-101 image dataset and placed it in (Cryptonet root directory)\bin\x64\Release folder as a folder name of "CALObjectCategories",

(Cryptonet root directory)\bin\x64\Release> ls .\CALObjectCategories\

    디렉터리: 
(Cryptonet root directory)\bin\x64\Release\CALObjectCategories


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----     2019-08-07   오전 5:31                accordion
d-----     2019-08-07   오전 5:31                airplanes
.
.
.

and executed following command.

(Cryptonet root directory)\bin\x64\Release>.\DataPreprocess.exe CAL ".\cal_train.tsv" ".\CALObjectCategories\"

But It failed to process all the images, printing

failure on line ant/image_0013.jpg	4

faliure message for all the files.

So I tried to find out what caused the exception, and printed stacktrace for all try catch syntaxes on GetCAL.cs file.

Then only this exception stack trace was printed.

 location: Microsoft.ML.Transforms.OnnxTransformer..ctor(IHostEnvironment env, Options options, Byte[] modelBytes)
   location: Microsoft.ML.Transforms.AlexNetExtension.AlexNet(DnnImageModelSelector dnnModelContext, IHostEnvironment env, String outputColumnName, String inputColumnName, String modelDir)
   location: Microsoft.ML.Transforms.AlexNetExtension.AlexNet(DnnImageModelSelector dnnModelContext, IHostEnvironment env, String outputColumnName, String inputColumnName)
  location: Microsoft.ML.Transforms.DnnImageFeaturizerEstimator..ctor(IHostEnvironment env, String outputColumnName, Func`2 modelFactory, String inputColumnName)
   location: DataPreprocess.GetCAL._Run(String imagesCatalog, String imagesFolder) 파일 C:\Users\ohsai\Desktop\Workspace\CryptoNets\DataPreprocess\GetCAL.cs:line 93
   location: DataPreprocess.GetCAL._Run_failover(String line, String imagesFolder) 파일 C:\Users\ohsai\Desktop\Workspace\CryptoNets\DataPreprocess\GetCAL.cs:line58

So, my question is,

  1. Is this the right way to fetch and preprocess CAL dataset? You said to fetch CAL dataset first by following the instruction after the first .\DataPreprocess.exe CAL, but it did not gave the instruction at all.
  2. If it is, how should I deal with this error? From the exception stacktrace, I think the error comes from Microsoft.ML.Transforms module.

Issue with building

Hello, I am using SEAL 3.2.2 and running into some issues. This is what I encountered when trying to compile Cryptonets for the first time. I have installed all the packages that were originally missing but I'm not sure whether the repo is missing some dll files. Any help would be appreciated!

seal

[Help Wanted] Is CifarCryptoNets Functional? Low Accuracy with Small Test

I was able to reproduce the output provided for CifarCryptoNets. I believe they are the prediction values for the 10 categories in Cifar-10 and that the max value is the prediction.

I tested the model separately with the full Cifar-10 dataset and with 1 test image from the dataset and produced the same output which, I believe, is because the code doesn't loop through the network with the GetNext() method like the other provided models.

After iterating through 10 test images and took the max value as the prediction as displayed below, I noticed that the accuracy based on my approach is roughly around 10% instead of the higher accuracy expected of LoLaCryptoNet.

Is the CifarCryptoNet fully functional? Please advise.

# Prediction output for the first 10 images of the Cifar-10 dataset. 
0: -14.9947
1: -13.1457
2: 12.7913
3: 8.6813
4: 12.8255
5: -3.2621
6: 0.7135
7: 4.8243
8: -14.3768
9: -7.1885
Prediction 4 Label 3
0: -8.2010
1: -3.6772
2: 0.1281
3: 10.1785
4: -10.3159
5: -13.5987
6: -7.4372
7: -14.5098
8: -15.4177
9: -5.1588
Prediction 3 Label 8
0: 4.5273
1: 11.4319
2: -8.0989
3: 11.5048
4: -12.1562
5: 14.9259
6: 15.8742
7: -4.1455
8: 9.8287
9: 10.6513
Prediction 6 Label 8
0: 14.2459
1: -11.5474
2: 8.2095
3: -13.5229
4: -7.3236
5: 4.1504
6: -14.8993
7: -12.6799
8: -9.5187
9: -11.7253
Prediction 0 Label 0
0: -2.7235
1: -7.0029
2: 13.5247
3: -13.9630
4: 15.9141
5: 6.9853
6: -13.9143
7: -7.6527
8: -0.7338
9: 10.5105
Prediction 4 Label 6
0: 4.4299
1: -5.5504
2: -8.3946
3: 2.4063
4: 6.1031
5: -10.7999
6: -9.1229
7: 3.5830
8: -5.5245
9: -5.6314
Prediction 4 Label 6
0: -14.3356
1: 4.2231
2: 15.7832
3: 5.4311
4: 3.8572
5: 5.8699
6: -13.2955
7: -11.3057
8: 8.0676
9: -2.4369
Prediction 2 Label 1
0: 11.9822
1: 5.2481
2: -12.5903
3: 5.4623
4: 2.8625
5: 8.3463
6: -3.1007
7: 0.5379
8: -11.2521
9: -8.9174
Prediction 0 Label 6
0: 13.6397
1: -14.8832
2: -9.6858
3: 5.0069
4: -7.6892
5: 2.1170
6: 4.9055
7: 9.6919
8: -4.4410
9: 2.3507
Prediction 0 Label 3
0: 0.9694
1: -13.4114
2: -3.8784
3: -8.0430
4: 3.8281
5: -2.8454
6: 13.5963
7: 2.3001
8: 0.8784
9: -1.7873
Prediction 6 Label 1
Accuracy: 1/10

Hello,I meet a problem when I installed the CryptoNets!

Hello, when I installed the CryptoNets I meet an error that error CS0234 The type or namespace name 'research' does not exist in namespace 'Microsoft' (missing assembly reference?) HE Wrapper, and I can't solve this problem.

Running on other datasets

Hello,
So ,we know that the CryptoNets project is trained with MNIST dataset and works on currently 3 different datasets namely MNIST, CIFAR-10 and CALTECH-101.
My question is , can it run on any other datasets?. I am having my own dataset and want to train the CrytoNets model with it and run the model. So, is there any way to do it ? Thank you

Running the application using CKKS scheme other than BFV

Hello,

I had a confusion regarding the 'Selecting the encryption parameters' section. Is the code given in this section for 'BFV scheme' only or we can use it for 'CKKS scheme' as well? If it is for 'CKKS scheme' too, will changing the line var Factory = new RawFactory((ulong)batchSize); // we start without using encryption to var Factory = new EncryptedSealCkksFactory(new ulong[] { 957181001729, 957181034497 }, 16384); help in this case ?

Another thing is that the accuracy for running 'CIFAR-10' dataset with encryption is 76.318 % whilst if i run the cnn model for the dataset that i've jst built is 78.12 %. Can you please explain the reason for it ?

Thank you

How to create 'test.txt' ?

Sorry to bother you but I want to know how to create the 'test.txt' in the code of chapter 'creating the application' in wiki pages. Since I just got in touch with this project and deep learning, maybe my question is very simple. Please don't mind and thank you for your patience and contributions.

Cryptonet MNIST training script

Hello,
I am trying to train the model from the original cryptonet paper and I am facing issues in even making the model in keras. For example: For the first 3 layers:
model = Sequential()
model.add(Conv2D(filters=5, kernel_size=(5, 5),strides=(2,2),input_shape=(28,28,1), padding = 'same'))
model.add(Activation(square))
model.add(AveragePooling2D(pool_size=(2,2)))

And the output shape:


Layer (type) Output Shape Param #

conv2d_8 (Conv2D) (None, 14, 14, 5) 130


activation_13 (Activation) (None, 14, 14, 5) 0


average_pooling2d_7 (Average (None, 7, 7, 5) 0


Which does not match the paper. Also could you please tell me the optimizer you used? Because I am always getting 'nan' loss when I have a square activation layer involved

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.