Encrypted Skin Cancer Detection
The purpose of this project is to demonstrate how simple it is to provide encrypted skin cancer detection with TF Encrypted. We released this code in the context of the blog post A Path to Sub-Second, Encrypted Skin Cancer Detection.
Only three steps are required to provide private predictions:
- Train your deep learning model with the framework of your choice.
- Export the model to a protocol buffer file (protobuf).
- Load the protobuf in TF Encrypted to start serving private predictions.
This project requires Python 3.6 and the following Python libraries installed:
You can easily install these libraries with:
pip install -r requirements.txt
We recommend installing Anaconda, a pre-packaged Python distribution that can be used to install and manage all of the necessary libraries and software for this project.
If you experience any issues installing fastai, you can consult the documentation.
Run Private Predictions
If you want, you can run a private prediction right away. We supply a protobuf containing the model weights and the neural network architecture in this GCS storage bucket. For demonstration purposes, we also provide a pre-processed skin lesion image as a pickled Numpy array:
To perform a private prediction locally, you can simply run this command in your terminal:
MODEL_URL=https://storage.googleapis.com/tfe-examples-data/skin_cancer/skin_cancer_model.pb ./private_predict --protocol_name securenn \ --model $MODEL_URL \ --input-file skin_cancer_image.npy \ --batch-size 1 \ --iterations 1
Alternatively, you can download the protobuf manually and supply it directly to the CLI:
./private_predict --protocol_name securenn \ --model skin_cancer_model.pb \ --input-file skin_cancer_image.npy \ --batch-size 1 \ --iterations 1
When running this command, a TF Encrypted graph is automatically created using the GraphDef inside the supplied protobuf. The original model weights are secret shared during this conversion process. Finally, data provided through the
--input-file arg is secret shared before the model performs the secure inference.
After downloading the data from here, you can train the model by running the notebook
training.ipynb. The purpose of this model is to classify correctly the malignant skin lesions (Melanoma) images. For this project, we trained the model with the fastai library to quickly experiment with different architectures, data augmentation strategies, cyclical learning rates, etc. This was mainly due to the availability of the cyclical learning rate finder -- training with TensorFlow, Keras, or a library like tensor2tensor is usually preferred.
Once trained, the model gets exported to a protobuf file with the function
export_to_pb from the utility file
transform_to_pb.py. This function first transforms the PyTorch model into a TensorFlow graph and then exports it to protobuf.
For this project, we have gathered 1,321 skin lesions images labeled as Melanona and 2,229 skin lesion images labeled as Nevi or Seborrheic Keratoses. This data were collected from the 2017 ISIC Challenge on Skin Lesion Analysis Towards Melanoma Detection and additional data where collected from ISIC archive using the instructions here. You can download the data used for this project from here.
Codella N, Gutman D, Celebi ME, Helba B, Marchetti MA, Dusza S, Kalloo A, Liopyris K, Mishra N, Kittler H, Halpern A. "Skin Lesion Analysis Toward Melanoma Detection: A Challenge at the 2017 International Symposium on Biomedical Imaging (ISBI), Hosted by the International Skin Imaging Collaboration (ISIC)". arXiv: 1710.05006 [cs.CV] Available: https://arxiv.org/abs/1710.05006