From 59a97b1d52021d8fb3cb74899ee87e97f171cbe2 Mon Sep 17 00:00:00 2001 From: laurentm Date: Thu, 11 Aug 2022 11:24:59 +0200 Subject: [PATCH] Update imports --- README.md | 2 +- keras_fsl/callbacks/binary_statistics.py | 2 +- keras_fsl/layers/centroids_matrix.py | 2 +- keras_fsl/layers/classification.py | 2 +- keras_fsl/layers/slicing.py | 4 ++-- keras_fsl/layers/support_layer.py | 2 +- keras_fsl/losses/gram_matrix_losses.py | 2 +- keras_fsl/metrics/gram_matrix_metrics.py | 2 +- keras_fsl/models/encoders/basic_cnn.py | 4 ++-- keras_fsl/models/encoders/darknet.py | 6 +++--- keras_fsl/models/encoders/koch_net.py | 8 ++++---- keras_fsl/models/encoders/single_conv_2d.py | 4 ++-- keras_fsl/models/encoders/vinyals_net.py | 4 ++-- keras_fsl/models/head_models/dense_sigmoid.py | 4 ++-- keras_fsl/models/head_models/learnt_norms.py | 8 ++++---- keras_fsl/models/head_models/mixed_norms.py | 6 +++--- .../models/head_models/tests/learnt_norms_test.py | 6 +++--- keras_fsl/models/siamese_nets.py | 4 ++-- keras_fsl/sequences/abstract_sequence.py | 4 ++-- .../sequences/prediction/pairs/product_sequence.py | 2 +- .../training/pairs/random_product_sequence.py | 2 +- notebooks/batch_gram_matrix_training.py | 12 ++++++------ notebooks/benchmark_caching_performance.ipynb | 4 ++-- notebooks/build_siamese_model_for_serving.py | 2 +- notebooks/centroids_similarity_training.py | 14 +++++++------- notebooks/evaluate.py | 4 ++-- notebooks/omniglot/basic_siamese_nets.py | 6 +++--- notebooks/siamese_nets_training.py | 8 ++++---- notebooks/supervised_gram_matrix.py | 8 ++++---- notebooks/triplet_loss_cifar10.py | 6 +++--- notebooks/triplet_loss_mnist.py | 6 +++--- notebooks/unsupervised_cifar10.py | 6 +++--- 32 files changed, 78 insertions(+), 78 deletions(-) diff --git a/README.md b/README.md index 8016ca1..ceed0bb 100644 --- a/README.md +++ b/README.md @@ -95,7 +95,7 @@ The [notebooks](notebooks) section provides some examples. For instance, just ru ```python import tensorflow as tf import tensorflow_datasets as tfds -from tensorflow.keras.models import Sequential +from keras.models import Sequential from keras_fsl.models.encoders import BasicCNN from keras_fsl.layers import GramMatrix diff --git a/keras_fsl/callbacks/binary_statistics.py b/keras_fsl/callbacks/binary_statistics.py index dda6c69..08cfc9e 100644 --- a/keras_fsl/callbacks/binary_statistics.py +++ b/keras_fsl/callbacks/binary_statistics.py @@ -2,7 +2,7 @@ import numpy as np import tensorflow as tf from matplotlib.backends.backend_agg import FigureCanvasAgg -from tensorflow.keras.callbacks import Callback +from keras.callbacks import Callback class BinaryStatistics(Callback): diff --git a/keras_fsl/layers/centroids_matrix.py b/keras_fsl/layers/centroids_matrix.py index c92c0e9..e9cdea8 100644 --- a/keras_fsl/layers/centroids_matrix.py +++ b/keras_fsl/layers/centroids_matrix.py @@ -1,5 +1,5 @@ import tensorflow as tf -from tensorflow.keras import activations +from keras import activations from keras_fsl.layers.support_layer import SupportLayer diff --git a/keras_fsl/layers/classification.py b/keras_fsl/layers/classification.py index 8a3a9bd..efb2280 100644 --- a/keras_fsl/layers/classification.py +++ b/keras_fsl/layers/classification.py @@ -1,5 +1,5 @@ import tensorflow as tf -from tensorflow.keras.layers import Layer +from keras.layers import Layer from keras_fsl.losses import class_consistency_loss diff --git a/keras_fsl/layers/slicing.py b/keras_fsl/layers/slicing.py index a317a97..e8ea9fe 100644 --- a/keras_fsl/layers/slicing.py +++ b/keras_fsl/layers/slicing.py @@ -1,5 +1,5 @@ -from tensorflow.keras import Sequential -from tensorflow.keras.layers import Lambda, Flatten +from keras import Sequential +from keras.layers import Lambda, Flatten def CenterSlicing2D(): diff --git a/keras_fsl/layers/support_layer.py b/keras_fsl/layers/support_layer.py index dc1ed32..e17e4a7 100644 --- a/keras_fsl/layers/support_layer.py +++ b/keras_fsl/layers/support_layer.py @@ -1,5 +1,5 @@ import tensorflow as tf -from tensorflow.keras.layers import Layer +from keras.layers import Layer from keras_fsl.models import head_models diff --git a/keras_fsl/losses/gram_matrix_losses.py b/keras_fsl/losses/gram_matrix_losses.py index e7362c3..5db4fe7 100644 --- a/keras_fsl/losses/gram_matrix_losses.py +++ b/keras_fsl/losses/gram_matrix_losses.py @@ -13,7 +13,7 @@ import tensorflow as tf import tensorflow.keras.backend as K import tensorflow_probability as tfp -from tensorflow.keras.losses import Loss +from keras.losses import Loss class MeanScoreClassificationLoss(Loss): diff --git a/keras_fsl/metrics/gram_matrix_metrics.py b/keras_fsl/metrics/gram_matrix_metrics.py index d9346f8..ba23117 100644 --- a/keras_fsl/metrics/gram_matrix_metrics.py +++ b/keras_fsl/metrics/gram_matrix_metrics.py @@ -3,7 +3,7 @@ instance). y_true should be one-hot encoded """ import tensorflow as tf -from tensorflow.keras import backend as K +from keras import backend as K def classification_accuracy(ascending=False): diff --git a/keras_fsl/models/encoders/basic_cnn.py b/keras_fsl/models/encoders/basic_cnn.py index 2f0faac..8dd1f67 100644 --- a/keras_fsl/models/encoders/basic_cnn.py +++ b/keras_fsl/models/encoders/basic_cnn.py @@ -1,5 +1,5 @@ -from tensorflow.keras.layers import Conv2D, Dense, Dropout, Flatten, MaxPooling2D -from tensorflow.keras.models import Sequential +from keras.layers import Conv2D, Dense, Dropout, Flatten, MaxPooling2D +from keras.models import Sequential def BasicCNN(input_shape, classes=None): diff --git a/keras_fsl/models/encoders/darknet.py b/keras_fsl/models/encoders/darknet.py index 3924e32..89d9a2b 100644 --- a/keras_fsl/models/encoders/darknet.py +++ b/keras_fsl/models/encoders/darknet.py @@ -1,8 +1,8 @@ from functools import wraps -from tensorflow.keras import Sequential, Input, Model -from tensorflow.keras.layers import Conv2D, LeakyReLU, ZeroPadding2D, Add, MaxPooling2D, BatchNormalization -from tensorflow.keras.regularizers import l2 +from keras import Sequential, Input, Model +from keras.layers import Conv2D, LeakyReLU, ZeroPadding2D, Add, MaxPooling2D, BatchNormalization +from keras.regularizers import l2 @wraps(Conv2D) diff --git a/keras_fsl/models/encoders/koch_net.py b/keras_fsl/models/encoders/koch_net.py index c02a389..2b1bbca 100644 --- a/keras_fsl/models/encoders/koch_net.py +++ b/keras_fsl/models/encoders/koch_net.py @@ -1,7 +1,7 @@ -from tensorflow.keras import Sequential, Input -from tensorflow.keras.layers import Conv2D, MaxPooling2D, Dense, Flatten -from tensorflow.keras.initializers import RandomNormal -from tensorflow.keras.regularizers import l2 +from keras import Sequential, Input +from keras.layers import Conv2D, MaxPooling2D, Dense, Flatten +from keras.initializers import RandomNormal +from keras.regularizers import l2 def conv_2d(*args, **kwargs): diff --git a/keras_fsl/models/encoders/single_conv_2d.py b/keras_fsl/models/encoders/single_conv_2d.py index d55b723..f01182f 100644 --- a/keras_fsl/models/encoders/single_conv_2d.py +++ b/keras_fsl/models/encoders/single_conv_2d.py @@ -1,5 +1,5 @@ -from tensorflow.keras import Sequential -from tensorflow.keras.layers import Conv2D, GlobalAveragePooling2D +from keras import Sequential +from keras.layers import Conv2D, GlobalAveragePooling2D def SingleConv2D(input_shape): diff --git a/keras_fsl/models/encoders/vinyals_net.py b/keras_fsl/models/encoders/vinyals_net.py index ef9fb41..f8c3daa 100644 --- a/keras_fsl/models/encoders/vinyals_net.py +++ b/keras_fsl/models/encoders/vinyals_net.py @@ -1,5 +1,5 @@ -from tensorflow.keras import Sequential -from tensorflow.keras.layers import Conv2D, Input, BatchNormalization, Activation, MaxPooling2D, Flatten +from keras import Sequential +from keras.layers import Conv2D, Input, BatchNormalization, Activation, MaxPooling2D, Flatten def conv_block(*args, **kwargs): diff --git a/keras_fsl/models/head_models/dense_sigmoid.py b/keras_fsl/models/head_models/dense_sigmoid.py index e1126e0..5e622bb 100644 --- a/keras_fsl/models/head_models/dense_sigmoid.py +++ b/keras_fsl/models/head_models/dense_sigmoid.py @@ -1,6 +1,6 @@ import tensorflow as tf -from tensorflow.keras.layers import Dense, Input, Lambda -from tensorflow.keras.models import Model +from keras.layers import Dense, Input, Lambda +from keras.models import Model def DenseSigmoid(input_shape, use_bias=True): diff --git a/keras_fsl/models/head_models/learnt_norms.py b/keras_fsl/models/head_models/learnt_norms.py index ca5c234..2bfb390 100644 --- a/keras_fsl/models/head_models/learnt_norms.py +++ b/keras_fsl/models/head_models/learnt_norms.py @@ -1,7 +1,7 @@ import numpy as np import tensorflow as tf -from tensorflow.keras import activations -from tensorflow.keras.layers import ( +from keras import activations +from keras.layers import ( Concatenate, Conv2D, Dense, @@ -9,8 +9,8 @@ Input, Reshape, ) -from tensorflow.keras.mixed_precision.experimental import global_policy -from tensorflow.keras.models import Model +from keras.mixed_precision import global_policy +from keras.models import Model from tensorflow.python.keras.layers import Activation diff --git a/keras_fsl/models/head_models/mixed_norms.py b/keras_fsl/models/head_models/mixed_norms.py index 7919040..7f4f7aa 100644 --- a/keras_fsl/models/head_models/mixed_norms.py +++ b/keras_fsl/models/head_models/mixed_norms.py @@ -1,6 +1,6 @@ import tensorflow as tf -from tensorflow.keras import activations -from tensorflow.keras.layers import ( +from keras import activations +from keras.layers import ( Concatenate, Conv2D, Dense, @@ -10,7 +10,7 @@ Lambda, Reshape, ) -from tensorflow.keras.models import Model +from keras.models import Model def MixedNorms(input_shape, norms=None, use_bias=True, activation="sigmoid"): diff --git a/keras_fsl/models/head_models/tests/learnt_norms_test.py b/keras_fsl/models/head_models/tests/learnt_norms_test.py index 5224b1c..4fd159b 100644 --- a/keras_fsl/models/head_models/tests/learnt_norms_test.py +++ b/keras_fsl/models/head_models/tests/learnt_norms_test.py @@ -1,7 +1,7 @@ import numpy as np import tensorflow as tf from absl.testing import parameterized -from tensorflow.keras.optimizers import RMSprop +from keras.optimizers import RMSprop from tensorflow.python.keras.keras_parameterized import TestCase, run_all_keras_modes, run_with_all_model_types from keras_fsl.models.head_models import LearntNorms @@ -34,8 +34,8 @@ def test_should_fit(self, input_shape): ("float64", "float64", "float64"), ) def test_last_activation_fp32_in_mixed_precision(self, mixed_precision_policy, expected_last_layer_dtype_policy): - policy = tf.keras.mixed_precision.experimental.Policy(mixed_precision_policy) - tf.keras.mixed_precision.experimental.set_policy(policy) + policy = tf.keras.mixed_precision.Policy(mixed_precision_policy) + tf.keras.mixed_precision.set_policy(policy) learnt_norms = LearntNorms(input_shape=(10,)) # Check dtype policy of internal non-input layers diff --git a/keras_fsl/models/siamese_nets.py b/keras_fsl/models/siamese_nets.py index 45a24b3..4d4bc92 100644 --- a/keras_fsl/models/siamese_nets.py +++ b/keras_fsl/models/siamese_nets.py @@ -1,5 +1,5 @@ -from tensorflow.keras import Model -from tensorflow.keras.layers import Input +from keras import Model +from keras.layers import Input from keras_fsl.models import encoders, head_models diff --git a/keras_fsl/sequences/abstract_sequence.py b/keras_fsl/sequences/abstract_sequence.py index 13fb810..692a413 100644 --- a/keras_fsl/sequences/abstract_sequence.py +++ b/keras_fsl/sequences/abstract_sequence.py @@ -3,8 +3,8 @@ import imgaug.augmenters as iaa import numpy as np from abc import ABCMeta -from tensorflow.keras.preprocessing.image import img_to_array, load_img -from tensorflow.keras.utils import Sequence +from keras.preprocessing.image import img_to_array, load_img +from keras.utils import Sequence class AbstractSequence(Sequence, metaclass=ABCMeta): diff --git a/keras_fsl/sequences/prediction/pairs/product_sequence.py b/keras_fsl/sequences/prediction/pairs/product_sequence.py index b3029c5..614bd3d 100644 --- a/keras_fsl/sequences/prediction/pairs/product_sequence.py +++ b/keras_fsl/sequences/prediction/pairs/product_sequence.py @@ -1,7 +1,7 @@ import math import pandas as pd -from tensorflow.keras.utils import Sequence +from keras.utils import Sequence class ProductSequence(Sequence): diff --git a/keras_fsl/sequences/training/pairs/random_product_sequence.py b/keras_fsl/sequences/training/pairs/random_product_sequence.py index 61df4ec..e4a4cb7 100644 --- a/keras_fsl/sequences/training/pairs/random_product_sequence.py +++ b/keras_fsl/sequences/training/pairs/random_product_sequence.py @@ -1,7 +1,7 @@ import math import pandas as pd -from tensorflow.keras.utils import Sequence +from keras.utils import Sequence class RandomProductSequence(Sequence): diff --git a/notebooks/batch_gram_matrix_training.py b/notebooks/batch_gram_matrix_training.py index c04de9e..e3fd90f 100644 --- a/notebooks/batch_gram_matrix_training.py +++ b/notebooks/batch_gram_matrix_training.py @@ -4,14 +4,14 @@ import click import pandas as pd import tensorflow as tf -from tensorflow.keras import applications as keras_applications -from tensorflow.keras.callbacks import ( +from keras import applications as keras_applications +from keras.callbacks import ( ModelCheckpoint, ReduceLROnPlateau, TensorBoard, ) -from tensorflow.keras.models import Sequential -from tensorflow.keras.optimizers import Adam +from keras.models import Sequential +from keras.optimizers import Adam from keras_fsl.dataframe.operators import ToKShotDataset from keras_fsl.layers import Classification, GramMatrix @@ -22,8 +22,8 @@ #%% Toggle some config if required # tf.config.experimental_run_functions_eagerly(True) # tf.config.optimizer.set_jit(True) -# policy = tf.keras.mixed_precision.experimental.Policy("mixed_float16") -# tf.keras.mixed_precision.experimental.set_policy(policy) +# policy = tf.keras.mixed_precision.Policy("mixed_float16") +# tf.keras.mixed_precision.set_policy(policy) #%% CLI args diff --git a/notebooks/benchmark_caching_performance.ipynb b/notebooks/benchmark_caching_performance.ipynb index 362d033..ea84402 100644 --- a/notebooks/benchmark_caching_performance.ipynb +++ b/notebooks/benchmark_caching_performance.ipynb @@ -1897,8 +1897,8 @@ "import tensorflow_datasets as tfds\n", "from functools import partial\n", "from gpumonitor.callbacks.tf import TFGpuMonitorCallback\n", - "from tensorflow.keras.layers import Conv2D, Dropout, Flatten, GlobalMaxPooling2D, Input, MaxPooling2D\n", - "from tensorflow.keras.models import Sequential\n", + "from keras.layers import Conv2D, Dropout, Flatten, GlobalMaxPooling2D, Input, MaxPooling2D\n", + "from keras.models import Sequential\n", "\n", "from keras_fsl.utils.datasets import assign, cache, cache_with_tf_record, read_decode_and_crop_jpeg, transform" ], diff --git a/notebooks/build_siamese_model_for_serving.py b/notebooks/build_siamese_model_for_serving.py index 5995edb..603cb8e 100644 --- a/notebooks/build_siamese_model_for_serving.py +++ b/notebooks/build_siamese_model_for_serving.py @@ -1,6 +1,6 @@ # flake8: noqa: E265 import tensorflow as tf -from tensorflow.keras.models import load_model +from keras.models import load_model #%% Load siamese nets classifier = load_model("siamese_nets_classifier/1") diff --git a/notebooks/centroids_similarity_training.py b/notebooks/centroids_similarity_training.py index feafa60..8113aab 100644 --- a/notebooks/centroids_similarity_training.py +++ b/notebooks/centroids_similarity_training.py @@ -3,15 +3,15 @@ import click import pandas as pd import tensorflow as tf -from tensorflow.keras import applications as keras_applications -from tensorflow.keras.callbacks import ( +from keras import applications as keras_applications +from keras.callbacks import ( ModelCheckpoint, ReduceLROnPlateau, TensorBoard, ) -from tensorflow.keras.layers import Input -from tensorflow.keras.models import Model -from tensorflow.keras.optimizers import Adam +from keras.layers import Input +from keras.models import Model +from keras.optimizers import Adam from keras_fsl.dataframe.operators import ToKShotDataset from keras_fsl.layers import CentroidsMatrix @@ -22,8 +22,8 @@ #%% Toggle some config if required # tf.config.experimental_run_functions_eagerly(True) # tf.config.optimizer.set_jit(True) -# policy = tf.keras.mixed_precision.experimental.Policy("mixed_float16") -# tf.keras.mixed_precision.experimental.set_policy(policy) +# policy = tf.keras.mixed_precision.Policy("mixed_float16") +# tf.keras.mixed_precision.set_policy(policy) #%% CLI args diff --git a/notebooks/evaluate.py b/notebooks/evaluate.py index 826a4fd..ec18c3e 100644 --- a/notebooks/evaluate.py +++ b/notebooks/evaluate.py @@ -3,8 +3,8 @@ import numpy as np import pandas as pd import tensorflow as tf -from tensorflow.keras.models import load_model -from tensorflow.keras import metrics +from keras.models import load_model +from keras import metrics #%% Init k_shot = 4 diff --git a/notebooks/omniglot/basic_siamese_nets.py b/notebooks/omniglot/basic_siamese_nets.py index c890fe6..506b764 100644 --- a/notebooks/omniglot/basic_siamese_nets.py +++ b/notebooks/omniglot/basic_siamese_nets.py @@ -4,9 +4,9 @@ import imgaug.augmenters as iaa import pandas as pd -from tensorflow.keras.callbacks import ModelCheckpoint, TensorBoard, ReduceLROnPlateau, EarlyStopping -from tensorflow.keras.optimizer_v2.adam import Adam -from tensorflow.keras.saving import load_model +from keras.callbacks import ModelCheckpoint, TensorBoard, ReduceLROnPlateau, EarlyStopping +from keras.optimizer_v2.adam import Adam +from keras.saving import load_model from keras_fsl.datasets import omniglot from keras_fsl.models import SiameseNets diff --git a/notebooks/siamese_nets_training.py b/notebooks/siamese_nets_training.py index 81fc4cb..cde5216 100644 --- a/notebooks/siamese_nets_training.py +++ b/notebooks/siamese_nets_training.py @@ -8,10 +8,10 @@ import pandas as pd import tensorflow as tf import yaml -from tensorflow.keras.models import load_model -from tensorflow.keras import applications as keras_applications -from tensorflow.keras.callbacks import ModelCheckpoint, ReduceLROnPlateau, TensorBoard -from tensorflow.keras.optimizers import Adam +from keras.models import load_model +from keras import applications as keras_applications +from keras.callbacks import ModelCheckpoint, ReduceLROnPlateau, TensorBoard +from keras.optimizers import Adam from keras_fsl.models import SiameseNets from keras_fsl.sequences import training diff --git a/notebooks/supervised_gram_matrix.py b/notebooks/supervised_gram_matrix.py index 9c83c45..ad618eb 100644 --- a/notebooks/supervised_gram_matrix.py +++ b/notebooks/supervised_gram_matrix.py @@ -7,10 +7,10 @@ import pandas as pd import tensorflow as tf from tensorboard.plugins import projector -from tensorflow.keras.datasets import cifar10 -from tensorflow.keras.models import Sequential -from tensorflow.keras.layers import Lambda -from tensorflow.keras.utils import to_categorical +from keras.datasets import cifar10 +from keras.models import Sequential +from keras.layers import Lambda +from keras.utils import to_categorical from keras_fsl.models.encoders import BasicCNN from keras_fsl.losses import BinaryCrossentropy, class_consistency_loss diff --git a/notebooks/triplet_loss_cifar10.py b/notebooks/triplet_loss_cifar10.py index 2441b1f..7a037df 100644 --- a/notebooks/triplet_loss_cifar10.py +++ b/notebooks/triplet_loss_cifar10.py @@ -12,9 +12,9 @@ import pandas as pd import tensorflow as tf import tensorflow_datasets as tfds -from tensorflow.keras.callbacks import TensorBoard -from tensorflow.keras.layers import Conv2D, Dense, Dropout, GlobalMaxPooling2D, Input, Flatten, MaxPooling2D, Lambda -from tensorflow.keras.models import Sequential +from keras.callbacks import TensorBoard +from keras.layers import Conv2D, Dense, Dropout, GlobalMaxPooling2D, Input, Flatten, MaxPooling2D, Lambda +from keras.models import Sequential from keras_fsl.layers import GramMatrix from keras_fsl.losses.gram_matrix_losses import BinaryCrossentropy, class_consistency_loss, TripletLoss diff --git a/notebooks/triplet_loss_mnist.py b/notebooks/triplet_loss_mnist.py index 6c60521..fa41d71 100644 --- a/notebooks/triplet_loss_mnist.py +++ b/notebooks/triplet_loss_mnist.py @@ -8,9 +8,9 @@ import tensorflow as tf import tensorflow_addons as tfa import tensorflow_datasets as tfds -from tensorflow.keras.layers import Conv2D, Dense, Dropout, Flatten, Lambda, MaxPooling2D -from tensorflow.keras.models import Sequential -from tensorflow.keras.callbacks import TensorBoard +from keras.layers import Conv2D, Dense, Dropout, Flatten, Lambda, MaxPooling2D +from keras.models import Sequential +from keras.callbacks import TensorBoard from keras_fsl.losses.gram_matrix_losses import triplet_loss from keras_fsl.layers import GramMatrix diff --git a/notebooks/unsupervised_cifar10.py b/notebooks/unsupervised_cifar10.py index a7b7ec6..339c74d 100644 --- a/notebooks/unsupervised_cifar10.py +++ b/notebooks/unsupervised_cifar10.py @@ -5,9 +5,9 @@ import tensorflow as tf import tensorflow_datasets as tfds import tensorflow_addons as tfa -from tensorflow.keras.callbacks import EarlyStopping, TensorBoard -from tensorflow.keras.layers import Conv2D, Dense, Dropout, GlobalMaxPooling2D, Input, Flatten, MaxPooling2D, Lambda -from tensorflow.keras.models import Sequential +from keras.callbacks import EarlyStopping, TensorBoard +from keras.layers import Conv2D, Dense, Dropout, GlobalMaxPooling2D, Input, Flatten, MaxPooling2D, Lambda +from keras.models import Sequential from keras_fsl.layers import GramMatrix from keras_fsl.losses.gram_matrix_losses import ClippedBinaryCrossentropy, ClassConsistencyLoss