Commit
·
a13c444
1
Parent(s):
75bc44e
Update Concrete ML version and re-generate development files
Browse files- client_server_interface.py +9 -15
- filters.py +1 -1
- filters/black and white/deployment/client.zip +2 -2
- filters/black and white/deployment/server.zip +2 -2
- filters/blur/deployment/client.zip +2 -2
- filters/blur/deployment/server.zip +2 -2
- filters/identity/deployment/client.zip +2 -2
- filters/identity/deployment/server.zip +2 -2
- filters/inverted/deployment/client.zip +2 -2
- filters/inverted/deployment/server.zip +2 -2
- filters/ridge detection/deployment/client.zip +2 -2
- filters/ridge detection/deployment/server.zip +2 -2
- filters/rotate/deployment/client.zip +2 -2
- filters/rotate/deployment/server.zip +2 -2
- filters/sharpen/deployment/client.zip +2 -2
- filters/sharpen/deployment/server.zip +2 -2
- requirements.txt +1 -3
client_server_interface.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
"Client-server interface custom implementation for filter models."
|
| 2 |
|
| 3 |
-
|
| 4 |
|
| 5 |
from filters import Filter
|
| 6 |
|
|
@@ -17,7 +17,7 @@ class FHEServer:
|
|
| 17 |
self.path_dir = path_dir
|
| 18 |
|
| 19 |
# Load the FHE circuit
|
| 20 |
-
self.server =
|
| 21 |
|
| 22 |
def run(self, serialized_encrypted_image, serialized_evaluation_keys):
|
| 23 |
"""Run the filter on the server over an encrypted image.
|
|
@@ -30,20 +30,14 @@ class FHEServer:
|
|
| 30 |
bytes: The filter's output.
|
| 31 |
"""
|
| 32 |
# Deserialize the encrypted input image and the evaluation keys
|
| 33 |
-
encrypted_image =
|
| 34 |
-
|
| 35 |
-
)
|
| 36 |
-
evaluation_keys = cnp.EvaluationKeys.unserialize(serialized_evaluation_keys)
|
| 37 |
|
| 38 |
# Execute the filter in FHE
|
| 39 |
-
encrypted_output = self.server.run(
|
| 40 |
-
encrypted_image, evaluation_keys
|
| 41 |
-
)
|
| 42 |
|
| 43 |
# Serialize the encrypted output image
|
| 44 |
-
serialized_encrypted_output =
|
| 45 |
-
encrypted_output
|
| 46 |
-
)
|
| 47 |
|
| 48 |
return serialized_encrypted_output
|
| 49 |
|
|
@@ -98,7 +92,7 @@ class FHEClient:
|
|
| 98 |
assert path_dir.exists(), f"{path_dir} does not exist. Please specify a valid path."
|
| 99 |
|
| 100 |
# Load the client
|
| 101 |
-
self.client =
|
| 102 |
|
| 103 |
# Instantiate the filter
|
| 104 |
self.filter = Filter(filter_name)
|
|
@@ -132,7 +126,7 @@ class FHEClient:
|
|
| 132 |
encrypted_image = self.client.encrypt(input_image)
|
| 133 |
|
| 134 |
# Serialize the encrypted image to be sent to the server
|
| 135 |
-
serialized_encrypted_image =
|
| 136 |
return serialized_encrypted_image
|
| 137 |
|
| 138 |
def deserialize_decrypt_post_process(self, serialized_encrypted_output_image):
|
|
@@ -145,7 +139,7 @@ class FHEClient:
|
|
| 145 |
numpy.ndarray: The decrypted, deserialized and post-processed image.
|
| 146 |
"""
|
| 147 |
# Deserialize the encrypted image
|
| 148 |
-
encrypted_output_image =
|
| 149 |
serialized_encrypted_output_image
|
| 150 |
)
|
| 151 |
|
|
|
|
| 1 |
"Client-server interface custom implementation for filter models."
|
| 2 |
|
| 3 |
+
from concrete import fhe
|
| 4 |
|
| 5 |
from filters import Filter
|
| 6 |
|
|
|
|
| 17 |
self.path_dir = path_dir
|
| 18 |
|
| 19 |
# Load the FHE circuit
|
| 20 |
+
self.server = fhe.Server.load(self.path_dir / "server.zip")
|
| 21 |
|
| 22 |
def run(self, serialized_encrypted_image, serialized_evaluation_keys):
|
| 23 |
"""Run the filter on the server over an encrypted image.
|
|
|
|
| 30 |
bytes: The filter's output.
|
| 31 |
"""
|
| 32 |
# Deserialize the encrypted input image and the evaluation keys
|
| 33 |
+
encrypted_image = fhe.Value.deserialize(serialized_encrypted_image)
|
| 34 |
+
evaluation_keys = fhe.EvaluationKeys.deserialize(serialized_evaluation_keys)
|
|
|
|
|
|
|
| 35 |
|
| 36 |
# Execute the filter in FHE
|
| 37 |
+
encrypted_output = self.server.run(encrypted_image, evaluation_keys=evaluation_keys)
|
|
|
|
|
|
|
| 38 |
|
| 39 |
# Serialize the encrypted output image
|
| 40 |
+
serialized_encrypted_output = encrypted_output.serialize()
|
|
|
|
|
|
|
| 41 |
|
| 42 |
return serialized_encrypted_output
|
| 43 |
|
|
|
|
| 92 |
assert path_dir.exists(), f"{path_dir} does not exist. Please specify a valid path."
|
| 93 |
|
| 94 |
# Load the client
|
| 95 |
+
self.client = fhe.Client.load(self.path_dir / "client.zip", self.key_dir)
|
| 96 |
|
| 97 |
# Instantiate the filter
|
| 98 |
self.filter = Filter(filter_name)
|
|
|
|
| 126 |
encrypted_image = self.client.encrypt(input_image)
|
| 127 |
|
| 128 |
# Serialize the encrypted image to be sent to the server
|
| 129 |
+
serialized_encrypted_image = encrypted_image.serialize()
|
| 130 |
return serialized_encrypted_image
|
| 131 |
|
| 132 |
def deserialize_decrypt_post_process(self, serialized_encrypted_output_image):
|
|
|
|
| 139 |
numpy.ndarray: The decrypted, deserialized and post-processed image.
|
| 140 |
"""
|
| 141 |
# Deserialize the encrypted image
|
| 142 |
+
encrypted_output_image = fhe.Value.deserialize(
|
| 143 |
serialized_encrypted_output_image
|
| 144 |
)
|
| 145 |
|
filters.py
CHANGED
|
@@ -5,7 +5,7 @@ import torch
|
|
| 5 |
from torch import nn
|
| 6 |
from common import AVAILABLE_FILTERS, INPUT_SHAPE
|
| 7 |
|
| 8 |
-
from concrete.
|
| 9 |
from concrete.ml.common.utils import generate_proxy_function
|
| 10 |
from concrete.ml.torch.numpy_module import NumpyModule
|
| 11 |
|
|
|
|
| 5 |
from torch import nn
|
| 6 |
from common import AVAILABLE_FILTERS, INPUT_SHAPE
|
| 7 |
|
| 8 |
+
from concrete.fhe.compilation.compiler import Compiler
|
| 9 |
from concrete.ml.common.utils import generate_proxy_function
|
| 10 |
from concrete.ml.torch.numpy_module import NumpyModule
|
| 11 |
|
filters/black and white/deployment/client.zip
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:2f224e21a8a189c8b9431de533c3401f174fe97f455b347309256d5c61c91c2f
|
| 3 |
+
size 348
|
filters/black and white/deployment/server.zip
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6811bb8621f87ceb1c7eaa18439daabe0400d3f206e6fb7d034b7258ab3f47e7
|
| 3 |
+
size 5120
|
filters/blur/deployment/client.zip
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:784113c8aa6256ae136dcdcef246eb726c0a30a7bf79f91fc458e13cfdaeed66
|
| 3 |
+
size 360
|
filters/blur/deployment/server.zip
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:fc03fc47e2f1c4ddedcf9e0dd9c46890b79e0de5c75bc3523c0be9eb504fc544
|
| 3 |
+
size 7356
|
filters/identity/deployment/client.zip
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e2ff4b6d075e418d6577f88fe77e580949023837708a52cd377fa4388d38ad1f
|
| 3 |
+
size 347
|
filters/identity/deployment/server.zip
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e5a2cd8e175ff9b99dc1b9700884ae40c24afc7375005833f7410dcd73f0cfee
|
| 3 |
+
size 2818
|
filters/inverted/deployment/client.zip
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e2ff4b6d075e418d6577f88fe77e580949023837708a52cd377fa4388d38ad1f
|
| 3 |
+
size 347
|
filters/inverted/deployment/server.zip
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:eb99ecacca176c7f5cca0fbf577af46495e028074169495aa3f6af5beafa1855
|
| 3 |
+
size 4026
|
filters/ridge detection/deployment/client.zip
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b6d461d356570d465d012715048d824b76b31668d80678e5e5083e9c8a93e6e6
|
| 3 |
+
size 369
|
filters/ridge detection/deployment/server.zip
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0275c0bc7fbc90b19ccc16b87d220fd9be72cef303775245725845b1f1f918d7
|
| 3 |
+
size 6082
|
filters/rotate/deployment/client.zip
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e2ff4b6d075e418d6577f88fe77e580949023837708a52cd377fa4388d38ad1f
|
| 3 |
+
size 347
|
filters/rotate/deployment/server.zip
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:dfc258c33a41a748949729e0a443c7f667b1b5b52db43966d2e8257979a82b36
|
| 3 |
+
size 3831
|
filters/sharpen/deployment/client.zip
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:63bdea70a18addfa2ee8667a6be682f4b9856b9776a707f2ecebe56359066897
|
| 3 |
+
size 369
|
filters/sharpen/deployment/server.zip
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0635f6e814ad6a55806d93d804afea95c264b30c08dc81b110d4a8b348b701f9
|
| 3 |
+
size 7891
|
requirements.txt
CHANGED
|
@@ -1,4 +1,2 @@
|
|
| 1 |
-
concrete-ml==
|
| 2 |
gradio==3.11.0
|
| 3 |
-
uvicorn==0.20.0
|
| 4 |
-
fastapi==0.87.0
|
|
|
|
| 1 |
+
concrete-ml==1.1.0
|
| 2 |
gradio==3.11.0
|
|
|
|
|
|