From 74bd89d754fca076f9a3046bf6b9e5c4b87bd710 Mon Sep 17 00:00:00 2001 From: "A. Unique TensorFlower" Date: Wed, 24 Jun 2020 06:12:53 -0700 Subject: [PATCH] Updates to the codelab. PiperOrigin-RevId: 318051333 --- .../membership_inference_attack/codelab.ipynb | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/tensorflow_privacy/privacy/membership_inference_attack/codelab.ipynb b/tensorflow_privacy/privacy/membership_inference_attack/codelab.ipynb index e717432..ad13f10 100644 --- a/tensorflow_privacy/privacy/membership_inference_attack/codelab.ipynb +++ b/tensorflow_privacy/privacy/membership_inference_attack/codelab.ipynb @@ -94,12 +94,6 @@ "outputs": [], "source": [ "#@title Import statements.\n", - "try:\n", - " # %tensorflow_version only exists in Colab.\n", - " %tensorflow_version 1.x\n", - "except Exception:\n", - " pass\n", - "\n", "import numpy as np\n", "from typing import Tuple, Text\n", "from scipy import special\n", @@ -107,7 +101,12 @@ "import tensorflow as tf\n", "import tensorflow_datasets as tfds\n", "\n", - "tf.compat.v1.logging.set_verbosity(tf.logging.ERROR)" + "# Set verbosity.\n", + "tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR)\n", + "from warnings import simplefilter\n", + "from sklearn.exceptions import ConvergenceWarning\n", + "simplefilter(action=\"ignore\", category=ConvergenceWarning)\n", + "simplefilter(action=\"ignore\", category=FutureWarning)" ] }, { @@ -274,12 +273,23 @@ "#@markdown doesn't have privacy issues according to this test. Higher values,\n", "#@markdown on the contrary, indicate potential privacy issues.\n", "\n", - "#@markdown Note: This will take a while, since it also trains ML models to\n", - "#@markdown separate train/test examples.\n", - "\n", "labels_train = np.argmax(y_train, axis=1)\n", "labels_test = np.argmax(y_test, axis=1)\n", "\n", + "results_without_classifiers = mia.run_all_attacks(\n", + " loss_train,\n", + " loss_test,\n", + " logits_train,\n", + " logits_test,\n", + " labels_train,\n", + " labels_test,\n", + " attack_classifiers=[],\n", + ")\n", + "print(results_without_classifiers)\n", + "\n", + "# Note: This will take a while, since it also trains ML models to\n", + "# separate train/test examples. If it's taking too looking, use\n", + "# the `run_all_attacks` function instead.\n", "attack_result_summary = mia.run_all_attacks_and_create_summary(\n", " loss_train,\n", " loss_test,\n",