mirror of
https://github.com/serengil/deepface.git
synced 2025-06-07 03:55:21 +00:00
Update README.md
phe snippet
This commit is contained in:
parent
72dc780abc
commit
76676ac51c
10
README.md
10
README.md
@ -381,13 +381,12 @@ Even though vector embeddings are not reversible to original images, they still
|
|||||||
```python
|
```python
|
||||||
from lightphe import LightPHE
|
from lightphe import LightPHE
|
||||||
|
|
||||||
# define a plain vectors for source and target
|
|
||||||
alpha = DeepFace.represent("img1.jpg")[0]["embedding"] # user tower
|
|
||||||
beta = DeepFace.represent("target.jpg")[0]["embedding"] # item tower
|
|
||||||
|
|
||||||
# build an additively homomorphic cryptosystem (e.g. Paillier) on-prem
|
# build an additively homomorphic cryptosystem (e.g. Paillier) on-prem
|
||||||
cs = LightPHE(algorithm_name = "Paillier", precision = 19)
|
cs = LightPHE(algorithm_name = "Paillier", precision = 19)
|
||||||
|
|
||||||
|
# define a plain vector for source
|
||||||
|
alpha = DeepFace.represent("img1.jpg")[0]["embedding"] # user tower
|
||||||
|
|
||||||
# export keys
|
# export keys
|
||||||
cs.export_keys("secret.txt"); cs.export_keys("public.txt", public=True)
|
cs.export_keys("secret.txt"); cs.export_keys("public.txt", public=True)
|
||||||
|
|
||||||
@ -400,6 +399,9 @@ del cs, alpha
|
|||||||
# restore the cryptosystem in cloud with only public key
|
# restore the cryptosystem in cloud with only public key
|
||||||
cloud_cs = LightPHE(algorithm_name = "Paillier", precision = 19, key_file = "public.txt")
|
cloud_cs = LightPHE(algorithm_name = "Paillier", precision = 19, key_file = "public.txt")
|
||||||
|
|
||||||
|
# define a plain vector for target
|
||||||
|
beta = DeepFace.represent("target.jpg")[0]["embedding"] # item tower
|
||||||
|
|
||||||
# dot product of encrypted and plain embedding pair
|
# dot product of encrypted and plain embedding pair
|
||||||
encrypted_cosine_similarity = encrypted_alpha @ beta
|
encrypted_cosine_similarity = encrypted_alpha @ beta
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user