diff --git a/tensorflow_privacy/__init__.py b/tensorflow_privacy/__init__.py index bf0e8e4..1e6e42d 100644 --- a/tensorflow_privacy/__init__.py +++ b/tensorflow_privacy/__init__.py @@ -26,9 +26,6 @@ from tensorflow_privacy.version import __version__ # pylint: disable=g-bad-impo if hasattr(sys, 'skip_tf_privacy_import'): # Useful for standalone scripts. pass else: - # TensorFlow v1 imports - import tensorflow_privacy.v1 - # Analysis from tensorflow_privacy.privacy.analysis.compute_dp_sgd_privacy_lib import compute_dp_sgd_privacy from tensorflow_privacy.privacy.analysis.privacy_ledger import GaussianSumQueryEntry @@ -57,6 +54,7 @@ else: # Estimators from tensorflow_privacy.privacy.estimators.dnn import DNNClassifier + from tensorflow_privacy.privacy.estimators.v1.dnn import DNNClassifier as DNNClassifierV1 # Keras Models from tensorflow_privacy.privacy.keras_models.dp_keras_model import DPModel @@ -64,6 +62,14 @@ else: from tensorflow_privacy.privacy.keras_models.dp_keras_model import make_dp_model_class # Optimizers + from tensorflow_privacy.privacy.optimizers.dp_optimizer import DPAdagradGaussianOptimizer + from tensorflow_privacy.privacy.optimizers.dp_optimizer import DPAdagradOptimizer + from tensorflow_privacy.privacy.optimizers.dp_optimizer import DPAdamGaussianOptimizer + from tensorflow_privacy.privacy.optimizers.dp_optimizer import DPAdamOptimizer + from tensorflow_privacy.privacy.optimizers.dp_optimizer import DPGradientDescentGaussianOptimizer + from tensorflow_privacy.privacy.optimizers.dp_optimizer import DPGradientDescentOptimizer + from tensorflow_privacy.privacy.optimizers.dp_optimizer import make_optimizer_class + from tensorflow_privacy.privacy.optimizers.dp_optimizer_keras import DPKerasAdagradOptimizer from tensorflow_privacy.privacy.optimizers.dp_optimizer_keras import DPKerasAdamOptimizer from tensorflow_privacy.privacy.optimizers.dp_optimizer_keras import DPKerasSGDOptimizer @@ -74,6 +80,15 @@ else: from tensorflow_privacy.privacy.optimizers.dp_optimizer_keras_vectorized import VectorizedDPKerasSGDOptimizer from tensorflow_privacy.privacy.optimizers.dp_optimizer_keras_vectorized import make_vectorized_keras_optimizer_class + from tensorflow_privacy.privacy.optimizers.dp_optimizer_vectorized import VectorizedDPAdagradOptimizer + from tensorflow_privacy.privacy.optimizers.dp_optimizer_vectorized import VectorizedDPAdamOptimizer + from tensorflow_privacy.privacy.optimizers.dp_optimizer_vectorized import VectorizedDPSGDOptimizer + + from tensorflow_privacy.privacy.optimizers.dp_optimizer_vectorized import VectorizedDPAdagrad + from tensorflow_privacy.privacy.optimizers.dp_optimizer_vectorized import VectorizedDPAdam + from tensorflow_privacy.privacy.optimizers.dp_optimizer_vectorized import VectorizedDPSGD + from tensorflow_privacy.privacy.optimizers.dp_optimizer_vectorized import make_vectorized_optimizer_class + try: from tensorflow_privacy.privacy.bolt_on.models import BoltOnModel from tensorflow_privacy.privacy.bolt_on.optimizers import BoltOn diff --git a/tensorflow_privacy/privacy/analysis/compute_dp_sgd_privacy.py b/tensorflow_privacy/privacy/analysis/compute_dp_sgd_privacy.py index e9d999d..e4a0efb 100644 --- a/tensorflow_privacy/privacy/analysis/compute_dp_sgd_privacy.py +++ b/tensorflow_privacy/privacy/analysis/compute_dp_sgd_privacy.py @@ -32,11 +32,16 @@ from __future__ import absolute_import from __future__ import division from __future__ import print_function +import sys + from absl import app from absl import flags from tensorflow_privacy.privacy.analysis.compute_dp_sgd_privacy_lib import compute_dp_sgd_privacy +# Opting out of loading all sibling packages and their dependencies. +sys.skip_tf_privacy_import = True + FLAGS = flags.FLAGS flags.DEFINE_integer('N', None, 'Total number of examples') diff --git a/tensorflow_privacy/privacy/analysis/compute_dp_sgd_privacy_lib.py b/tensorflow_privacy/privacy/analysis/compute_dp_sgd_privacy_lib.py index 8d081c5..a69d7db 100644 --- a/tensorflow_privacy/privacy/analysis/compute_dp_sgd_privacy_lib.py +++ b/tensorflow_privacy/privacy/analysis/compute_dp_sgd_privacy_lib.py @@ -19,9 +19,13 @@ from __future__ import division from __future__ import print_function import math +import sys from absl import app +# Opting out of loading all sibling packages and their dependencies. +sys.skip_tf_privacy_import = True + from tensorflow_privacy.privacy.analysis.rdp_accountant import compute_rdp # pylint: disable=g-import-not-at-top from tensorflow_privacy.privacy.analysis.rdp_accountant import get_privacy_spent diff --git a/tensorflow_privacy/privacy/analysis/compute_noise_from_budget.py b/tensorflow_privacy/privacy/analysis/compute_noise_from_budget.py index 731c9ac..bb23eea 100644 --- a/tensorflow_privacy/privacy/analysis/compute_noise_from_budget.py +++ b/tensorflow_privacy/privacy/analysis/compute_noise_from_budget.py @@ -34,11 +34,16 @@ from __future__ import absolute_import from __future__ import division from __future__ import print_function +import sys + from absl import app from absl import flags from tensorflow_privacy.privacy.analysis.compute_noise_from_budget_lib import compute_noise +# Opting out of loading all sibling packages and their dependencies. +sys.skip_tf_privacy_import = True + FLAGS = flags.FLAGS flags.DEFINE_integer('N', None, 'Total number of examples') diff --git a/tensorflow_privacy/privacy/analysis/compute_noise_from_budget_lib.py b/tensorflow_privacy/privacy/analysis/compute_noise_from_budget_lib.py index ccf1f1c..1325cb2 100644 --- a/tensorflow_privacy/privacy/analysis/compute_noise_from_budget_lib.py +++ b/tensorflow_privacy/privacy/analysis/compute_noise_from_budget_lib.py @@ -19,6 +19,7 @@ from __future__ import division from __future__ import print_function import math +import sys from absl import app from scipy.optimize import bisect @@ -26,6 +27,9 @@ from scipy.optimize import bisect from tensorflow_privacy.privacy.analysis.rdp_accountant import compute_rdp # pylint: disable=g-import-not-at-top from tensorflow_privacy.privacy.analysis.rdp_accountant import get_privacy_spent +# Opting out of loading all sibling packages and their dependencies. +sys.skip_tf_privacy_import = True + def apply_dp_sgd_analysis(q, sigma, steps, orders, delta): """Compute and print results of DP-SGD analysis.""" diff --git a/tensorflow_privacy/v1/__init__.py b/tensorflow_privacy/v1/__init__.py deleted file mode 100644 index 7bce1a9..0000000 --- a/tensorflow_privacy/v1/__init__.py +++ /dev/null @@ -1,50 +0,0 @@ -# Copyright 2020, The TensorFlow Privacy Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -"""TensorFlow Privacy library v1 imports. - -This module includes classes designed to be compatible with TF1, based on -`tf.compat.v1.train.Optimizer` and `tf.estimator.Estimator`. -""" - -from __future__ import absolute_import -from __future__ import division -from __future__ import print_function - -import sys - -# pylint: disable=g-import-not-at-top - -if hasattr(sys, 'skip_tf_privacy_import'): # Useful for standalone scripts. - pass -else: - # Estimators - from tensorflow_privacy.privacy.estimators.v1.dnn import DNNClassifier as DNNClassifierV1 - - # Optimizers - from tensorflow_privacy.privacy.optimizers.dp_optimizer import DPAdagradGaussianOptimizer - from tensorflow_privacy.privacy.optimizers.dp_optimizer import DPAdagradOptimizer - from tensorflow_privacy.privacy.optimizers.dp_optimizer import DPAdamGaussianOptimizer - from tensorflow_privacy.privacy.optimizers.dp_optimizer import DPAdamOptimizer - from tensorflow_privacy.privacy.optimizers.dp_optimizer import DPGradientDescentGaussianOptimizer - from tensorflow_privacy.privacy.optimizers.dp_optimizer import DPGradientDescentOptimizer - from tensorflow_privacy.privacy.optimizers.dp_optimizer import make_optimizer_class - - from tensorflow_privacy.privacy.optimizers.dp_optimizer_vectorized import VectorizedDPAdagradOptimizer - from tensorflow_privacy.privacy.optimizers.dp_optimizer_vectorized import VectorizedDPAdamOptimizer - from tensorflow_privacy.privacy.optimizers.dp_optimizer_vectorized import VectorizedDPSGDOptimizer - - from tensorflow_privacy.privacy.optimizers.dp_optimizer_vectorized import VectorizedDPAdagrad - from tensorflow_privacy.privacy.optimizers.dp_optimizer_vectorized import VectorizedDPAdam - from tensorflow_privacy.privacy.optimizers.dp_optimizer_vectorized import VectorizedDPSGD - from tensorflow_privacy.privacy.optimizers.dp_optimizer_vectorized import make_vectorized_optimizer_class