Bridge between TensorFlow and the Microsoft SEAL homomorphic encryption library.
Project description
TF Seal
TF Seal provides a bridge between TF Encrypted and the Microsoft SEAL homomorphic encryption library, making it easier than ever to use this library to compute on encrypted data directly from TensorFlow.
Usage
The following demonstrates how to perform a matrix multiplication using homomorphic encryption inside of TensorFlow.
import numpy as np
import tensorflow as tf
import tf_seal as tfs
public_keys, secret_key = tfs.seal_key_gen(gen_relin=True, gen_galois=True)
# encrypted input -> tf_seal.Tensor
a_plain = np.random.normal(size=(2, 2)).astype(np.float32)
a = tfs.constant(a_plain, secret_key, public_keys)
# public weights
b = np.random.normal(size=(2, 2)).astype(np.float32)
# because of how the data is laid out in memory tfs.matmul expects
# the b matrix to be order column-major wise
c = tfs.matmul(a, b.transpose())
with tf.Session() as sess:
print(sess.run(c))
Installation
We recommend using Miniconda or Anaconda to set up and use a Python 3.7 environment for all instructions below:
conda create -n tfseal python=3.7 -y
source activate tfseal
Custom TensorFlow
A custom build of TensorFlow is currently needed to run TF Seal due to a mismatch between the C++ version used by the official TensorFlow build (C++11) and the one needed by Microsoft SEAL (C++17). A patched version of TensorFlow built with C++17 can be installed as shown below.
Ubuntu
wget https://storage.googleapis.com/tf-pips/tf-c++17-support/tf_nightly-1.14.0-cp37-cp37m-linux_x86_64.whl
pip install tf_nightly-1.14.0-cp37-cp37m-linux_x86_64.whl
macOS
wget https://storage.googleapis.com/tf-pips/tf-c++17-support/tf_nightly-1.14.0-cp37-cp37m-macosx_10_7_x86_64.whl
pip install tf_nightly-1.14.0-cp37-cp37m-macosx_10_7_x86_64.whl
After installing the custom build of TensorFlow you can install TF Seal from PyPi using pip:
pip install tf-seal
Examples
There is currently one example displaying how we can run a simple logistic regression prediction with TF SEAL.
Once TF SEAL is installed we can run the example by simplying running:
python logistic_regression.py
Development
We recommend using Miniconda or Anaconda to set up and use a Python 3.7 environment for all instructions below:
conda create -n tfseal-dev python=3.7 -y
source activate tfseal-dev
Requirements
Ubuntu
- Python (== 3.7)
- Bazel (>= 0.26.1)
- CMake
- TensorFlow built with C++17
CMake can be installed simply with apt:
sudo apt install cmake
Bazel is a little more involved, the following instructions can be installed, recommend installing Bazel 0.26.1: https://docs.bazel.build/versions/master/install-ubuntu.html#install-with-installer-ubuntu
The remaining PyPI packages can then be installed using:
pip install -r requirements-dev.txt
Once the custom TensorFlow is installed you will be able to start development.
macOS
We need the following items:
- Python (== 3.7)
- Bazel (>= 0.26.1)
- CMake
- TensorFlow built with C++17
Using Homebrew we make sure that both Bazel and CMake are installed:
brew tap bazelbuild/tap
brew install bazelbuild/tap/bazel
brew install cmake
The remaining PyPI packages can then be installed using:
pip install -r requirements-dev.txt
Once the custom TensorFlow is installed you will be able to start development.
Testing
Once the development environment is set up you can run:
make test
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Hashes for tf_seal-0.1.0-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 75fa589075015eb401c2c0bfe3d75aec81b117063d204abd5f1c29f3ca616f1a |
|
MD5 | e1c51f6246d0df08c592adb7d301b963 |
|
BLAKE2b-256 | ebb7ecfaa0325f0da16347258b3f49cf2000093f1c63fad7cc0b94689b190440 |