From 75de85c177eb390ab872452c213b11d46657fab4 Mon Sep 17 00:00:00 2001 From: Mark Harfouche Date: Tue, 28 Nov 2023 08:26:28 -0500 Subject: [PATCH 1/2] Release a version from git 2023/11 for tf 2.14 compatibility --- recipe/meta.yaml | 41 +- recipe/patches/0001-Internal-change.patch | 35 ++ ...value-for-the-use_gpu-param-to-True-.patch | 46 ++ ...-NaN-issue-with-streaming_covariance.patch | 77 +++ ...e-the-private-TF-API-usage-of-layers.patch | 344 +++++++++++++ .../patches/0005-Internal-Google-change.patch | 26 + ...low-checkpoint-and-trackable-imports.patch | 73 +++ ....23-compatibility-problems-in-tf_sl.patch} | 6 +- ...-by-previous-change-list-due-to-smal.patch | 27 + ...erences-to-deprecated-NumPy-type-ali.patch | 41 ++ ...erences-to-deprecated-NumPy-type-ali.patch | 46 ++ ...Remove-legacy-references-from-ops.py.patch | 197 +++++++ ...ces-to-stack-and-unstack-to-their-ne.patch | 113 +++++ ...d-case_v2-out-of-control_flow_ops.py.patch | 61 +++ ...w_ops.Assert-into-its-own-file-contr.patch | 56 ++ ...w_ops.while_loop-into-its-own-file-w.patch | 97 ++++ ...ces-from-control_flow_ops.cond-to-co.patch | 136 +++++ ...stance-checks-of-tf.compat.v1.Variab.patch | 455 +++++++++++++++++ ...s-from-variables.VariableV1-to-its-n.patch | 210 ++++++++ ...s-from-tensorflow.python.platform-to.patch | 480 ++++++++++++++++++ ...ference-to-variable_scope.variable-i.patch | 37 ++ .../patches/0021-Internal-Code-Change.patch | 140 +++++ ...2-Delete-remnants-of-toollog-removal.patch | 27 + ...f-functions-deprecated-in-NumPy-1.25.patch | 61 +++ ...d-call-ops.device-device-only-when-d.patch | 39 ++ ...ncat-crashes-on-specific-and-relativ.patch | 65 +++ ...r-references-to-third_party-tensorfl.patch | 92 ++++ ...e-legacy-references-to-tensor.Tensor.patch | 44 ++ ...to-TF-resource-variable-toggle-funct.patch | 94 ++++ ...references-to-functions-imported-by-.patch | 121 +++++ ...o-layer.apply-and-just-use-__call__.patch} | 9 +- 31 files changed, 3287 insertions(+), 9 deletions(-) create mode 100644 recipe/patches/0001-Internal-change.patch create mode 100644 recipe/patches/0002-Set-the-default-value-for-the-use_gpu-param-to-True-.patch create mode 100644 recipe/patches/0003-Fix-a-NaN-issue-with-streaming_covariance.patch create mode 100644 recipe/patches/0004-Remove-the-private-TF-API-usage-of-layers.patch create mode 100644 recipe/patches/0005-Internal-Google-change.patch create mode 100644 recipe/patches/0006-Fix-TensorFlow-checkpoint-and-trackable-imports.patch rename recipe/{numpy_123_comaptibility.patch => patches/0007-NumPy-Fix-NumPy-1.23-compatibility-problems-in-tf_sl.patch} (92%) create mode 100644 recipe/patches/0008-Fix-tests-broken-by-previous-change-list-due-to-smal.patch create mode 100644 recipe/patches/0009-NumPy-Remove-references-to-deprecated-NumPy-type-ali.patch create mode 100644 recipe/patches/0010-NumPy-Remove-references-to-deprecated-NumPy-type-ali.patch create mode 100644 recipe/patches/0011-Remove-legacy-references-from-ops.py.patch create mode 100644 recipe/patches/0012-Redirect-references-to-stack-and-unstack-to-their-ne.patch create mode 100644 recipe/patches/0013-Refactor-case-and-case_v2-out-of-control_flow_ops.py.patch create mode 100644 recipe/patches/0014-Move-control_flow_ops.Assert-into-its-own-file-contr.patch create mode 100644 recipe/patches/0015-Move-control_flow_ops.while_loop-into-its-own-file-w.patch create mode 100644 recipe/patches/0016-Redirect-references-from-control_flow_ops.cond-to-co.patch create mode 100644 recipe/patches/0017-Update-some-isinstance-checks-of-tf.compat.v1.Variab.patch create mode 100644 recipe/patches/0018-Update-references-from-variables.VariableV1-to-its-n.patch create mode 100644 recipe/patches/0019-Update-references-from-tensorflow.python.platform-to.patch create mode 100644 recipe/patches/0020-Update-legacy-reference-to-variable_scope.variable-i.patch create mode 100644 recipe/patches/0021-Internal-Code-Change.patch create mode 100644 recipe/patches/0022-Delete-remnants-of-toollog-removal.patch create mode 100644 recipe/patches/0023-NumPy-Fix-uses-of-functions-deprecated-in-NumPy-1.25.patch create mode 100644 recipe/patches/0024-Use-ExitStack-and-call-ops.device-device-only-when-d.patch create mode 100644 recipe/patches/0025-Fix-streaming_concat-crashes-on-specific-and-relativ.patch create mode 100644 recipe/patches/0026-Update-ops.Tensor-references-to-third_party-tensorfl.patch create mode 100644 recipe/patches/0027-Update-legacy-references-to-tensor.Tensor.patch create mode 100644 recipe/patches/0028-Move-references-to-TF-resource-variable-toggle-funct.patch create mode 100644 recipe/patches/0029-Update-outdated-references-to-functions-imported-by-.patch rename recipe/{21-avoid_layer_apply.patch => patches/0030-Remove-call-to-layer.apply-and-just-use-__call__.patch} (95%) diff --git a/recipe/meta.yaml b/recipe/meta.yaml index 4a8d64a..4bbadca 100644 --- a/recipe/meta.yaml +++ b/recipe/meta.yaml @@ -2,19 +2,50 @@ package: name: tf_slim - version: {{ version }} + version: {{ version }}.post20231128 source: url: https://github.com/google-research/tf-slim/archive/refs/heads/r{{ version }}.zip sha256: f9f6f04c9852bd6bc76bc11e1090ae44ff1dea31a5d7ef4f5feeaa20ae55cdb2 patches: + # Find the commit after the latest release 1.1.0 # https://github.com/google-research/tf-slim/pull/21 - - 21-avoid_layer_apply.patch - # https://github.com/google-research/tf-slim/commit/550196c9db2b76d9e23bc394f4dd02df78159a6a - - numpy_123_comaptibility.patch + # git checkout remove_layer_apply + # git format-patch 8f0215e924996d7287392241bc8d8b1133d0c5ca + - 0001-Internal-change.patch + - 0002-Set-the-default-value-for-the-use_gpu-param-to-True-.patch + - 0003-Fix-a-NaN-issue-with-streaming_covariance.patch + - 0004-Remove-the-private-TF-API-usage-of-layers.patch + - 0005-Internal-Google-change.patch + - 0006-Fix-TensorFlow-checkpoint-and-trackable-imports.patch + - 0007-NumPy-Fix-NumPy-1.23-compatibility-problems-in-tf_sl.patch + - 0008-Fix-tests-broken-by-previous-change-list-due-to-smal.patch + - 0009-NumPy-Remove-references-to-deprecated-NumPy-type-ali.patch + - 0010-NumPy-Remove-references-to-deprecated-NumPy-type-ali.patch + - 0011-Remove-legacy-references-from-ops.py.patch + - 0012-Redirect-references-to-stack-and-unstack-to-their-ne.patch + - 0013-Refactor-case-and-case_v2-out-of-control_flow_ops.py.patch + - 0014-Move-control_flow_ops.Assert-into-its-own-file-contr.patch + - 0015-Move-control_flow_ops.while_loop-into-its-own-file-w.patch + - 0016-Redirect-references-from-control_flow_ops.cond-to-co.patch + - 0017-Update-some-isinstance-checks-of-tf.compat.v1.Variab.patch + - 0018-Update-references-from-variables.VariableV1-to-its-n.patch + - 0019-Update-references-from-tensorflow.python.platform-to.patch + - 0020-Update-legacy-reference-to-variable_scope.variable-i.patch + - 0021-Internal-Code-Change.patch + - 0022-Delete-remnants-of-toollog-removal.patch + - 0023-NumPy-Fix-uses-of-functions-deprecated-in-NumPy-1.25.patch + - 0024-Use-ExitStack-and-call-ops.device-device-only-when-d.patch + - 0025-Fix-streaming_concat-crashes-on-specific-and-relativ.patch + - 0026-Update-ops.Tensor-references-to-third_party-tensorfl.patch + - 0027-Update-legacy-references-to-tensor.Tensor.patch + - 0028-Move-references-to-TF-resource-variable-toggle-funct.patch + - 0029-Update-outdated-references-to-functions-imported-by-.patch + # https://github.com/google-research/tf-slim/pull/21 + - 0030-Remove-call-to-layer.apply-and-just-use-__call__.patch build: noarch: python - number: 3 + number: 0 script: {{ PYTHON }} -m pip install . -vv requirements: diff --git a/recipe/patches/0001-Internal-change.patch b/recipe/patches/0001-Internal-change.patch new file mode 100644 index 0000000..f54f1cf --- /dev/null +++ b/recipe/patches/0001-Internal-change.patch @@ -0,0 +1,35 @@ +From b189304a31b4e471128e988a3108ee6845a53e31 Mon Sep 17 00:00:00 2001 +From: Sanjoy Das +Date: Wed, 27 Jan 2021 20:59:44 -0800 +Subject: [PATCH 01/30] Internal change. + +PiperOrigin-RevId: 354234980 +Change-Id: I5989d83c71236cd88b5cdbf245dbb96c3a36068c +--- + pip_pkg.sh | 2 +- + tests_release.sh | 2 +- + 2 files changed, 2 insertions(+), 2 deletions(-) + +diff --git a/pip_pkg.sh b/pip_pkg.sh +index 5caab4e..632cb16 100755 +--- a/pip_pkg.sh ++++ b/pip_pkg.sh +@@ -1,4 +1,4 @@ +-# Copyright 2020 The TF-Slim Authors. ++# Copyright 2021 The TF-Slim Authors. + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. +diff --git a/tests_release.sh b/tests_release.sh +index 5c3b5e7..a719d50 100755 +--- a/tests_release.sh ++++ b/tests_release.sh +@@ -1,4 +1,4 @@ +-# Copyright 2020 The TF-Slim Authors. ++# Copyright 2021 The TF-Slim Authors. + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. +-- +2.40.1 + diff --git a/recipe/patches/0002-Set-the-default-value-for-the-use_gpu-param-to-True-.patch b/recipe/patches/0002-Set-the-default-value-for-the-use_gpu-param-to-True-.patch new file mode 100644 index 0000000..1b08397 --- /dev/null +++ b/recipe/patches/0002-Set-the-default-value-for-the-use_gpu-param-to-True-.patch @@ -0,0 +1,46 @@ +From 6387efbf7878c5269f3a19cbe33e631988528bc5 Mon Sep 17 00:00:00 2001 +From: Sanjoy Das +Date: Wed, 10 Feb 2021 22:53:32 -0800 +Subject: [PATCH 02/30] Set the default value for the use_gpu-param to True in + test utilities + +Also, fix a bug in IsFunctionCallOp found by this CL. + +Contrary to what it sounds like, `use_gpu` does not force the test to run on +GPUs, it merely *allows* the test to run on GPUs (there is a separate +`force_gpu` option for forcing). This means setting `use_gpu` to `True` means +that the test will run on GPUs if one is available. + +Given that setting `use_gpu` to `True` by default makes sense, and there should +be a good reason for a test to set it to `False` (which disallows GPU use, even +when one is available). + +For this reason, this CL changes the default value of `use_gpu`. As you can +see, this has already found a few real bugs. + +In a later CL I will remove instances that pass use_gpu=True explicitly as those +should no longer be necessary. + +PiperOrigin-RevId: 356906251 +Change-Id: I39cc6e254b3295f3f3bc5c90f397cf15bd1c2eed +--- + tf_slim/ops/variables_test.py | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/tf_slim/ops/variables_test.py b/tf_slim/ops/variables_test.py +index 231f99e..9f127eb 100644 +--- a/tf_slim/ops/variables_test.py ++++ b/tf_slim/ops/variables_test.py +@@ -480,7 +480,8 @@ class VariablesTest(test.TestCase): + self.assertDeviceEqual(e.initial_value.device, 'cpu:99') + + def testVariableWithReplicaDeviceSetter(self): +- with self.cached_session(): ++ # Explicitly disable GPU usage because we check for the CPU device below. ++ with self.cached_session(use_gpu=False): + with ops.device(device_setter.replica_device_setter(ps_tasks=2)): + a = variables_lib2.variable('a', []) + b = variables_lib2.variable('b', []) +-- +2.40.1 + diff --git a/recipe/patches/0003-Fix-a-NaN-issue-with-streaming_covariance.patch b/recipe/patches/0003-Fix-a-NaN-issue-with-streaming_covariance.patch new file mode 100644 index 0000000..9ff8e90 --- /dev/null +++ b/recipe/patches/0003-Fix-a-NaN-issue-with-streaming_covariance.patch @@ -0,0 +1,77 @@ +From 77b441267e27359e94a641b906f07afc25f69b13 Mon Sep 17 00:00:00 2001 +From: TF-Slim Team +Date: Mon, 15 Mar 2021 21:08:50 -0700 +Subject: [PATCH 03/30] Fix a NaN issue with streaming_covariance. + +PiperOrigin-RevId: 363099343 +Change-Id: I7012be19e3afd9b0b1f8f7b8e047065ae09909ce +--- + tf_slim/metrics/metric_ops.py | 2 +- + tf_slim/metrics/metric_ops_test.py | 27 +++++++++++++++++---------- + 2 files changed, 18 insertions(+), 11 deletions(-) + +diff --git a/tf_slim/metrics/metric_ops.py b/tf_slim/metrics/metric_ops.py +index 3febbfa..cdd844c 100644 +--- a/tf_slim/metrics/metric_ops.py ++++ b/tf_slim/metrics/metric_ops.py +@@ -3242,7 +3242,7 @@ def streaming_covariance(predictions, + delta_comoment = ( + batch_comoment + (prev_mean_prediction - batch_mean_prediction) * + (prev_mean_label - batch_mean_label) * +- (prev_count * batch_count / update_count)) ++ (math_ops.div_no_nan(prev_count * batch_count, update_count))) + update_comoment = state_ops.assign_add(comoment, delta_comoment) + + covariance = array_ops.where( +diff --git a/tf_slim/metrics/metric_ops_test.py b/tf_slim/metrics/metric_ops_test.py +index 9920fa2..3d63758 100644 +--- a/tf_slim/metrics/metric_ops_test.py ++++ b/tf_slim/metrics/metric_ops_test.py +@@ -5947,12 +5947,13 @@ class StreamingCovarianceTest(tf.test.TestCase): + with self.cached_session() as sess: + np.random.seed(123) + n = 100 ++ stride = 10 + predictions = np.random.randn(n) + labels = 0.5 * predictions + np.random.randn(n) +- weights = np.tile(np.arange(n // 10), n // 10) ++ weights = np.tile(np.arange(n // stride), n // stride) + np.random.shuffle(weights) ++ weights[0:stride] = 0.0 + +- stride = 10 + predictions_t = array_ops.placeholder(dtypes_lib.float32, [stride]) + labels_t = array_ops.placeholder(dtypes_lib.float32, [stride]) + weights_t = array_ops.placeholder(dtypes_lib.float32, [stride]) +@@ -5974,14 +5975,20 @@ class StreamingCovarianceTest(tf.test.TestCase): + if not np.isnan(prev_expected_cov): + self.assertAlmostEqual(prev_expected_cov, + sess.run(cov, feed_dict=feed_dict), 5) +- expected_cov = np.cov( +- predictions[:stride * (i + 1)], +- labels[:stride * (i + 1)], +- fweights=weights[:stride * (i + 1)])[0, 1] +- self.assertAlmostEqual(expected_cov, +- sess.run(update_op, feed_dict=feed_dict), 5) +- self.assertAlmostEqual(expected_cov, sess.run(cov, feed_dict=feed_dict), +- 5) ++ if np.sum(weights[:stride * (i + 1)]) != 0.0: ++ expected_cov = np.cov( ++ predictions[:stride * (i + 1)], ++ labels[:stride * (i + 1)], ++ fweights=weights[:stride * (i + 1)])[0, 1] ++ else: ++ expected_cov = NAN ++ sess.run(update_op, feed_dict=feed_dict) ++ self.assertEqual( ++ np.isnan(expected_cov), ++ np.isnan(sess.run(cov, feed_dict=feed_dict))) ++ if not np.isnan(expected_cov): ++ self.assertAlmostEqual(expected_cov, ++ sess.run(cov, feed_dict=feed_dict), 5) + prev_expected_cov = expected_cov + + +-- +2.40.1 + diff --git a/recipe/patches/0004-Remove-the-private-TF-API-usage-of-layers.patch b/recipe/patches/0004-Remove-the-private-TF-API-usage-of-layers.patch new file mode 100644 index 0000000..f30603e --- /dev/null +++ b/recipe/patches/0004-Remove-the-private-TF-API-usage-of-layers.patch @@ -0,0 +1,344 @@ +From 3209e28b6aa4eb7f5fb5c17fef1adc9abb0c1860 Mon Sep 17 00:00:00 2001 +From: Scott Zhu +Date: Mon, 8 Nov 2021 13:03:51 -0800 +Subject: [PATCH 04/30] Remove the private TF API usage of layers. + +PiperOrigin-RevId: 408420918 +Change-Id: I6761540a8c724d79612e00c6f4230a7e085ddfb6 +--- + tf_slim/layers/layers.py | 41 ++++++++++++---------------- + tf_slim/layers/rev_block_lib.py | 5 ++-- + tf_slim/layers/rev_block_lib_test.py | 39 ++++++++++++-------------- + 3 files changed, 39 insertions(+), 46 deletions(-) + +diff --git a/tf_slim/layers/layers.py b/tf_slim/layers/layers.py +index 5dd310d..f8cb8e9 100644 +--- a/tf_slim/layers/layers.py ++++ b/tf_slim/layers/layers.py +@@ -36,12 +36,6 @@ from tensorflow.python.framework import dtypes + from tensorflow.python.framework import ops + from tensorflow.python.framework import sparse_tensor + from tensorflow.python.framework import tensor_shape +-from tensorflow.python.keras.engine import input_spec +-from tensorflow.python.layers import base +-from tensorflow.python.layers import convolutional as convolutional_layers +-from tensorflow.python.layers import core as core_layers +-from tensorflow.python.layers import normalization as normalization_layers +-from tensorflow.python.layers import pooling as pooling_layers + from tensorflow.python.ops import array_ops + from tensorflow.python.ops import check_ops + from tensorflow.python.ops import custom_gradient +@@ -115,7 +109,7 @@ def avg_pool2d(inputs, + inputs = ops.convert_to_tensor(inputs) + df = ('channels_first' + if data_format and data_format.startswith('NC') else 'channels_last') +- layer = pooling_layers.AveragePooling2D( ++ layer = tf.layers.AveragePooling2D( + pool_size=kernel_size, + strides=stride, + padding=padding, +@@ -164,7 +158,7 @@ def avg_pool3d(inputs, + inputs = ops.convert_to_tensor(inputs) + df = ('channels_first' + if data_format and data_format.startswith('NC') else 'channels_last') +- layer = pooling_layers.AveragePooling3D( ++ layer = tf.layers.AveragePooling3D( + pool_size=kernel_size, + strides=stride, + padding=padding, +@@ -660,7 +654,7 @@ def batch_norm(inputs, + param_regularizers = {} + beta_regularizer = param_regularizers.get('beta') + gamma_regularizer = param_regularizers.get('gamma') +- layer = normalization_layers.BatchNormalization( ++ layer = tf.layers.BatchNormalization( + axis=axis, + momentum=decay, + epsilon=epsilon, +@@ -1056,11 +1050,11 @@ def convolution(inputs, + raise ValueError('Convolution expects input with rank %d, got %d' % + (conv_dims + 2, input_rank)) + if input_rank == 3: +- layer_class = convolutional_layers.Convolution1D ++ layer_class = tf.layers.Conv1D + elif input_rank == 4: +- layer_class = convolutional_layers.Convolution2D ++ layer_class = tf.layers.Conv2D + elif input_rank == 5: +- layer_class = convolutional_layers.Convolution3D ++ layer_class = tf.layers.Conv3D + else: + raise ValueError('Convolution not supported for input with rank', + input_rank) +@@ -1428,7 +1422,7 @@ def convolution2d_transpose( + + df = ('channels_first' + if data_format and data_format.startswith('NC') else 'channels_last') +- layer = convolutional_layers.Convolution2DTranspose( ++ layer = tf.layers.Conv2DTranspose( + filters=num_outputs, + kernel_size=kernel_size, + strides=stride, +@@ -1542,7 +1536,7 @@ def convolution3d_transpose( + + df = ('channels_first' + if data_format and data_format.startswith('NC') else 'channels_last') +- layer = convolutional_layers.Convolution3DTranspose( ++ layer = tf.layers.Conv3DTranspose( + filters=num_outputs, + kernel_size=kernel_size, + strides=stride, +@@ -1635,7 +1629,7 @@ def dropout(inputs, + with variable_scope.variable_scope( + scope, 'Dropout', [inputs], custom_getter=_model_variable_getter) as sc: + inputs = ops.convert_to_tensor(inputs) +- layer = core_layers.Dropout( ++ layer = tf.layers.Dropout( + rate=1 - keep_prob, + noise_shape=noise_shape, + seed=seed, +@@ -1663,7 +1657,7 @@ def flatten(inputs, outputs_collections=None, scope=None): + """ + with ops.name_scope(scope, 'Flatten', [inputs]) as sc: + inputs = ops.convert_to_tensor(inputs) +- outputs = core_layers.flatten(inputs) ++ outputs = tf.layers.flatten(inputs) + return utils.collect_named_outputs(outputs_collections, sc, outputs) + + +@@ -1881,7 +1875,7 @@ def fully_connected(inputs, + reuse=reuse, + custom_getter=layer_variable_getter) as sc: + inputs = ops.convert_to_tensor(inputs) +- layer = core_layers.Dense( ++ layer = tf.layers.Dense( + units=num_outputs, + activation=None, + use_bias=not normalizer_fn and biases_initializer, +@@ -1914,7 +1908,8 @@ def fully_connected(inputs, + return utils.collect_named_outputs(outputs_collections, sc.name, outputs) + + +-class GDN(base.Layer): ++# pylint: disable=g-classes-have-attributes ++class GDN(tf.layers.Layer): + """Generalized divisive normalization layer. + + Based on the papers: +@@ -2000,7 +1995,7 @@ class GDN(base.Layer): + self._reparam_offset = reparam_offset + self.data_format = data_format + self._channel_axis() # trigger ValueError early +- self.input_spec = input_spec.InputSpec(min_ndim=3, max_ndim=5) ++ self.input_spec = tf.layers.InputSpec(min_ndim=3, max_ndim=5) + + def _channel_axis(self): + try: +@@ -2056,7 +2051,7 @@ class GDN(base.Layer): + raise ValueError('The channel dimension of the inputs to `GDN` ' + 'must be defined.') + self._input_rank = input_shape.ndims +- self.input_spec = input_spec.InputSpec( ++ self.input_spec = tf.layers.InputSpec( + ndim=input_shape.ndims, axes={channel_axis: num_channels}) + + pedestal = array_ops.constant(self._reparam_offset**2, dtype=self.dtype) +@@ -2437,7 +2432,7 @@ def max_pool2d(inputs, + inputs = ops.convert_to_tensor(inputs) + df = ('channels_first' + if data_format and data_format.startswith('NC') else 'channels_last') +- layer = pooling_layers.MaxPooling2D( ++ layer = tf.layers.MaxPooling2D( + pool_size=kernel_size, + strides=stride, + padding=padding, +@@ -2487,7 +2482,7 @@ def max_pool3d(inputs, + inputs = ops.convert_to_tensor(inputs) + df = ('channels_first' + if data_format and data_format.startswith('NC') else 'channels_last') +- layer = pooling_layers.MaxPooling3D( ++ layer = tf.layers.MaxPooling3D( + pool_size=kernel_size, + strides=stride, + padding=padding, +@@ -2777,7 +2772,7 @@ def separable_convolution2d( + if data_format and data_format.startswith('NC') else 'channels_last') + if num_outputs is not None: + # Apply separable conv using the SeparableConvolution2D layer. +- layer = convolutional_layers.SeparableConvolution2D( ++ layer = tf.layers.SeparableConv2D( + filters=num_outputs, + kernel_size=kernel_size, + strides=stride, +diff --git a/tf_slim/layers/rev_block_lib.py b/tf_slim/layers/rev_block_lib.py +index ef85a7f..4d52bfc 100644 +--- a/tf_slim/layers/rev_block_lib.py ++++ b/tf_slim/layers/rev_block_lib.py +@@ -33,13 +33,14 @@ import re + import numpy as np + import six + from six.moves import xrange # pylint: disable=redefined-builtin ++import tensorflow.compat.v1 as tf ++ + # pylint: disable=g-direct-tensorflow-import + from tf_slim.ops import arg_scope as arg_scope_lib + from tensorflow.python import tf2 + from tensorflow.python.eager import backprop + from tensorflow.python.framework import dtypes + from tensorflow.python.framework import ops as framework_ops +-from tensorflow.python.layers import base + from tensorflow.python.ops import array_ops + from tensorflow.python.ops import control_flow_ops + from tensorflow.python.ops import control_flow_util +@@ -180,7 +181,7 @@ def _scope_wrap(fn, scope): + return wrap + + +-class RevBlock(base.Layer): ++class RevBlock(tf.layers.Layer): + """Block of reversible layers. See rev_block.""" + + def __init__(self, +diff --git a/tf_slim/layers/rev_block_lib_test.py b/tf_slim/layers/rev_block_lib_test.py +index b402f44..f72884c 100644 +--- a/tf_slim/layers/rev_block_lib_test.py ++++ b/tf_slim/layers/rev_block_lib_test.py +@@ -26,9 +26,6 @@ from tf_slim.layers import rev_block_lib + from tensorflow.python.framework import dtypes + from tensorflow.python.framework import ops + from tensorflow.python.framework import random_seed +-from tensorflow.python.layers import convolutional +-from tensorflow.python.layers import core as core_layers +-from tensorflow.python.layers import normalization as normalization_layers + from tensorflow.python.ops import array_ops + from tensorflow.python.ops import gradients_impl + from tensorflow.python.ops import init_ops +@@ -52,10 +49,10 @@ class RevBlockTest(test.TestCase): + def testForwardBackward(self): + + def f(x): +- return core_layers.dense(x, self.CHANNELS // 2, use_bias=True) ++ return tf.layers.dense(x, self.CHANNELS // 2, use_bias=True) + + def g(x): +- return core_layers.dense(x, self.CHANNELS // 2, use_bias=True) ++ return tf.layers.dense(x, self.CHANNELS // 2, use_bias=True) + + x = random_ops.random_uniform( + [self.BATCH_SIZE, self.CHANNELS], dtype=dtypes.float32) +@@ -75,10 +72,10 @@ class RevBlockTest(test.TestCase): + def testBackwardForward(self): + + def f(x): +- return core_layers.dense(x, self.CHANNELS // 2, use_bias=True) ++ return tf.layers.dense(x, self.CHANNELS // 2, use_bias=True) + + def g(x): +- return core_layers.dense(x, self.CHANNELS // 2, use_bias=True) ++ return tf.layers.dense(x, self.CHANNELS // 2, use_bias=True) + + y = random_ops.random_uniform( + [self.BATCH_SIZE, self.CHANNELS], dtype=dtypes.float32) +@@ -106,12 +103,12 @@ class RevBlockTest(test.TestCase): + if f is None: + + def f(x): # pylint: disable=function-redefined +- return core_layers.dense(x, self.CHANNELS // 2, use_bias=True) ++ return tf.layers.dense(x, self.CHANNELS // 2, use_bias=True) + + if g is None: + + def g(x): # pylint: disable=function-redefined +- return core_layers.dense(x, self.CHANNELS // 2, use_bias=True) ++ return tf.layers.dense(x, self.CHANNELS // 2, use_bias=True) + + if f_side_input is None: + f_side_input = [] +@@ -173,7 +170,7 @@ class RevBlockTest(test.TestCase): + [self.BATCH_SIZE, self.CHANNELS // 2]) + + def f(x, side_input): +- return core_layers.dense( ++ return tf.layers.dense( + x, self.CHANNELS // 2, use_bias=True) + side_input[0] + + self._testRevBlock(f=f, f_side_input=[f_side_input]) +@@ -181,10 +178,10 @@ class RevBlockTest(test.TestCase): + def testMultipleFns(self): + + def f1(x): +- return core_layers.dense(x, self.CHANNELS // 2) ++ return tf.layers.dense(x, self.CHANNELS // 2) + + def f2(x): +- return core_layers.dense(x, self.CHANNELS // 2, activation=nn_ops.relu) ++ return tf.layers.dense(x, self.CHANNELS // 2, activation=nn_ops.relu) + + self._testRevBlock(f=[f1, f2, f1, f2]) + +@@ -194,9 +191,9 @@ class RevBlockTest(test.TestCase): + [self.BATCH_SIZE, 10, self.CHANNELS], dtype=dtypes.float32) + + def f(x): +- x = convolutional.conv1d(x, self.CHANNELS // 2, 3, padding="same") ++ x = tf.layers.conv1d(x, self.CHANNELS // 2, 3, padding="same") + x = layers.batch_norm(x, is_training=False) +- x = convolutional.conv1d(x, self.CHANNELS // 2, 3, padding="same") ++ x = tf.layers.conv1d(x, self.CHANNELS // 2, 3, padding="same") + x = layers.batch_norm(x, is_training=False) + return x + +@@ -205,10 +202,10 @@ class RevBlockTest(test.TestCase): + def testReuse(self): + + def f(x): +- return core_layers.dense(x, self.CHANNELS // 2) ++ return tf.layers.dense(x, self.CHANNELS // 2) + + def g(x): +- return core_layers.dense(x, self.CHANNELS // 2) ++ return tf.layers.dense(x, self.CHANNELS // 2) + + x = random_ops.random_uniform( + [self.BATCH_SIZE, self.CHANNELS], dtype=dtypes.float32) +@@ -243,7 +240,7 @@ class RecomputeTest(test.TestCase): + def layer(x, name=None): + with variable_scope.variable_scope(name, default_name="layer"): + x = layers.layer_norm(x) +- x = convolutional.conv1d( ++ x = tf.layers.conv1d( + x, + 10, + 1, +@@ -315,7 +312,7 @@ class RecomputeTest(test.TestCase): + + @rev_block_lib.recompute_grad + def layer_with_recompute(inputs): +- return core_layers.dense(inputs, 2) ++ return tf.layers.dense(inputs, 2) + + with variable_scope.variable_scope("layer", use_resource=True): + inputs = array_ops.ones((2, 4), dtypes.float32) +@@ -334,7 +331,7 @@ class RecomputeTest(test.TestCase): + @rev_block_lib.recompute_grad + def layer_with_recompute(inputs): + with variable_scope.variable_scope("inner", use_resource=True): +- return core_layers.dense(inputs, 2) ++ return tf.layers.dense(inputs, 2) + + with variable_scope.variable_scope("layer", use_resource=True): + inputs = array_ops.ones((2, 4), dtypes.float32) +@@ -358,8 +355,8 @@ class RecomputeTest(test.TestCase): + @rev_block_lib.recompute_grad + def layer_with_recompute(inputs, is_recomputing=False): + kwarg_values.append(is_recomputing) +- out = core_layers.dense(inputs, 2) +- out = normalization_layers.batch_normalization(out, training=True) ++ out = tf.layers.dense(inputs, 2) ++ out = tf.layers.batch_normalization(out, training=True) + if is_recomputing: + # Ensure that the updates are not duplicated by popping off the latest + # 2 additions. +-- +2.40.1 + diff --git a/recipe/patches/0005-Internal-Google-change.patch b/recipe/patches/0005-Internal-Google-change.patch new file mode 100644 index 0000000..3e28869 --- /dev/null +++ b/recipe/patches/0005-Internal-Google-change.patch @@ -0,0 +1,26 @@ +From e00575ad39d19112a4b1342930825258316cf233 Mon Sep 17 00:00:00 2001 +From: Pulkit Sinha +Date: Mon, 15 Nov 2021 09:56:09 -0800 +Subject: [PATCH 05/30] Internal Google change + +PiperOrigin-RevId: 410009606 +Change-Id: Ie70858ad073cfc02a3481d5891f49fbe17a14b2d +--- + tf_slim/losses/metric_learning.py | 1 - + 1 file changed, 1 deletion(-) + +diff --git a/tf_slim/losses/metric_learning.py b/tf_slim/losses/metric_learning.py +index 7fe6d43..94fafe7 100644 +--- a/tf_slim/losses/metric_learning.py ++++ b/tf_slim/losses/metric_learning.py +@@ -16,7 +16,6 @@ + """Implements various metric learning losses.""" + from __future__ import absolute_import + from __future__ import division +- + from __future__ import print_function + + import importlib +-- +2.40.1 + diff --git a/recipe/patches/0006-Fix-TensorFlow-checkpoint-and-trackable-imports.patch b/recipe/patches/0006-Fix-TensorFlow-checkpoint-and-trackable-imports.patch new file mode 100644 index 0000000..f582367 --- /dev/null +++ b/recipe/patches/0006-Fix-TensorFlow-checkpoint-and-trackable-imports.patch @@ -0,0 +1,73 @@ +From 1385820cc7e89f25eb1c41c688dc6a0aae91acfa Mon Sep 17 00:00:00 2001 +From: Katherine Wu +Date: Wed, 1 Jun 2022 16:06:23 -0700 +Subject: [PATCH 06/30] Fix TensorFlow checkpoint and trackable imports. + +PiperOrigin-RevId: 452406141 +Change-Id: I6230d3bb59e6ecf8f6f961e0af41da809c2c53c8 +--- + pip_pkg.sh | 2 +- + tests_release.sh | 2 +- + tf_slim/training/evaluation.py | 2 +- + tf_slim/training/training_test.py | 2 +- + 4 files changed, 4 insertions(+), 4 deletions(-) + +diff --git a/pip_pkg.sh b/pip_pkg.sh +index 632cb16..37fdbd4 100755 +--- a/pip_pkg.sh ++++ b/pip_pkg.sh +@@ -1,4 +1,4 @@ +-# Copyright 2021 The TF-Slim Authors. ++# Copyright 2022 The TF-Slim Authors. + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. +diff --git a/tests_release.sh b/tests_release.sh +index a719d50..695bcf9 100755 +--- a/tests_release.sh ++++ b/tests_release.sh +@@ -1,4 +1,4 @@ +-# Copyright 2021 The TF-Slim Authors. ++# Copyright 2022 The TF-Slim Authors. + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. +diff --git a/tf_slim/training/evaluation.py b/tf_slim/training/evaluation.py +index fc0cc9f..3755467 100644 +--- a/tf_slim/training/evaluation.py ++++ b/tf_slim/training/evaluation.py +@@ -140,10 +140,10 @@ from __future__ import print_function + import time + import tensorflow.compat.v1 as tf + # pylint: disable=g-direct-tensorflow-import ++from tensorflow.python.checkpoint import checkpoint_management + from tensorflow.python.platform import tf_logging as logging + from tensorflow.python.summary import summary + from tensorflow.python.training import basic_session_run_hooks +-from tensorflow.python.training import checkpoint_management + from tensorflow.python.training import evaluation + from tensorflow.python.training import monitored_session + from tensorflow.python.training import session_run_hook +diff --git a/tf_slim/training/training_test.py b/tf_slim/training/training_test.py +index ebabf3a..555f68a 100644 +--- a/tf_slim/training/training_test.py ++++ b/tf_slim/training/training_test.py +@@ -29,6 +29,7 @@ from tf_slim.layers import layers + from tf_slim.ops import variables as variables_lib + from tf_slim.training import training + # pylint: disable=g-direct-tensorflow-import ++from tensorflow.python.checkpoint import checkpoint_management + from tensorflow.python.framework import constant_op + from tensorflow.python.framework import dtypes + from tensorflow.python.framework import ops +@@ -40,7 +41,6 @@ from tensorflow.python.ops import variables as variables_lib2 + from tensorflow.python.platform import gfile + from tensorflow.python.platform import test + from tensorflow.python.training import basic_session_run_hooks +-from tensorflow.python.training import checkpoint_management + from tensorflow.python.training import gradient_descent + from tensorflow.python.training import monitored_session + from tensorflow.python.training import saver as saver_lib +-- +2.40.1 + diff --git a/recipe/numpy_123_comaptibility.patch b/recipe/patches/0007-NumPy-Fix-NumPy-1.23-compatibility-problems-in-tf_sl.patch similarity index 92% rename from recipe/numpy_123_comaptibility.patch rename to recipe/patches/0007-NumPy-Fix-NumPy-1.23-compatibility-problems-in-tf_sl.patch index 36482a1..64876f5 100644 --- a/recipe/numpy_123_comaptibility.patch +++ b/recipe/patches/0007-NumPy-Fix-NumPy-1.23-compatibility-problems-in-tf_sl.patch @@ -1,7 +1,8 @@ From 550196c9db2b76d9e23bc394f4dd02df78159a6a Mon Sep 17 00:00:00 2001 From: Peter Hawkins Date: Wed, 3 Aug 2022 10:52:02 -0700 -Subject: [PATCH] [NumPy] Fix NumPy 1.23 compatibility problems in tf_slim. +Subject: [PATCH 07/30] [NumPy] Fix NumPy 1.23 compatibility problems in + tf_slim. Multidimensional indexing by non-tuple values no longer works in NumPy 1.23 (https://numpy.org/devdocs/release/1.23.0-notes.html#expired-deprecations). @@ -24,3 +25,6 @@ index d797355..0f988a9 100644 slice_value = ckpt_value[slice_dims] slice_value = slice_value.reshape(var._save_slice_info.var_shape) feed_dict[placeholder_tensor] = slice_value +-- +2.40.1 + diff --git a/recipe/patches/0008-Fix-tests-broken-by-previous-change-list-due-to-smal.patch b/recipe/patches/0008-Fix-tests-broken-by-previous-change-list-due-to-smal.patch new file mode 100644 index 0000000..544001f --- /dev/null +++ b/recipe/patches/0008-Fix-tests-broken-by-previous-change-list-due-to-smal.patch @@ -0,0 +1,27 @@ +From 90a76e567c0fe0aacf42e26bbcf03d30263a10cf Mon Sep 17 00:00:00 2001 +From: TF-Slim Team +Date: Mon, 19 Sep 2022 12:30:22 -0700 +Subject: [PATCH 08/30] Fix tests broken by previous change list due to small + differences in XLA ops. + +PiperOrigin-RevId: 475357125 +Change-Id: If902452fd5c2ecdc7cce69386550a8b965a1a1d2 +--- + tf_slim/layers/layers_test.py | 1 - + 1 file changed, 1 deletion(-) + +diff --git a/tf_slim/layers/layers_test.py b/tf_slim/layers/layers_test.py +index 505df31..0aa91d3 100644 +--- a/tf_slim/layers/layers_test.py ++++ b/tf_slim/layers/layers_test.py +@@ -1367,7 +1367,6 @@ class DropoutTest(test.TestCase): + with self.cached_session(): + images = np.random.uniform(size=(5, height, width, 3)) + output = _layers.dropout(images) +- self.assertEqual(output.op.name.lower(), 'dropout/dropout_1/mul_1') + output.get_shape().assert_is_compatible_with( + ops.convert_to_tensor(images).get_shape()) + +-- +2.40.1 + diff --git a/recipe/patches/0009-NumPy-Remove-references-to-deprecated-NumPy-type-ali.patch b/recipe/patches/0009-NumPy-Remove-references-to-deprecated-NumPy-type-ali.patch new file mode 100644 index 0000000..7afd9e6 --- /dev/null +++ b/recipe/patches/0009-NumPy-Remove-references-to-deprecated-NumPy-type-ali.patch @@ -0,0 +1,41 @@ +From ee0a7611e85bd41834550222b6da8206ddb8ccf0 Mon Sep 17 00:00:00 2001 +From: Peter Hawkins +Date: Wed, 14 Dec 2022 16:38:03 -0800 +Subject: [PATCH 09/30] [NumPy] Remove references to deprecated NumPy type + aliases. + +This change replaces references to a number of deprecated NumPy type aliases (np.bool, np.int, np.float, np.complex, np.object, np.str) with their recommended replacement (bool, int, float, complex, object, str). + +NumPy 1.24 drops the deprecated aliases, so we must remove uses before updating NumPy. + +PiperOrigin-RevId: 495451219 +Change-Id: I7c87c3f78cc55f231f287549e8720f43a06d0758 +--- + tf_slim/layers/sparse_ops_test.py | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/tf_slim/layers/sparse_ops_test.py b/tf_slim/layers/sparse_ops_test.py +index 501e693..bc6d116 100644 +--- a/tf_slim/layers/sparse_ops_test.py ++++ b/tf_slim/layers/sparse_ops_test.py +@@ -86,7 +86,7 @@ class DenseToSparseTensorTest(test.TestCase): + st = sparse_ops.dense_to_sparse_tensor([b'qwe', b'', b'ewq', b'']) + result = sess.run(st) + self.assertEqual(result.indices.dtype, np.int64) +- self.assertEqual(result.values.dtype, np.object) ++ self.assertEqual(result.values.dtype, object) + self.assertEqual(result.dense_shape.dtype, np.int64) + self.assertAllEqual([[0], [2]], result.indices) + self.assertAllEqual([b'qwe', b'ewq'], result.values) +@@ -98,7 +98,7 @@ class DenseToSparseTensorTest(test.TestCase): + [b'qwe', b'', b'ewq', b''], ignore_value=b'qwe') + result = sess.run(st) + self.assertEqual(result.indices.dtype, np.int64) +- self.assertEqual(result.values.dtype, np.object) ++ self.assertEqual(result.values.dtype, object) + self.assertEqual(result.dense_shape.dtype, np.int64) + self.assertAllEqual([[1], [2], [3]], result.indices) + self.assertAllEqual([b'', b'ewq', b''], result.values) +-- +2.40.1 + diff --git a/recipe/patches/0010-NumPy-Remove-references-to-deprecated-NumPy-type-ali.patch b/recipe/patches/0010-NumPy-Remove-references-to-deprecated-NumPy-type-ali.patch new file mode 100644 index 0000000..07d3089 --- /dev/null +++ b/recipe/patches/0010-NumPy-Remove-references-to-deprecated-NumPy-type-ali.patch @@ -0,0 +1,46 @@ +From 68c918af6a1a3fefd70c522d6758723775098906 Mon Sep 17 00:00:00 2001 +From: Peter Hawkins +Date: Tue, 20 Dec 2022 10:01:27 -0800 +Subject: [PATCH 10/30] [NumPy] Remove references to deprecated NumPy type + aliases. + +This change replaces references to a number of deprecated NumPy type aliases (np.bool, np.int, np.float, np.complex, np.object, np.str) with their recommended replacement (bool, int, float, complex, object, str). + +NumPy 1.24 drops the deprecated aliases, so we must remove uses before updating NumPy. + +PiperOrigin-RevId: 496687458 +Change-Id: If3e28221023dd69a4ee50157df787c79ac63c37c +--- + tf_slim/layers/sparse_ops_test.py | 2 +- + tf_slim/losses/metric_learning_test.py | 2 +- + 2 files changed, 2 insertions(+), 2 deletions(-) + +diff --git a/tf_slim/layers/sparse_ops_test.py b/tf_slim/layers/sparse_ops_test.py +index bc6d116..573df88 100644 +--- a/tf_slim/layers/sparse_ops_test.py ++++ b/tf_slim/layers/sparse_ops_test.py +@@ -75,7 +75,7 @@ class DenseToSparseTensorTest(test.TestCase): + st = sparse_ops.dense_to_sparse_tensor([True, False, True, False]) + result = sess.run(st) + self.assertEqual(result.indices.dtype, np.int64) +- self.assertEqual(result.values.dtype, np.bool) ++ self.assertEqual(result.values.dtype, bool) + self.assertEqual(result.dense_shape.dtype, np.int64) + self.assertAllEqual([[0], [2]], result.indices) + self.assertAllEqual([True, True], result.values) +diff --git a/tf_slim/losses/metric_learning_test.py b/tf_slim/losses/metric_learning_test.py +index b0e231e..460de88 100644 +--- a/tf_slim/losses/metric_learning_test.py ++++ b/tf_slim/losses/metric_learning_test.py +@@ -320,7 +320,7 @@ class NpairsLossMultiLabelTest(test.TestCase): + + similarity_matrix = np.matmul(embeddings_anchor, embeddings_positive.T) + +- labels_remapped = np.dot(labels, labels.T).astype(np.float) ++ labels_remapped = np.dot(labels, labels.T).astype(float) + labels_remapped /= np.sum(labels_remapped, 1, keepdims=True) + + xent_loss = math_ops.reduce_mean(nn.softmax_cross_entropy_with_logits( +-- +2.40.1 + diff --git a/recipe/patches/0011-Remove-legacy-references-from-ops.py.patch b/recipe/patches/0011-Remove-legacy-references-from-ops.py.patch new file mode 100644 index 0000000..7be3837 --- /dev/null +++ b/recipe/patches/0011-Remove-legacy-references-from-ops.py.patch @@ -0,0 +1,197 @@ +From c3cfb34a76545d3c5d8d539430c449e80bddf44a Mon Sep 17 00:00:00 2001 +From: Juan Martinez Castellanos +Date: Thu, 26 Jan 2023 14:21:23 -0800 +Subject: [PATCH 11/30] Remove legacy references from `ops.py`. + +This is done to eventually remove the lazy loads in `indexed_slices.py`. + +PiperOrigin-RevId: 504941001 +Change-Id: I8bbecb24a5e553aa9419d0bf5859222cc1b488e5 +--- + tf_slim/layers/optimizers.py | 16 +++++++++------- + tf_slim/learning.py | 11 ++++++----- + tf_slim/learning_test.py | 5 +++-- + tf_slim/training/training.py | 11 ++++++----- + 4 files changed, 24 insertions(+), 19 deletions(-) + +diff --git a/tf_slim/layers/optimizers.py b/tf_slim/layers/optimizers.py +index 1797f2a..ea5ca2f 100644 +--- a/tf_slim/layers/optimizers.py ++++ b/tf_slim/layers/optimizers.py +@@ -22,6 +22,7 @@ from __future__ import print_function + import six + # pylint: disable=g-direct-tensorflow-import + from tensorflow.python.framework import dtypes ++from tensorflow.python.framework import indexed_slices + from tensorflow.python.framework import ops + from tensorflow.python.ops import array_ops + from tensorflow.python.ops import check_ops +@@ -271,7 +272,7 @@ def optimize_loss(loss, + + # Add histograms for variables, gradients and gradient norms. + for gradient, variable in gradients: +- if isinstance(gradient, ops.IndexedSlices): ++ if isinstance(gradient, indexed_slices.IndexedSlices): + grad_values = gradient.values + else: + grad_values = gradient +@@ -395,10 +396,10 @@ def adaptive_clipping_fn(std_factor=2., + for grad in grads: + if grad is None: + clipped_grads.append(None) +- elif isinstance(grad, ops.IndexedSlices): ++ elif isinstance(grad, indexed_slices.IndexedSlices): + clipped_grads.append( +- ops.IndexedSlices(grad.values * factor, grad.indices, +- grad.dense_shape)) ++ indexed_slices.IndexedSlices( ++ grad.values * factor, grad.indices, grad.dense_shape)) + else: + clipped_grads.append(grad * factor) + +@@ -415,7 +416,7 @@ def _add_scaled_noise_to_gradients(grads_and_vars, gradient_noise_scale): + if gradient is None: + noisy_gradients.append(None) + continue +- if isinstance(gradient, ops.IndexedSlices): ++ if isinstance(gradient, indexed_slices.IndexedSlices): + gradient_shape = gradient.dense_shape + else: + gradient_shape = gradient.get_shape() +@@ -432,9 +433,10 @@ def _multiply_gradients(grads_and_vars, gradient_multipliers): + (var in gradient_multipliers or var.name in gradient_multipliers)): + key = var if var in gradient_multipliers else var.name + multiplier = gradient_multipliers[key] +- if isinstance(grad, ops.IndexedSlices): ++ if isinstance(grad, indexed_slices.IndexedSlices): + grad_values = grad.values * multiplier +- grad = ops.IndexedSlices(grad_values, grad.indices, grad.dense_shape) ++ grad = indexed_slices.IndexedSlices( ++ grad_values, grad.indices, grad.dense_shape) + else: + grad *= math_ops.cast(multiplier, grad.dtype) + multiplied_grads_and_vars.append((grad, var)) +diff --git a/tf_slim/learning.py b/tf_slim/learning.py +index 3d4e0a3..6803517 100644 +--- a/tf_slim/learning.py ++++ b/tf_slim/learning.py +@@ -261,6 +261,7 @@ from tensorflow.core.protobuf import config_pb2 + from tensorflow.python.client import timeline + from tensorflow.python.framework import constant_op + from tensorflow.python.framework import errors ++from tensorflow.python.framework import indexed_slices + from tensorflow.python.framework import ops + from tensorflow.python.lib.io import file_io + from tensorflow.python.ops import array_ops +@@ -297,9 +298,9 @@ def clip_gradient_norms(gradients_to_variables, max_norm): + clipped_grads_and_vars = [] + for grad, var in gradients_to_variables: + if grad is not None: +- if isinstance(grad, ops.IndexedSlices): ++ if isinstance(grad, indexed_slices.IndexedSlices): + tmp = clip_ops.clip_by_norm(grad.values, max_norm) +- grad = ops.IndexedSlices(tmp, grad.indices, grad.dense_shape) ++ grad = indexed_slices.IndexedSlices(tmp, grad.indices, grad.dense_shape) + else: + grad = clip_ops.clip_by_norm(grad, max_norm) + clipped_grads_and_vars.append((grad, var)) +@@ -339,9 +340,9 @@ def multiply_gradients(grads_and_vars, gradient_multipliers): + if not isinstance(multiplier, ops.Tensor): + multiplier = constant_op.constant(multiplier, dtype=grad.dtype) + +- if isinstance(grad, ops.IndexedSlices): ++ if isinstance(grad, indexed_slices.IndexedSlices): + tmp = grad.values * multiplier +- grad = ops.IndexedSlices(tmp, grad.indices, grad.dense_shape) ++ grad = indexed_slices.IndexedSlices(tmp, grad.indices, grad.dense_shape) + else: + grad *= multiplier + multiplied_grads_and_vars.append((grad, var)) +@@ -360,7 +361,7 @@ def add_gradients_summaries(grads_and_vars): + summaries = [] + for grad, var in grads_and_vars: + if grad is not None: +- if isinstance(grad, ops.IndexedSlices): ++ if isinstance(grad, indexed_slices.IndexedSlices): + grad_values = grad.values + else: + grad_values = grad +diff --git a/tf_slim/learning_test.py b/tf_slim/learning_test.py +index fee0416..4b749a5 100644 +--- a/tf_slim/learning_test.py ++++ b/tf_slim/learning_test.py +@@ -31,6 +31,7 @@ from tf_slim.layers import layers + from tf_slim.ops import variables as variables_lib2 + + # pylint:disable=g-direct-tensorflow-import ++from tensorflow.python.framework import indexed_slices + from tensorflow.python.framework import ops + from tensorflow.python.framework import random_seed + from tensorflow.python.ops import math_ops +@@ -99,7 +100,7 @@ class ClipGradientNormsTest(test.TestCase): + indices = tf.constant(sparse_grad_indices, dtype=tf.int32) + dense_shape = tf.constant(sparse_grad_dense_shape, dtype=tf.int32) + +- gradient = ops.IndexedSlices(values, indices, dense_shape) ++ gradient = indexed_slices.IndexedSlices(values, indices, dense_shape) + variable = variables_lib.Variable(self._zero_vec, dtype=tf.float32) + + gradients_to_variables = (gradient, variable) +@@ -177,7 +178,7 @@ class MultiplyGradientsTest(test.TestCase): + indices = tf.constant([0, 1, 2], dtype=tf.int32) + dense_shape = tf.constant([self._grad_vec.size], dtype=tf.int32) + +- gradient = ops.IndexedSlices(values, indices, dense_shape) ++ gradient = indexed_slices.IndexedSlices(values, indices, dense_shape) + variable = variables_lib.Variable(tf.zeros((1, 3))) + grad_to_var = (gradient, variable) + gradient_multipliers = {variable: self._multiplier} +diff --git a/tf_slim/training/training.py b/tf_slim/training/training.py +index 2e9a7da..1ece335 100644 +--- a/tf_slim/training/training.py ++++ b/tf_slim/training/training.py +@@ -248,6 +248,7 @@ from __future__ import print_function + + # pylint: disable=g-direct-tensorflow-import + ++from tensorflow.python.framework import indexed_slices + from tensorflow.python.framework import ops + from tensorflow.python.ops import array_ops + from tensorflow.python.ops import clip_ops +@@ -282,7 +283,7 @@ def add_gradients_summaries(grads_and_vars): + summaries = [] + for grad, var in grads_and_vars: + if grad is not None: +- if isinstance(grad, ops.IndexedSlices): ++ if isinstance(grad, indexed_slices.IndexedSlices): + grad_values = grad.values + else: + grad_values = grad +@@ -310,9 +311,9 @@ def clip_gradient_norms(gradients_to_variables, max_norm): + clipped_grads_and_vars = [] + for grad, var in gradients_to_variables: + if grad is not None: +- if isinstance(grad, ops.IndexedSlices): ++ if isinstance(grad, indexed_slices.IndexedSlices): + tmp = clip_ops.clip_by_norm(grad.values, max_norm) +- grad = ops.IndexedSlices(tmp, grad.indices, grad.dense_shape) ++ grad = indexed_slices.IndexedSlices(tmp, grad.indices, grad.dense_shape) + else: + grad = clip_ops.clip_by_norm(grad, max_norm) + clipped_grads_and_vars.append((grad, var)) +@@ -357,10 +358,10 @@ def multiply_gradients(grads_and_vars, gradient_multipliers): + if grad is None: + raise ValueError('Requested multiple of `None` gradient.') + +- if isinstance(grad, ops.IndexedSlices): ++ if isinstance(grad, indexed_slices.IndexedSlices): + tmp = grad.values * ops.convert_to_tensor( + gradient_multipliers[key], dtype=grad.dtype) +- grad = ops.IndexedSlices(tmp, grad.indices, grad.dense_shape) ++ grad = indexed_slices.IndexedSlices(tmp, grad.indices, grad.dense_shape) + else: + grad *= ops.convert_to_tensor( + gradient_multipliers[key], dtype=grad.dtype) +-- +2.40.1 + diff --git a/recipe/patches/0012-Redirect-references-to-stack-and-unstack-to-their-ne.patch b/recipe/patches/0012-Redirect-references-to-stack-and-unstack-to-their-ne.patch new file mode 100644 index 0000000..0ce006c --- /dev/null +++ b/recipe/patches/0012-Redirect-references-to-stack-and-unstack-to-their-ne.patch @@ -0,0 +1,113 @@ +From 0171d4be874f8bc89fb9532eca5b12ac97e5a31e Mon Sep 17 00:00:00 2001 +From: Juan Martinez Castellanos +Date: Fri, 24 Feb 2023 11:58:05 -0800 +Subject: [PATCH 12/30] Redirect references to `stack` and `unstack` to their + new location in `array_ops_stack.py`. + +This is to ultimately remove the circular dependency between `array_ops.py` and `sparse_tensor.py`. + +PiperOrigin-RevId: 512128147 +Change-Id: Ic85522f652af988e4da2c5d9dc6749e437cff86c +--- + tf_slim/data/tfexample_decoder.py | 5 +++-- + tf_slim/layers/layers.py | 5 +++-- + tf_slim/metrics/metric_ops.py | 7 ++++--- + 3 files changed, 10 insertions(+), 7 deletions(-) + +diff --git a/tf_slim/data/tfexample_decoder.py b/tf_slim/data/tfexample_decoder.py +index c5df47e..7d4dc0b 100644 +--- a/tf_slim/data/tfexample_decoder.py ++++ b/tf_slim/data/tfexample_decoder.py +@@ -34,6 +34,7 @@ from tensorflow.python.framework import dtypes + from tensorflow.python.framework import ops + from tensorflow.python.framework import sparse_tensor + from tensorflow.python.ops import array_ops ++from tensorflow.python.ops import array_ops_stack + from tensorflow.python.ops import check_ops + from tensorflow.python.ops import control_flow_ops + from tensorflow.python.ops import image_ops +@@ -200,7 +201,7 @@ class Tensor(ItemHandler): + if isinstance(shape_dim, sparse_tensor.SparseTensor): + shape_dim = sparse_ops.sparse_tensor_to_dense(shape_dim) + shape_dims.append(shape_dim) +- shape = array_ops.reshape(array_ops.stack(shape_dims), [-1]) ++ shape = array_ops.reshape(array_ops_stack.stack(shape_dims), [-1]) + if isinstance(tensor, sparse_tensor.SparseTensor): + if shape is not None: + tensor = sparse_ops.sparse_reshape(tensor, shape) +@@ -334,7 +335,7 @@ class SparseTensor(ItemHandler): + rank = indices_shape[1] + ids = math_ops.cast(indices.values, dtypes.int64) + indices_columns_to_preserve = array_ops.slice( +- indices.indices, [0, 0], array_ops.stack([-1, rank - 1])) ++ indices.indices, [0, 0], array_ops_stack.stack([-1, rank - 1])) + new_indices = array_ops.concat( + [indices_columns_to_preserve, array_ops.reshape(ids, [-1, 1])], 1) + +diff --git a/tf_slim/layers/layers.py b/tf_slim/layers/layers.py +index f8cb8e9..c91cc1d 100644 +--- a/tf_slim/layers/layers.py ++++ b/tf_slim/layers/layers.py +@@ -37,6 +37,7 @@ from tensorflow.python.framework import ops + from tensorflow.python.framework import sparse_tensor + from tensorflow.python.framework import tensor_shape + from tensorflow.python.ops import array_ops ++from tensorflow.python.ops import array_ops_stack # pylint: disable=g-direct-tensorflow-import + from tensorflow.python.ops import check_ops + from tensorflow.python.ops import custom_gradient + from tensorflow.python.ops import init_ops +@@ -3317,10 +3318,10 @@ def legacy_fully_connected(x, + y = nn.bias_add(y, b) + + if len(dims) > 2: +- out_shape = array_ops.unstack(array_ops.shape(x)) ++ out_shape = array_ops_stack.unstack(array_ops.shape(x)) + out_shape[-1] = num_output_units + +- y = array_ops.reshape(y, array_ops.stack(out_shape)) ++ y = array_ops.reshape(y, array_ops_stack.stack(out_shape)) + + static_shape = x.get_shape().as_list() + static_shape[-1] = num_output_units +diff --git a/tf_slim/metrics/metric_ops.py b/tf_slim/metrics/metric_ops.py +index cdd844c..d87afb3 100644 +--- a/tf_slim/metrics/metric_ops.py ++++ b/tf_slim/metrics/metric_ops.py +@@ -26,6 +26,7 @@ import tensorflow.compat.v1 as tf + from tensorflow.python.framework import dtypes + from tensorflow.python.framework import ops + from tensorflow.python.ops import array_ops ++from tensorflow.python.ops import array_ops_stack # pylint: disable=g-direct-tensorflow-import + from tensorflow.python.ops import check_ops + from tensorflow.python.ops import confusion_matrix + from tensorflow.python.ops import control_flow_ops +@@ -748,7 +749,7 @@ def _streaming_confusion_matrix_at_thresholds(predictions, + num_predictions = array_ops.shape(predictions_2d)[0] + thresh_tiled = array_ops.tile( + array_ops.expand_dims(array_ops.constant(thresholds), [1]), +- array_ops.stack([1, num_predictions])) ++ array_ops_stack.stack([1, num_predictions])) + + # Tile the predictions after thresholding them across different thresholds. + pred_is_pos = math_ops.greater( +@@ -947,7 +948,7 @@ def streaming_curve_points(labels=None, + + xs, ys = compute_points(values['tp'], values['fn'], values['tn'], + values['fp']) +- points = array_ops.stack([xs, ys], axis=1) ++ points = array_ops_stack.stack([xs, ys], axis=1) + update_op = control_flow_ops.group(*update_ops.values()) + + if metrics_collections: +@@ -3629,7 +3630,7 @@ def streaming_concat(values, + def reallocate(): + """Reallocates the varible to the next size.""" + next_size = _next_array_size(new_size) +- next_shape = array_ops.stack([next_size] + fixed_shape) ++ next_shape = array_ops_stack.stack([next_size] + fixed_shape) + new_value = array_ops.zeros(next_shape, dtype=values.dtype) + old_value = array.value() + with ops.control_dependencies([old_value]): +-- +2.40.1 + diff --git a/recipe/patches/0013-Refactor-case-and-case_v2-out-of-control_flow_ops.py.patch b/recipe/patches/0013-Refactor-case-and-case_v2-out-of-control_flow_ops.py.patch new file mode 100644 index 0000000..bacfa6e --- /dev/null +++ b/recipe/patches/0013-Refactor-case-and-case_v2-out-of-control_flow_ops.py.patch @@ -0,0 +1,61 @@ +From 2b8351c823e1b96e31a5bb92afda904772ea9fdc Mon Sep 17 00:00:00 2001 +From: Fiona Lang +Date: Tue, 28 Feb 2023 14:23:19 -0800 +Subject: [PATCH 13/30] Refactor `case` and `case_v2` out of + `control_flow_ops.py`. + +This is the first prerequisite step for refactoring `cond` out of `control_flow_ops.py` which is needed to eliminate circular dependencies. + +PiperOrigin-RevId: 513038726 +Change-Id: I60858e253277e5d684322e7479d535b412253366 +--- + tf_slim/data/tfexample_decoder.py | 3 ++- + tf_slim/data/tfexample_decoder_test.py | 4 ++-- + 2 files changed, 4 insertions(+), 3 deletions(-) + +diff --git a/tf_slim/data/tfexample_decoder.py b/tf_slim/data/tfexample_decoder.py +index 7d4dc0b..e58fcc8 100644 +--- a/tf_slim/data/tfexample_decoder.py ++++ b/tf_slim/data/tfexample_decoder.py +@@ -36,6 +36,7 @@ from tensorflow.python.framework import sparse_tensor + from tensorflow.python.ops import array_ops + from tensorflow.python.ops import array_ops_stack + from tensorflow.python.ops import check_ops ++from tensorflow.python.ops import control_flow_case + from tensorflow.python.ops import control_flow_ops + from tensorflow.python.ops import image_ops + from tensorflow.python.ops import map_fn +@@ -451,7 +452,7 @@ class Image(ItemHandler): + math_ops.equal(image_format, 'raw'), + math_ops.equal(image_format, 'RAW')), decode_raw)] + +- image = control_flow_ops.case( ++ image = control_flow_case.case( + pred_fn_pairs, default=check_jpeg, exclusive=True) + + image.set_shape([None, None, self._channels]) +diff --git a/tf_slim/data/tfexample_decoder_test.py b/tf_slim/data/tfexample_decoder_test.py +index 3cb140e..abed2a3 100644 +--- a/tf_slim/data/tfexample_decoder_test.py ++++ b/tf_slim/data/tfexample_decoder_test.py +@@ -27,7 +27,7 @@ from tf_slim.data import tfexample_decoder + from google.protobuf import text_format + # pylint:disable=g-direct-tensorflow-import + from tensorflow.python.ops import array_ops +-from tensorflow.python.ops import control_flow_ops ++from tensorflow.python.ops import control_flow_case + from tensorflow.python.ops import image_ops + from tensorflow.python.ops import lookup_ops + from tensorflow.python.ops import math_ops +@@ -723,7 +723,7 @@ class TFExampleDecoderTest(test.TestCase): + def DecodeJpg(): + return image_ops.decode_jpeg(image_buffer, 3) + +- image = control_flow_ops.case( ++ image = control_flow_case.case( + { + math_ops.equal(image_format, 'png'): DecodePng, + }, +-- +2.40.1 + diff --git a/recipe/patches/0014-Move-control_flow_ops.Assert-into-its-own-file-contr.patch b/recipe/patches/0014-Move-control_flow_ops.Assert-into-its-own-file-contr.patch new file mode 100644 index 0000000..701d852 --- /dev/null +++ b/recipe/patches/0014-Move-control_flow_ops.Assert-into-its-own-file-contr.patch @@ -0,0 +1,56 @@ +From 7a19ed0643c2b973bc441f40c2322520e7f64d85 Mon Sep 17 00:00:00 2001 +From: Fiona Lang +Date: Fri, 3 Mar 2023 09:44:31 -0800 +Subject: [PATCH 14/30] Move `control_flow_ops.Assert` into its own file, + `control_flow_assert.py`, as a first step in removing circular dependencies + with `control_flow_ops.cond`. + +PiperOrigin-RevId: 513851275 +Change-Id: I5f66f085183c3c640a05f6cb24052c2ecfb1e29d +--- + tf_slim/metrics/histogram_ops.py | 22 +++++++++++++--------- + 1 file changed, 13 insertions(+), 9 deletions(-) + +diff --git a/tf_slim/metrics/histogram_ops.py b/tf_slim/metrics/histogram_ops.py +index dd75c44..b606647 100644 +--- a/tf_slim/metrics/histogram_ops.py ++++ b/tf_slim/metrics/histogram_ops.py +@@ -25,6 +25,7 @@ from tensorflow.python.framework import dtypes + from tensorflow.python.framework import ops + from tensorflow.python.ops import array_ops + from tensorflow.python.ops import confusion_matrix as cm ++from tensorflow.python.ops import control_flow_assert + from tensorflow.python.ops import control_flow_ops + from tensorflow.python.ops import histogram_ops + from tensorflow.python.ops import init_ops +@@ -104,15 +105,18 @@ def _check_labels_and_scores(boolean_labels, scores, check_shape): + boolean_labels.dtype) + + if check_shape: +- labels_rank_1 = control_flow_ops.Assert( +- math_ops.equal(1, array_ops.rank(boolean_labels)), +- ['Argument boolean_labels should have rank 1. Found: ', +- boolean_labels.name, array_ops.shape(boolean_labels)]) +- +- scores_rank_1 = control_flow_ops.Assert( +- math_ops.equal(1, array_ops.rank(scores)), +- ['Argument scores should have rank 1. Found: ', scores.name, +- array_ops.shape(scores)]) ++ labels_rank_1 = control_flow_assert.Assert( ++ math_ops.equal(1, array_ops.rank(boolean_labels)), [ ++ 'Argument boolean_labels should have rank 1. Found: ', ++ boolean_labels.name, ++ array_ops.shape(boolean_labels) ++ ]) ++ ++ scores_rank_1 = control_flow_assert.Assert( ++ math_ops.equal(1, array_ops.rank(scores)), [ ++ 'Argument scores should have rank 1. Found: ', scores.name, ++ array_ops.shape(scores) ++ ]) + + with ops.control_dependencies([labels_rank_1, scores_rank_1]): + return boolean_labels, scores +-- +2.40.1 + diff --git a/recipe/patches/0015-Move-control_flow_ops.while_loop-into-its-own-file-w.patch b/recipe/patches/0015-Move-control_flow_ops.while_loop-into-its-own-file-w.patch new file mode 100644 index 0000000..e509b2a --- /dev/null +++ b/recipe/patches/0015-Move-control_flow_ops.while_loop-into-its-own-file-w.patch @@ -0,0 +1,97 @@ +From bf7b6395bf497ca3131660f78fbc166454904325 Mon Sep 17 00:00:00 2001 +From: Fiona Lang +Date: Tue, 7 Mar 2023 10:49:39 -0800 +Subject: [PATCH 15/30] Move control_flow_ops.while_loop into its own file, + while_loop.py. + +This removes circular dependencies that pass through while_v2 through control_flow_ops. + +PiperOrigin-RevId: 514780017 +Change-Id: I8a5fddf9bde9a3ff91e5892b1b7b3714dfbcdfc2 +--- + tf_slim/losses/metric_learning.py | 27 +++++++++++++++------------ + 1 file changed, 15 insertions(+), 12 deletions(-) + +diff --git a/tf_slim/losses/metric_learning.py b/tf_slim/losses/metric_learning.py +index 94fafe7..8d53955 100644 +--- a/tf_slim/losses/metric_learning.py ++++ b/tf_slim/losses/metric_learning.py +@@ -26,12 +26,12 @@ from tensorflow.python.framework import ops + from tensorflow.python.framework import sparse_tensor + from tensorflow.python.framework import tensor_shape + from tensorflow.python.ops import array_ops +-from tensorflow.python.ops import control_flow_ops + from tensorflow.python.ops import logging_ops + from tensorflow.python.ops import math_ops + from tensorflow.python.ops import nn + from tensorflow.python.ops import script_ops + from tensorflow.python.ops import sparse_ops ++from tensorflow.python.ops import while_loop + from tensorflow.python.summary import summary + try: + # pylint: disable=g-import-not-at-top +@@ -718,8 +718,8 @@ def _find_loss_augmented_facility_idx(pairwise_distances, labels, chosen_ids, + return iteration + 1, nmi_scores + array_ops.concat( + [pad_before, [1.0 - nmi_score_i], pad_after], 0) + +- _, nmi_scores = control_flow_ops.while_loop( +- func_cond, func_body, [iteration, nmi_scores]) ++ _, nmi_scores = while_loop.while_loop(func_cond, func_body, ++ [iteration, nmi_scores]) + + candidate_scores = math_ops.add( + candidate_scores, margin_multiplier * nmi_scores) +@@ -767,11 +767,13 @@ def compute_augmented_facility_locations(pairwise_distances, labels, all_ids, + # num_classes get determined at run time based on the sampled batch. + iteration = array_ops.constant(0) + +- _, chosen_ids = control_flow_ops.while_loop( ++ _, chosen_ids = while_loop.while_loop( + func_cond_augmented, + func_body_augmented, [iteration, chosen_ids], +- shape_invariants=[iteration.get_shape(), tensor_shape.TensorShape( +- [None])]) ++ shape_invariants=[ ++ iteration.get_shape(), ++ tensor_shape.TensorShape([None]) ++ ]) + return chosen_ids + + +@@ -820,8 +822,8 @@ def update_medoid_per_cluster(pairwise_distances, pairwise_distances_subset, + num_candidates = array_ops.size(cluster_member_ids) + scores_margin = array_ops.zeros([num_candidates]) + +- _, scores_margin = control_flow_ops.while_loop(func_cond, func_body, +- [iteration, scores_margin]) ++ _, scores_margin = while_loop.while_loop(func_cond, func_body, ++ [iteration, scores_margin]) + candidate_scores = math_ops.add(scores_fac, margin_multiplier * scores_margin) + + argmax_index = math_ops.cast( +@@ -876,8 +878,9 @@ def update_all_medoids(pairwise_distances, predictions, labels, chosen_ids, + num_classes = array_ops.size(unique_class_ids) + iteration = array_ops.constant(0) + +- _, chosen_ids = control_flow_ops.while_loop( +- func_cond_augmented_pam, func_body_augmented_pam, [iteration, chosen_ids]) ++ _, chosen_ids = while_loop.while_loop(func_cond_augmented_pam, ++ func_body_augmented_pam, ++ [iteration, chosen_ids]) + return chosen_ids + + +@@ -949,8 +952,8 @@ def compute_gt_cluster_score(pairwise_distances, labels): + pairwise_distances_subset, axis=0)) + return iteration + 1, gt_cluster_score + this_cluster_score + +- _, gt_cluster_score = control_flow_ops.while_loop( +- func_cond, func_body, [iteration, gt_cluster_score]) ++ _, gt_cluster_score = while_loop.while_loop(func_cond, func_body, ++ [iteration, gt_cluster_score]) + return gt_cluster_score + + +-- +2.40.1 + diff --git a/recipe/patches/0016-Redirect-references-from-control_flow_ops.cond-to-co.patch b/recipe/patches/0016-Redirect-references-from-control_flow_ops.cond-to-co.patch new file mode 100644 index 0000000..ecd9701 --- /dev/null +++ b/recipe/patches/0016-Redirect-references-from-control_flow_ops.cond-to-co.patch @@ -0,0 +1,136 @@ +From 5876c8a76d24660552e5d703508194a92d4fabd2 Mon Sep 17 00:00:00 2001 +From: Fiona Lang +Date: Wed, 15 Mar 2023 23:04:22 -0700 +Subject: [PATCH 16/30] Redirect references from `control_flow_ops.cond` to + `cond.cond`. + +This is to ultimately remove the circular dependencies that pass from `control_flow_ops.py` to `cond_v2.py`. + +PiperOrigin-RevId: 517030581 +Change-Id: Ib8bd5df8ffb4a91e46be6b3d1259efcb240bf9ba +--- + tf_slim/data/tfexample_decoder.py | 6 +++--- + tf_slim/layers/utils.py | 4 ++-- + tf_slim/metrics/metric_ops.py | 17 +++++++++-------- + 3 files changed, 14 insertions(+), 13 deletions(-) + +diff --git a/tf_slim/data/tfexample_decoder.py b/tf_slim/data/tfexample_decoder.py +index e58fcc8..7be7f44 100644 +--- a/tf_slim/data/tfexample_decoder.py ++++ b/tf_slim/data/tfexample_decoder.py +@@ -36,8 +36,8 @@ from tensorflow.python.framework import sparse_tensor + from tensorflow.python.ops import array_ops + from tensorflow.python.ops import array_ops_stack + from tensorflow.python.ops import check_ops ++from tensorflow.python.ops import cond + from tensorflow.python.ops import control_flow_case +-from tensorflow.python.ops import control_flow_ops + from tensorflow.python.ops import image_ops + from tensorflow.python.ops import map_fn + from tensorflow.python.ops import math_ops +@@ -277,7 +277,7 @@ class BackupHandler(ItemHandler): + + def tensors_to_item(self, keys_to_tensors): + item = self._handler.tensors_to_item(keys_to_tensors) +- return control_flow_ops.cond( ++ return cond.cond( + pred=math_ops.equal(math_ops.reduce_prod(array_ops.shape(item)), 0), + true_fn=lambda: self._backup.tensors_to_item(keys_to_tensors), + false_fn=lambda: item) +@@ -438,7 +438,7 @@ class Image(ItemHandler): + """Checks if an image is jpeg.""" + # For jpeg, we directly use image_ops.decode_jpeg rather than decode_image + # in order to feed the jpeg specify parameter 'dct_method'. +- return control_flow_ops.cond( ++ return cond.cond( + image_ops.is_jpeg(image_buffer), + decode_jpeg, + decode_image, +diff --git a/tf_slim/layers/utils.py b/tf_slim/layers/utils.py +index 8c9e28b..5a4a664 100644 +--- a/tf_slim/layers/utils.py ++++ b/tf_slim/layers/utils.py +@@ -26,7 +26,7 @@ from collections import OrderedDict + from tensorflow.python.framework import ops + from tensorflow.python.framework import tensor_shape + from tensorflow.python.framework import tensor_util +-from tensorflow.python.ops import control_flow_ops ++from tensorflow.python.ops import cond + from tensorflow.python.ops import variables + + __all__ = ['collect_named_outputs', +@@ -217,7 +217,7 @@ def smart_cond(pred, fn1, fn2, name=None): + return static_cond(pred_value, fn1, fn2) + else: + # Use dynamic cond otherwise. +- return control_flow_ops.cond(pred, fn1, fn2, name) ++ return cond.cond(pred, fn1, fn2, name) + + + def get_variable_collections(variables_collections, name): +diff --git a/tf_slim/metrics/metric_ops.py b/tf_slim/metrics/metric_ops.py +index d87afb3..ded2f25 100644 +--- a/tf_slim/metrics/metric_ops.py ++++ b/tf_slim/metrics/metric_ops.py +@@ -28,6 +28,7 @@ from tensorflow.python.framework import ops + from tensorflow.python.ops import array_ops + from tensorflow.python.ops import array_ops_stack # pylint: disable=g-direct-tensorflow-import + from tensorflow.python.ops import check_ops ++from tensorflow.python.ops import cond + from tensorflow.python.ops import confusion_matrix + from tensorflow.python.ops import control_flow_ops + from tensorflow.python.ops import math_ops +@@ -1129,7 +1130,7 @@ def _compute_dynamic_auc(labels, predictions, curve='ROC', weights=None): + + # If all the labels are the same, AUC isn't well-defined (but raising an + # exception seems excessive) so we return 0, otherwise we finish computing. +- return control_flow_ops.cond( ++ return cond.cond( + math_ops.logical_or( + math_ops.equal(total_positive, 0), + math_ops.equal(total_positive, total_weight)), +@@ -1388,7 +1389,7 @@ def _compute_placement_auc(labels, predictions, weights, alpha, + # exception seems excessive) so we return 0, otherwise we finish computing. + trivial_value = array_ops.constant(0.0) + +- return AucData(*control_flow_ops.cond( ++ return AucData(*cond.cond( + is_valid, lambda: [auc, lower, upper], lambda: [trivial_value] * 3)) + + +@@ -1492,7 +1493,7 @@ def auc_with_confidence_intervals(labels, + is_valid = math_ops.logical_and(all_labels_positive_or_0, + sums_of_weights_at_least_1) + +- update_op = control_flow_ops.cond( ++ update_op = cond.cond( + sums_of_weights_at_least_1, lambda: update_op_for_valid_case, + control_flow_ops.no_op) + +@@ -2546,8 +2547,8 @@ def _compute_recall_at_precision(tp, fp, fn, precision, name, + return math_ops.div(tp[tf_index], tp[tf_index] + fn[tf_index] + _EPSILON, + name) + +- return control_flow_ops.cond(precisions[tf_index] >= precision, +- _return_good_recall, lambda: .0) ++ return cond.cond(precisions[tf_index] >= precision, ++ _return_good_recall, lambda: .0) + + + def recall_at_precision(labels, +@@ -3643,9 +3644,9 @@ def streaming_concat(values, + + new_size = size + batch_size + array_size = array_ops.shape_internal(array, optimize=False)[0] +- maybe_reallocate_op = control_flow_ops.cond(new_size > array_size, +- reallocate, +- control_flow_ops.no_op) ++ maybe_reallocate_op = cond.cond(new_size > array_size, ++ reallocate, ++ control_flow_ops.no_op) + with ops.control_dependencies([maybe_reallocate_op]): + append_values_op = array[size:new_size].assign(batch_values) + with ops.control_dependencies([append_values_op]): +-- +2.40.1 + diff --git a/recipe/patches/0017-Update-some-isinstance-checks-of-tf.compat.v1.Variab.patch b/recipe/patches/0017-Update-some-isinstance-checks-of-tf.compat.v1.Variab.patch new file mode 100644 index 0000000..2822fe2 --- /dev/null +++ b/recipe/patches/0017-Update-some-isinstance-checks-of-tf.compat.v1.Variab.patch @@ -0,0 +1,455 @@ +From 6ce0c735c31c0b875af5fadc46826241d94843ff Mon Sep 17 00:00:00 2001 +From: Fiona Lang +Date: Wed, 22 Mar 2023 12:03:31 -0700 +Subject: [PATCH 17/30] Update some isinstance checks of + `tf.compat.v1.Variable` to `tf.compat.v2.Variable`. + +Also fix calls to the deprecated Variable.initialized_value implementation by directly copying it to the use cases. + +These changes are in preparation for changing `tensorflow/python/ops/resource_variable_ops.BaseResourceVariable` to inherit from `tensorflow/python/ops/variables.Variable` instead of `tensorflow/python/ops/variables.VariableV1`. + +Since `tensorflow/python/ops/variables.VariableV1` inherits from `tensorflow/python/ops/variables.Variable`, these changes are backwards compatible. + +PiperOrigin-RevId: 518635742 +Change-Id: Ia8a67df33f36147998e72b405347be5dfd869266 +--- + tf_slim/metrics/metric_ops_test.py | 97 +++++++++++++++--------------- + 1 file changed, 49 insertions(+), 48 deletions(-) + +diff --git a/tf_slim/metrics/metric_ops_test.py b/tf_slim/metrics/metric_ops_test.py +index 3d63758..fad934d 100644 +--- a/tf_slim/metrics/metric_ops_test.py ++++ b/tf_slim/metrics/metric_ops_test.py +@@ -24,7 +24,8 @@ import math + import numpy as np + from six.moves import xrange # pylint: disable=redefined-builtin + +-import tensorflow.compat.v1 as tf ++import tensorflow.compat.v1 as tf1 ++import tensorflow.compat.v2 as tf2 + import tf_slim.metrics as metrics_lib + from tf_slim.metrics.metric_ops import _next_array_size + +@@ -43,7 +44,7 @@ from tensorflow.python.ops import variables + + + def setUpModule(): +- tf.disable_eager_execution() ++ tf1.disable_eager_execution() + + + NAN = float('nan') +@@ -165,7 +166,7 @@ def _assert_metric_variables(test_case, expected): + set(v.name for v in ops.get_collection(ops.GraphKeys.METRIC_VARIABLES))) + + +-class StreamingMeanTest(tf.test.TestCase): ++class StreamingMeanTest(tf1.test.TestCase): + + def testVars(self): + metrics.streaming_mean(array_ops.ones([4, 3])) +@@ -320,7 +321,7 @@ class StreamingMeanTest(tf.test.TestCase): + self.assertAlmostEqual((0 + 1 - 4.2 + 0) / 4.0, mean.eval(), 5) + + +-class StreamingMeanTensorTest(tf.test.TestCase): ++class StreamingMeanTensorTest(tf1.test.TestCase): + + def testVars(self): + metrics.streaming_mean_tensor(array_ops.ones([4, 3])) +@@ -480,7 +481,7 @@ class StreamingMeanTensorTest(tf.test.TestCase): + self.assertAllClose([[0, 0.5]], sess.run(mean), 5) + + +-class StreamingAccuracyTest(tf.test.TestCase): ++class StreamingAccuracyTest(tf1.test.TestCase): + + def testVars(self): + metrics.streaming_accuracy( +@@ -654,7 +655,7 @@ class StreamingAccuracyTest(tf.test.TestCase): + self.assertEqual(1.0, accuracy.eval()) + + +-class StreamingTruePositivesTest(tf.test.TestCase): ++class StreamingTruePositivesTest(tf1.test.TestCase): + + def setUp(self): + super(StreamingTruePositivesTest, self).setUp() +@@ -705,7 +706,7 @@ class StreamingTruePositivesTest(tf.test.TestCase): + self.assertEqual(37.0, tp.eval()) + + +-class StreamingFalseNegativesTest(tf.test.TestCase): ++class StreamingFalseNegativesTest(tf1.test.TestCase): + + def setUp(self): + super(StreamingFalseNegativesTest, self).setUp() +@@ -757,7 +758,7 @@ class StreamingFalseNegativesTest(tf.test.TestCase): + self.assertEqual(8.0, fn.eval()) + + +-class StreamingFalsePositivesTest(tf.test.TestCase): ++class StreamingFalsePositivesTest(tf1.test.TestCase): + + def setUp(self): + super(StreamingFalsePositivesTest, self).setUp() +@@ -811,7 +812,7 @@ class StreamingFalsePositivesTest(tf.test.TestCase): + self.assertEqual(42.0, fp.eval()) + + +-class StreamingTrueNegativesTest(tf.test.TestCase): ++class StreamingTrueNegativesTest(tf1.test.TestCase): + + def setUp(self): + super(StreamingTrueNegativesTest, self).setUp() +@@ -863,7 +864,7 @@ class StreamingTrueNegativesTest(tf.test.TestCase): + self.assertEqual(15.0, tn.eval()) + + +-class StreamingTruePositivesAtThresholdsTest(tf.test.TestCase): ++class StreamingTruePositivesAtThresholdsTest(tf1.test.TestCase): + + def setUp(self): + super(StreamingTruePositivesAtThresholdsTest, self).setUp() +@@ -901,7 +902,7 @@ class StreamingTruePositivesAtThresholdsTest(tf.test.TestCase): + self.assertAllEqual((111.0, 37.0, 0.0), tp.eval()) + + +-class StreamingFalseNegativesAtThresholdsTest(tf.test.TestCase): ++class StreamingFalseNegativesAtThresholdsTest(tf1.test.TestCase): + + def setUp(self): + super(StreamingFalseNegativesAtThresholdsTest, self).setUp() +@@ -947,7 +948,7 @@ class StreamingFalseNegativesAtThresholdsTest(tf.test.TestCase): + self.assertAllEqual((0.0, 8.0, 11.0), fn.eval()) + + +-class StreamingFalsePositivesAtThresholdsTest(tf.test.TestCase): ++class StreamingFalsePositivesAtThresholdsTest(tf1.test.TestCase): + + def setUp(self): + super(StreamingFalsePositivesAtThresholdsTest, self).setUp() +@@ -989,7 +990,7 @@ class StreamingFalsePositivesAtThresholdsTest(tf.test.TestCase): + self.assertAllEqual((125.0, 42.0, 12.0), fp.eval()) + + +-class StreamingTrueNegativesAtThresholdsTest(tf.test.TestCase): ++class StreamingTrueNegativesAtThresholdsTest(tf1.test.TestCase): + + def setUp(self): + super(StreamingTrueNegativesAtThresholdsTest, self).setUp() +@@ -1031,7 +1032,7 @@ class StreamingTrueNegativesAtThresholdsTest(tf.test.TestCase): + self.assertAllEqual((5.0, 15.0, 23.0), tn.eval()) + + +-class StreamingPrecisionTest(tf.test.TestCase): ++class StreamingPrecisionTest(tf1.test.TestCase): + + def setUp(self): + super(StreamingPrecisionTest, self).setUp() +@@ -1196,7 +1197,7 @@ class StreamingPrecisionTest(tf.test.TestCase): + self.assertEqual(0.0, precision.eval()) + + +-class StreamingRecallTest(tf.test.TestCase): ++class StreamingRecallTest(tf1.test.TestCase): + + def setUp(self): + super(StreamingRecallTest, self).setUp() +@@ -1320,7 +1321,7 @@ class StreamingRecallTest(tf.test.TestCase): + self.assertEqual(0, recall.eval()) + + +-class StreamingFPRTest(tf.test.TestCase): ++class StreamingFPRTest(tf1.test.TestCase): + + def setUp(self): + super(StreamingFPRTest, self).setUp() +@@ -1444,7 +1445,7 @@ class StreamingFPRTest(tf.test.TestCase): + self.assertEqual(0, fpr.eval()) + + +-class StreamingFNRTest(tf.test.TestCase): ++class StreamingFNRTest(tf1.test.TestCase): + + def setUp(self): + super(StreamingFNRTest, self).setUp() +@@ -1568,7 +1569,7 @@ class StreamingFNRTest(tf.test.TestCase): + self.assertEqual(0, fnr.eval()) + + +-class StreamingCurvePointsTest(tf.test.TestCase): ++class StreamingCurvePointsTest(tf1.test.TestCase): + + def setUp(self): + super(StreamingCurvePointsTest, self).setUp() +@@ -1690,7 +1691,7 @@ def _np_auc(predictions, labels, weights=None): + return np.sum((sorted_weights * tp)[~is_positive]) / num_negatives + + +-class StreamingAUCTest(tf.test.TestCase): ++class StreamingAUCTest(tf1.test.TestCase): + + def setUp(self): + super(StreamingAUCTest, self).setUp() +@@ -1936,7 +1937,7 @@ class StreamingAUCTest(tf.test.TestCase): + self.assertAlmostEqual(expected_auc, auc.eval(), 2) + + +-class StreamingDynamicAUCTest(tf.test.TestCase): ++class StreamingDynamicAUCTest(tf1.test.TestCase): + + def setUp(self): + super(StreamingDynamicAUCTest, self).setUp() +@@ -2181,7 +2182,7 @@ class StreamingDynamicAUCTest(tf.test.TestCase): + self.assertAlmostEqual(expected_auc, auc.eval()) + + +-class AucWithConfidenceIntervalsTest(tf.test.TestCase): ++class AucWithConfidenceIntervalsTest(tf1.test.TestCase): + + def setUp(self): + super(AucWithConfidenceIntervalsTest, self).setUp() +@@ -2382,7 +2383,7 @@ class AucWithConfidenceIntervalsTest(tf.test.TestCase): + sess.run(update_op) + + +-class StreamingPrecisionRecallAtEqualThresholdsTest(tf.test.TestCase): ++class StreamingPrecisionRecallAtEqualThresholdsTest(tf1.test.TestCase): + + def setUp(self): + super(StreamingPrecisionRecallAtEqualThresholdsTest, self).setUp() +@@ -2596,7 +2597,7 @@ class StreamingPrecisionRecallAtEqualThresholdsTest(tf.test.TestCase): + eps=1e-3) + + +-class StreamingSpecificityAtSensitivityTest(tf.test.TestCase): ++class StreamingSpecificityAtSensitivityTest(tf1.test.TestCase): + + def setUp(self): + super(StreamingSpecificityAtSensitivityTest, self).setUp() +@@ -2733,7 +2734,7 @@ class StreamingSpecificityAtSensitivityTest(tf.test.TestCase): + self.assertAlmostEqual(8.0 / 15.0, specificity.eval()) + + +-class StreamingSensitivityAtSpecificityTest(tf.test.TestCase): ++class StreamingSensitivityAtSpecificityTest(tf1.test.TestCase): + + def setUp(self): + super(StreamingSensitivityAtSpecificityTest, self).setUp() +@@ -2850,7 +2851,7 @@ class StreamingSensitivityAtSpecificityTest(tf.test.TestCase): + self.assertAlmostEqual(0.675, specificity.eval()) + + +-class StreamingPrecisionRecallThresholdsTest(tf.test.TestCase): ++class StreamingPrecisionRecallThresholdsTest(tf1.test.TestCase): + + def setUp(self): + super(StreamingPrecisionRecallThresholdsTest, self).setUp() +@@ -3138,7 +3139,7 @@ class StreamingPrecisionRecallThresholdsTest(tf.test.TestCase): + self.assertAlmostEqual(expected_rec, rec.eval(), 2) + + +-class StreamingFPRThresholdsTest(tf.test.TestCase): ++class StreamingFPRThresholdsTest(tf1.test.TestCase): + + def setUp(self): + super(StreamingFPRThresholdsTest, self).setUp() +@@ -3371,7 +3372,7 @@ class StreamingFPRThresholdsTest(tf.test.TestCase): + self.assertAlmostEqual(expected_fpr, fpr.eval(), 2) + + +-class RecallAtPrecisionTest(tf.test.TestCase): ++class RecallAtPrecisionTest(tf1.test.TestCase): + + def setUp(self): + super(RecallAtPrecisionTest, self).setUp() +@@ -3543,7 +3544,7 @@ class RecallAtPrecisionTest(tf.test.TestCase): + strict_mode=True, target_precision=0.2, expected_recall=2.0 / 3) + + +-class PrecisionAtRecallTest(tf.test.TestCase): ++class PrecisionAtRecallTest(tf1.test.TestCase): + + def setUp(self): + super(PrecisionAtRecallTest, self).setUp() +@@ -3676,7 +3677,7 @@ class PrecisionAtRecallTest(tf.test.TestCase): + self.assertAlmostEqual(34.0/43, precision.eval()) + + +-class StreamingFNRThresholdsTest(tf.test.TestCase): ++class StreamingFNRThresholdsTest(tf1.test.TestCase): + + def setUp(self): + super(StreamingFNRThresholdsTest, self).setUp() +@@ -3911,7 +3912,7 @@ class StreamingFNRThresholdsTest(tf.test.TestCase): + + # This test can be removed if `streaming_recall_at_k` is removed. + # Until then, this test validates that both ops yield the same results. +-class StreamingRecallAtKTest(tf.test.TestCase): ++class StreamingRecallAtKTest(tf1.test.TestCase): + + def setUp(self): + super(StreamingRecallAtKTest, self).setUp() +@@ -4031,7 +4032,7 @@ class StreamingRecallAtKTest(tf.test.TestCase): + self.assertEqual(1.0, sp_recall.eval()) + + +-class StreamingSparsePrecisionTest(tf.test.TestCase): ++class StreamingSparsePrecisionTest(tf1.test.TestCase): + + def _test_streaming_sparse_precision_at_k(self, + predictions, +@@ -4703,7 +4704,7 @@ class StreamingSparsePrecisionTest(tf.test.TestCase): + self.assertEqual(expected_precision, precision.eval()) + + +-class StreamingSparseRecallTest(tf.test.TestCase): ++class StreamingSparseRecallTest(tf1.test.TestCase): + + def _test_streaming_sparse_recall_at_k(self, + predictions, +@@ -5408,7 +5409,7 @@ class StreamingSparseRecallTest(tf.test.TestCase): + self.assertEqual(expected_recall, recall.eval()) + + +-class StreamingMeanAbsoluteErrorTest(tf.test.TestCase): ++class StreamingMeanAbsoluteErrorTest(tf1.test.TestCase): + + def testVars(self): + metrics.streaming_mean_absolute_error( +@@ -5466,7 +5467,7 @@ class StreamingMeanAbsoluteErrorTest(tf.test.TestCase): + self.assertEqual(3, error.eval()) + + +-class StreamingMeanRelativeErrorTest(tf.test.TestCase): ++class StreamingMeanRelativeErrorTest(tf1.test.TestCase): + + def testVars(self): + metrics.streaming_mean_relative_error( +@@ -5548,7 +5549,7 @@ class StreamingMeanRelativeErrorTest(tf.test.TestCase): + self.assertEqual(0.0, error.eval()) + + +-class StreamingMeanSquaredErrorTest(tf.test.TestCase): ++class StreamingMeanSquaredErrorTest(tf1.test.TestCase): + + def testVars(self): + metrics.streaming_mean_squared_error( +@@ -5725,7 +5726,7 @@ class StreamingMeanSquaredErrorTest(tf.test.TestCase): + self.assertAlmostEqual(208.0 / 6, mse.eval(), 5) + + +-class StreamingRootMeanSquaredErrorTest(tf.test.TestCase): ++class StreamingRootMeanSquaredErrorTest(tf1.test.TestCase): + + def testVars(self): + metrics.streaming_root_mean_squared_error( +@@ -5813,7 +5814,7 @@ class StreamingRootMeanSquaredErrorTest(tf.test.TestCase): + self.assertAlmostEqual(math.sqrt(13), rmse.eval(), 5) + + +-class StreamingCovarianceTest(tf.test.TestCase): ++class StreamingCovarianceTest(tf1.test.TestCase): + + def testVars(self): + metrics.streaming_covariance( +@@ -5992,7 +5993,7 @@ class StreamingCovarianceTest(tf.test.TestCase): + prev_expected_cov = expected_cov + + +-class StreamingPearsonRTest(tf.test.TestCase): ++class StreamingPearsonRTest(tf1.test.TestCase): + + def testVars(self): + metrics.streaming_pearson_correlation( +@@ -6222,7 +6223,7 @@ class StreamingPearsonRTest(tf.test.TestCase): + sess.run(pearson_r, feed_dict=feed_dict), 5) + + +-class StreamingMeanCosineDistanceTest(tf.test.TestCase): ++class StreamingMeanCosineDistanceTest(tf1.test.TestCase): + + def testVars(self): + metrics.streaming_mean_cosine_distance( +@@ -6364,7 +6365,7 @@ class StreamingMeanCosineDistanceTest(tf.test.TestCase): + self.assertEqual(1.5, error.eval()) + + +-class PcntBelowThreshTest(tf.test.TestCase): ++class PcntBelowThreshTest(tf1.test.TestCase): + + def testVars(self): + metrics.streaming_percentage_less(values=array_ops.ones((10,)), threshold=2) +@@ -6433,7 +6434,7 @@ class PcntBelowThreshTest(tf.test.TestCase): + self.assertAlmostEqual(0.0, pcnt2, 5) + + +-class StreamingMeanIOUTest(tf.test.TestCase): ++class StreamingMeanIOUTest(tf1.test.TestCase): + + def setUp(self): + super(StreamingMeanIOUTest, self).setUp() +@@ -6720,7 +6721,7 @@ class StreamingMeanIOUTest(tf.test.TestCase): + miou.eval()) + + +-class StreamingConcatTest(tf.test.TestCase): ++class StreamingConcatTest(tf1.test.TestCase): + + def setUp(self): + super(StreamingConcatTest, self).setUp() +@@ -6847,7 +6848,7 @@ class StreamingConcatTest(tf.test.TestCase): + self.assertAllEqual([3, 4], concatenated.eval()) + + +-class AggregateMetricsTest(tf.test.TestCase): ++class AggregateMetricsTest(tf1.test.TestCase): + + def testAggregateNoMetricsRaisesValueError(self): + with self.assertRaises(ValueError): +@@ -6880,7 +6881,7 @@ class AggregateMetricsTest(tf.test.TestCase): + self.assertEqual(4, value_tensors[1].eval()) + + +-class AggregateMetricMapTest(tf.test.TestCase): ++class AggregateMetricMapTest(tf1.test.TestCase): + + def testAggregateMultipleMetricsReturnsListsInOrder(self): + predictions = array_ops.ones((10, 4)) +@@ -6901,7 +6902,7 @@ class AggregateMetricMapTest(tf.test.TestCase): + self.assertEqual(4, names_to_values['m2'].eval()) + + +-class CountTest(tf.test.TestCase): ++class CountTest(tf1.test.TestCase): + + def testVars(self): + metrics.count(array_ops.ones([4, 3])) +@@ -6924,7 +6925,7 @@ class CountTest(tf.test.TestCase): + self.assertIsInstance(c, ops.Tensor) + # Note: If resource variables are enabeld the result is a Variable + # (AssignAdd) +- self.assertIsInstance(op, (ops.Operation, ops.Tensor, tf.Variable)) ++ self.assertIsInstance(op, (ops.Operation, ops.Tensor, tf2.Variable)) + + def testBasic(self): + with self.cached_session() as sess: +@@ -7063,7 +7064,7 @@ class CountTest(tf.test.TestCase): + self.assertAlmostEqual(4.1, result.eval(), 5) + + +-class CohenKappaTest(tf.test.TestCase): ++class CohenKappaTest(tf1.test.TestCase): + + def _confusion_matrix_to_samples(self, confusion_matrix): + x, y = confusion_matrix.shape +@@ -7277,4 +7278,4 @@ class CohenKappaTest(tf.test.TestCase): + print(sess.run(values)) + + if __name__ == '__main__': +- tf.test.main() ++ tf1.test.main() +-- +2.40.1 + diff --git a/recipe/patches/0018-Update-references-from-variables.VariableV1-to-its-n.patch b/recipe/patches/0018-Update-references-from-variables.VariableV1-to-its-n.patch new file mode 100644 index 0000000..643c2ca --- /dev/null +++ b/recipe/patches/0018-Update-references-from-variables.VariableV1-to-its-n.patch @@ -0,0 +1,210 @@ +From f67a0b4412c9a15b08fe0ed6daa9c95656751a6d Mon Sep 17 00:00:00 2001 +From: Fiona Lang +Date: Wed, 29 Mar 2023 15:48:27 -0700 +Subject: [PATCH 18/30] Update references from `variables.VariableV1` to its + new location in `ops/variable_v1.py`. + +PiperOrigin-RevId: 520463538 +Change-Id: I37f2a73375328d1b2bdb6ad537d5a38cb0e01d3c +--- + pip_pkg.sh | 2 +- + tests_release.sh | 2 +- + tf_slim/metrics/metric_ops_test.py | 15 +++++----- + tf_slim/ops/variables_test.py | 47 +++++++++++++++--------------- + 4 files changed, 34 insertions(+), 32 deletions(-) + +diff --git a/pip_pkg.sh b/pip_pkg.sh +index 37fdbd4..9989b0e 100755 +--- a/pip_pkg.sh ++++ b/pip_pkg.sh +@@ -1,4 +1,4 @@ +-# Copyright 2022 The TF-Slim Authors. ++# Copyright 2023 The TF-Slim Authors. + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. +diff --git a/tests_release.sh b/tests_release.sh +index 695bcf9..6b0f533 100755 +--- a/tests_release.sh ++++ b/tests_release.sh +@@ -1,4 +1,4 @@ +-# Copyright 2022 The TF-Slim Authors. ++# Copyright 2023 The TF-Slim Authors. + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. +diff --git a/tf_slim/metrics/metric_ops_test.py b/tf_slim/metrics/metric_ops_test.py +index fad934d..a5fe9e8 100644 +--- a/tf_slim/metrics/metric_ops_test.py ++++ b/tf_slim/metrics/metric_ops_test.py +@@ -40,6 +40,7 @@ from tensorflow.python.ops import data_flow_ops + from tensorflow.python.ops import math_ops + from tensorflow.python.ops import random_ops + from tensorflow.python.ops import variable_scope ++from tensorflow.python.ops import variable_v1 + from tensorflow.python.ops import variables + + +@@ -2085,11 +2086,11 @@ class StreamingDynamicAUCTest(tf1.test.TestCase): + num_batches = 100 + labels = np.array([]) + predictions = np.array([]) +- tf_labels = variables.VariableV1( ++ tf_labels = variable_v1.VariableV1( + array_ops.ones(batch_size, dtypes_lib.int32), + collections=[ops.GraphKeys.LOCAL_VARIABLES], + dtype=dtypes_lib.int32) +- tf_predictions = variables.VariableV1( ++ tf_predictions = variable_v1.VariableV1( + array_ops.ones(batch_size), + collections=[ops.GraphKeys.LOCAL_VARIABLES], + dtype=dtypes_lib.float32) +@@ -2149,15 +2150,15 @@ class StreamingDynamicAUCTest(tf1.test.TestCase): + labels = np.array([]) + predictions = np.array([]) + weights = np.array([]) +- tf_labels = variables.VariableV1( ++ tf_labels = variable_v1.VariableV1( + array_ops.ones(batch_size, dtypes_lib.int32), + collections=[ops.GraphKeys.LOCAL_VARIABLES], + dtype=dtypes_lib.int32) +- tf_predictions = variables.VariableV1( ++ tf_predictions = variable_v1.VariableV1( + array_ops.ones(batch_size), + collections=[ops.GraphKeys.LOCAL_VARIABLES], + dtype=dtypes_lib.float32) +- tf_weights = variables.VariableV1( ++ tf_weights = variable_v1.VariableV1( + array_ops.ones(batch_size), + collections=[ops.GraphKeys.LOCAL_VARIABLES], + dtype=dtypes_lib.float32) +@@ -2328,11 +2329,11 @@ class AucWithConfidenceIntervalsTest(tf1.test.TestCase): + num_batches = 100 + labels = np.array([]) + predictions = np.array([]) +- tf_labels = variables.VariableV1( ++ tf_labels = variable_v1.VariableV1( + array_ops.ones(batch_size, dtypes_lib.int32), + collections=[ops.GraphKeys.LOCAL_VARIABLES], + dtype=dtypes_lib.int32) +- tf_predictions = variables.VariableV1( ++ tf_predictions = variable_v1.VariableV1( + array_ops.ones(batch_size), + collections=[ops.GraphKeys.LOCAL_VARIABLES], + dtype=dtypes_lib.float32) +diff --git a/tf_slim/ops/variables_test.py b/tf_slim/ops/variables_test.py +index 9f127eb..589f951 100644 +--- a/tf_slim/ops/variables_test.py ++++ b/tf_slim/ops/variables_test.py +@@ -41,6 +41,7 @@ from tensorflow.python.ops import nn_ops + from tensorflow.python.ops import partitioned_variables + from tensorflow.python.ops import resource_variable_ops + from tensorflow.python.ops import variable_scope ++from tensorflow.python.ops import variable_v1 + from tensorflow.python.ops import variables as variables_lib + from tensorflow.python.platform import gfile + from tensorflow.python.platform import test +@@ -212,7 +213,7 @@ class GlobalStepTest(test.TestCase): + def test_invalid_dtype(self): + with ops.Graph().as_default() as g: + self.assertEqual(None, variables_lib2.get_global_step()) +- variables_lib.VariableV1( ++ variable_v1.VariableV1( + 0.0, + trainable=False, + dtype=dtypes.float32, +@@ -225,14 +226,14 @@ class GlobalStepTest(test.TestCase): + def test_invalid_shape(self): + with ops.Graph().as_default() as g: + self.assertEqual(None, variables_lib2.get_global_step()) +- variables_lib.VariableV1( +- [0], +- trainable=False, +- dtype=dtypes.int32, +- name=ops.GraphKeys.GLOBAL_STEP, +- collections=[ops.GraphKeys.GLOBAL_VARIABLES, +- ops.GraphKeys.GLOBAL_STEP] +- ) ++ variable_v1.VariableV1([0], ++ trainable=False, ++ dtype=dtypes.int32, ++ name=ops.GraphKeys.GLOBAL_STEP, ++ collections=[ ++ ops.GraphKeys.GLOBAL_VARIABLES, ++ ops.GraphKeys.GLOBAL_STEP ++ ]) + self.assertRaisesRegexp(TypeError, 'not scalar', + variables_lib2.get_global_step) + self.assertRaisesRegexp(TypeError, 'not scalar', +@@ -252,14 +253,14 @@ class GlobalStepTest(test.TestCase): + def test_get_global_step(self): + with ops.Graph().as_default() as g: + self.assertEqual(None, variables_lib2.get_global_step()) +- variables_lib.VariableV1( ++ variable_v1.VariableV1( + 0, + trainable=False, + dtype=dtypes.int32, + name=ops.GraphKeys.GLOBAL_STEP, +- collections=[ops.GraphKeys.GLOBAL_VARIABLES, +- ops.GraphKeys.GLOBAL_STEP] +- ) ++ collections=[ ++ ops.GraphKeys.GLOBAL_VARIABLES, ops.GraphKeys.GLOBAL_STEP ++ ]) + self._assert_global_step( + variables_lib2.get_global_step(), expected_dtype=dtypes.int32) + self._assert_global_step( +@@ -635,10 +636,10 @@ class ModelVariablesTest(test.TestCase): + with self.cached_session(): + with variable_scope.variable_scope('A'): + variables_lib2.local_variable([5]) +- a = variables_lib.VariableV1([5]) ++ a = variable_v1.VariableV1([5]) + with variable_scope.variable_scope('B'): + variables_lib2.local_variable([5]) +- b = variables_lib.VariableV1([5]) ++ b = variable_v1.VariableV1([5]) + self.assertEqual([a], variables_lib2.get_trainable_variables('A')) + self.assertEqual([b], variables_lib2.get_trainable_variables('B')) + +@@ -982,7 +983,7 @@ class AssignFromCheckpointTest(test.TestCase): + # Create a set of variables to save in the checkpoint. + for var_name in var_names_to_values: + var_value = var_names_to_values[var_name] +- var_list.append(variables_lib.VariableV1(var_value, name=var_name)) ++ var_list.append(variable_v1.VariableV1(var_value, name=var_name)) + saver = saver_lib.Saver(var_list) + init_op = variables_lib.variables_initializer(var_list) + sess.run(init_op) +@@ -1129,7 +1130,7 @@ class AssignFromCheckpointFnTest(test.TestCase): + # Create a set of variables to save in the checkpoint. + for var_name in var_names_to_values: + var_value = var_names_to_values[var_name] +- var_list.append(variables_lib.VariableV1(var_value, name=var_name)) ++ var_list.append(variable_v1.VariableV1(var_value, name=var_name)) + saver = saver_lib.Saver(var_list) + init_op = variables_lib.variables_initializer(var_list) + sess.run(init_op) +@@ -1318,12 +1319,12 @@ class FilterVariablesTest(test.TestCase): + g = ops.Graph() + with g.as_default(): + var_list = [] +- var_list.append(variables_lib.VariableV1(0, name='conv1/weights')) +- var_list.append(variables_lib.VariableV1(0, name='conv1/biases')) +- var_list.append(variables_lib.VariableV1(0, name='conv2/weights')) +- var_list.append(variables_lib.VariableV1(0, name='conv2/biases')) +- var_list.append(variables_lib.VariableV1(0, name='clfs/weights')) +- var_list.append(variables_lib.VariableV1(0, name='clfs/biases')) ++ var_list.append(variable_v1.VariableV1(0, name='conv1/weights')) ++ var_list.append(variable_v1.VariableV1(0, name='conv1/biases')) ++ var_list.append(variable_v1.VariableV1(0, name='conv2/weights')) ++ var_list.append(variable_v1.VariableV1(0, name='conv2/biases')) ++ var_list.append(variable_v1.VariableV1(0, name='clfs/weights')) ++ var_list.append(variable_v1.VariableV1(0, name='clfs/biases')) + self._var_list = var_list + + def _test_filter_variables(self, +-- +2.40.1 + diff --git a/recipe/patches/0019-Update-references-from-tensorflow.python.platform-to.patch b/recipe/patches/0019-Update-references-from-tensorflow.python.platform-to.patch new file mode 100644 index 0000000..cd3dffc --- /dev/null +++ b/recipe/patches/0019-Update-references-from-tensorflow.python.platform-to.patch @@ -0,0 +1,480 @@ +From 5db3950e6ebca309dd4f4ca18cff70999043523a Mon Sep 17 00:00:00 2001 +From: Brian Wieder +Date: Tue, 18 Apr 2023 07:58:34 -0700 +Subject: [PATCH 19/30] Update references from tensorflow.python.platform to + use the public API if available. + +PiperOrigin-RevId: 525147014 +Change-Id: Id77e0989ade18ae9a6d4cfe939a133b252a9598c +--- + tf_slim/data/dataset_data_provider_test.py | 5 ++- + tf_slim/layers/regularizers.py | 6 ++-- + tf_slim/learning.py | 37 ++++++++++++++-------- + tf_slim/ops/variables.py | 9 +++--- + tf_slim/ops/variables_test.py | 25 +++++++-------- + tf_slim/training/evaluation.py | 19 ++++++----- + tf_slim/training/evaluation_test.py | 21 ++++++------ + tf_slim/training/training_test.py | 13 ++++---- + 8 files changed, 72 insertions(+), 63 deletions(-) + +diff --git a/tf_slim/data/dataset_data_provider_test.py b/tf_slim/data/dataset_data_provider_test.py +index 61e9755..b967173 100644 +--- a/tf_slim/data/dataset_data_provider_test.py ++++ b/tf_slim/data/dataset_data_provider_test.py +@@ -38,7 +38,6 @@ from tensorflow.python.ops import array_ops + from tensorflow.python.ops import image_ops + from tensorflow.python.ops import io_ops + from tensorflow.python.ops import parsing_ops +-from tensorflow.python.platform import gfile + from tensorflow.python.platform import test + # pylint:enable=g-direct-tensorflow-import + +@@ -54,8 +53,8 @@ def _resize_image(image, height, width): + + + def _create_tfrecord_dataset(tmpdir): +- if not gfile.Exists(tmpdir): +- gfile.MakeDirs(tmpdir) ++ if not tf.gfile.Exists(tmpdir): ++ tf.gfile.MakeDirs(tmpdir) + + data_sources = test_utils.create_tfrecord_files(tmpdir, num_files=1) + +diff --git a/tf_slim/layers/regularizers.py b/tf_slim/layers/regularizers.py +index 9721c7f..d84a424 100644 +--- a/tf_slim/layers/regularizers.py ++++ b/tf_slim/layers/regularizers.py +@@ -20,13 +20,13 @@ from __future__ import division + from __future__ import print_function + + import numbers ++import tensorflow as tf + # pylint: disable=g-direct-tensorflow-import + from tensorflow.python.framework import constant_op + from tensorflow.python.framework import ops + from tensorflow.python.ops import math_ops + from tensorflow.python.ops import nn + from tensorflow.python.ops import standard_ops +-from tensorflow.python.platform import tf_logging as logging + + __all__ = ['l1_regularizer', + 'l2_regularizer', +@@ -57,7 +57,7 @@ def l1_regularizer(scale, scope=None): + raise ValueError('Setting a scale less than 0 on a regularizer: %g' % + scale) + if scale == 0.: +- logging.info('Scale of 0 disables regularizer.') ++ tf.compat.v1.logging.info('Scale of 0 disables regularizer.') + return lambda _: None + + def l1(weights, name=None): +@@ -96,7 +96,7 @@ def l2_regularizer(scale, scope=None): + raise ValueError('Setting a scale less than 0 on a regularizer: %g.' % + scale) + if scale == 0.: +- logging.info('Scale of 0 disables regularizer.') ++ tf.compat.v1.logging.info('Scale of 0 disables regularizer.') + return lambda _: None + + def l2(weights): +diff --git a/tf_slim/learning.py b/tf_slim/learning.py +index 6803517..5e95058 100644 +--- a/tf_slim/learning.py ++++ b/tf_slim/learning.py +@@ -255,6 +255,8 @@ import os + import sys + import time + ++import tensorflow as tf ++ + from tf_slim.training import training + # pylint:disable=g-direct-tensorflow-import + from tensorflow.core.protobuf import config_pb2 +@@ -270,7 +272,6 @@ from tensorflow.python.ops import control_flow_ops + from tensorflow.python.ops import lookup_ops + from tensorflow.python.ops import math_ops + from tensorflow.python.ops import variables +-from tensorflow.python.platform import tf_logging as logging + from tensorflow.python.summary import summary + from tensorflow.python.training import optimizer as tf_optimizer + from tensorflow.python.training import saver as tf_saver +@@ -371,7 +372,7 @@ def add_gradients_summaries(grads_and_vars): + summary.scalar(var.op.name + '/gradient_norm', + clip_ops.global_norm([grad_values]))) + else: +- logging.info('Var %s has no gradient', var.op.name) ++ tf.compat.v1.logging.info('Var %s has no gradient', var.op.name) + + return summaries + +@@ -501,7 +502,7 @@ def train_step(sess, train_op, global_step, train_step_kwargs): + trace = tl.generate_chrome_trace_format() + trace_filename = os.path.join(train_step_kwargs['logdir'], + 'tf_trace-%d.json' % np_global_step) +- logging.info('Writing trace to %s', trace_filename) ++ tf.compat.v1.logging.info('Writing trace to %s', trace_filename) + file_io.write_string_to_file(trace_filename, trace) + if 'summary_writer' in train_step_kwargs: + train_step_kwargs['summary_writer'].add_run_metadata( +@@ -509,8 +510,12 @@ def train_step(sess, train_op, global_step, train_step_kwargs): + + if 'should_log' in train_step_kwargs: + if sess.run(train_step_kwargs['should_log']): +- logging.info('global step %d: loss = %.4f (%.3f sec/step)', +- np_global_step, total_loss, time_elapsed) ++ tf.compat.v1.logging.info( ++ 'global step %d: loss = %.4f (%.3f sec/step)', ++ np_global_step, ++ total_loss, ++ time_elapsed, ++ ) + + if 'should_stop' in train_step_kwargs: + should_stop = sess.run(train_step_kwargs['should_stop']) +@@ -744,10 +749,11 @@ def train(train_op, + should_retry = False + with sv.managed_session( + master, start_standard_services=False, config=session_config) as sess: +- logging.info('Starting Session.') ++ tf.compat.v1.logging.info('Starting Session.') + if session_wrapper is not None: +- logging.info('Wrapping session with wrapper function: %s', +- session_wrapper) ++ tf.compat.v1.logging.info( ++ 'Wrapping session with wrapper function: %s', session_wrapper ++ ) + sess = session_wrapper(sess) + if is_chief: + if logdir: +@@ -758,7 +764,7 @@ def train(train_op, + sess, global_step, + min(startup_delay_steps, number_of_steps or sys.maxsize)) + threads = sv.start_queue_runners(sess) +- logging.info('Starting Queues.') ++ tf.compat.v1.logging.info('Starting Queues.') + if is_chief and sync_optimizer is not None: + sv.start_queue_runners(sess, chief_queue_runner) + sess.run(init_tokens_op) +@@ -767,25 +773,28 @@ def train(train_op, + total_loss, should_stop = train_step_fn(sess, train_op, global_step, + train_step_kwargs) + if should_stop: +- logging.info('Stopping Training.') ++ tf.compat.v1.logging.info('Stopping Training.') + sv.request_stop() + break + except errors.OutOfRangeError as e: + # OutOfRangeError is thrown when epoch limit per + # tf.compat.v1.train.limit_epochs is reached. +- logging.info('Caught OutOfRangeError. Stopping Training. %s', e) ++ tf.compat.v1.logging.info( ++ 'Caught OutOfRangeError. Stopping Training. %s', e ++ ) + if logdir and sv.is_chief: +- logging.info('Finished training! Saving model to disk.') ++ tf.compat.v1.logging.info('Finished training! Saving model to disk.') + sv.saver.save(sess, sv.save_path, global_step=sv.global_step) + sv.stop( + threads, + close_summary_writer=True, +- ignore_live_threads=ignore_live_threads) ++ ignore_live_threads=ignore_live_threads, ++ ) + + except errors.AbortedError: + # Always re-run on AbortedError as it indicates a restart of one of the + # distributed tensorflow servers. +- logging.info('Retrying training!') ++ tf.compat.v1.logging.info('Retrying training!') + should_retry = True + + return total_loss +diff --git a/tf_slim/ops/variables.py b/tf_slim/ops/variables.py +index 0f988a9..e15ca6e 100644 +--- a/tf_slim/ops/variables.py ++++ b/tf_slim/ops/variables.py +@@ -31,7 +31,6 @@ from tensorflow.python.ops import array_ops + from tensorflow.python.ops import control_flow_ops + from tensorflow.python.ops import variable_scope + from tensorflow.python.ops import variables +-from tensorflow.python.platform import tf_logging as logging + from tensorflow.python.training import saver as tf_saver + from tensorflow.python.training import training_util + from tensorflow.python.util.deprecation import deprecated +@@ -640,7 +639,7 @@ def assign_from_checkpoint(model_path, var_list, ignore_missing_vars=False): + if not reader.has_tensor(ckpt_name): + log_str = 'Checkpoint is missing variable [%s]' % ckpt_name + if ignore_missing_vars: +- logging.warning(log_str) ++ tf.logging.warning(log_str) + continue + else: + raise ValueError(log_str) +@@ -720,7 +719,9 @@ def assign_from_checkpoint_fn(model_path, + if reader.has_tensor(var): + available_vars[var] = var_dict[var] + else: +- logging.warning('Variable %s missing in checkpoint %s', var, model_path) ++ tf.logging.warning( ++ 'Variable %s missing in checkpoint %s', var, model_path ++ ) + var_list = available_vars + if var_list: + saver = tf_saver.Saver( +@@ -733,7 +734,7 @@ def assign_from_checkpoint_fn(model_path, + + return callback + else: +- logging.warning('No Variables to restore') ++ tf.logging.warning('No Variables to restore') + return None + + +diff --git a/tf_slim/ops/variables_test.py b/tf_slim/ops/variables_test.py +index 589f951..a87f5d9 100644 +--- a/tf_slim/ops/variables_test.py ++++ b/tf_slim/ops/variables_test.py +@@ -43,7 +43,6 @@ from tensorflow.python.ops import resource_variable_ops + from tensorflow.python.ops import variable_scope + from tensorflow.python.ops import variable_v1 + from tensorflow.python.ops import variables as variables_lib +-from tensorflow.python.platform import gfile + from tensorflow.python.platform import test + from tensorflow.python.training import device_setter + from tensorflow.python.training import saver as saver_lib +@@ -1139,8 +1138,8 @@ class AssignFromCheckpointFnTest(test.TestCase): + + def testLoadExistingVariables(self): + model_dir = tempfile.mkdtemp('load_existing_variables') +- if gfile.Exists(model_dir): +- gfile.DeleteRecursively(model_dir) ++ if tf.gfile.Exists(model_dir): ++ tf.gfile.DeleteRecursively(model_dir) + + init_value0 = 10.0 + init_value1 = 20.0 +@@ -1169,8 +1168,8 @@ class AssignFromCheckpointFnTest(test.TestCase): + @unittest.skip('sess.run functionality difference in v2.0') + def testLoadExistingVariablesDifferentShapeDefaultDoesNotAllowReshape(self): + model_dir = tempfile.mkdtemp('load_existing_vars_no_reshape') +- if gfile.Exists(model_dir): +- gfile.DeleteRecursively(model_dir) ++ if tf.gfile.Exists(model_dir): ++ tf.gfile.DeleteRecursively(model_dir) + + init_value0 = [[10.0, 11.0]] + init_value1 = 20.0 +@@ -1196,8 +1195,8 @@ class AssignFromCheckpointFnTest(test.TestCase): + def testLoadExistingVariablesDifferentShapeAllowReshape(self): + model_dir = tempfile.mkdtemp( + 'load_existing_variables_different_shape_allow_reshape') +- if gfile.Exists(model_dir): +- gfile.DeleteRecursively(model_dir) ++ if tf.gfile.Exists(model_dir): ++ tf.gfile.DeleteRecursively(model_dir) + + init_value0 = [[10.0, 11.0]] + init_value1 = 20.0 +@@ -1225,8 +1224,8 @@ class AssignFromCheckpointFnTest(test.TestCase): + + def testNotFoundError(self): + model_dir = tempfile.mkdtemp('not_found_error') +- if gfile.Exists(model_dir): +- gfile.DeleteRecursively(model_dir) ++ if tf.gfile.Exists(model_dir): ++ tf.gfile.DeleteRecursively(model_dir) + + init_value0 = 10.0 + init_value1 = 20.0 +@@ -1252,8 +1251,8 @@ class AssignFromCheckpointFnTest(test.TestCase): + + def testMissingVariablesList(self): + model_dir = tempfile.mkdtemp('missing_variables_list') +- if gfile.Exists(model_dir): +- gfile.DeleteRecursively(model_dir) ++ if tf.gfile.Exists(model_dir): ++ tf.gfile.DeleteRecursively(model_dir) + + init_value0 = 10.0 + init_value1 = 20.0 +@@ -1282,8 +1281,8 @@ class AssignFromCheckpointFnTest(test.TestCase): + + def testMissingVariablesDict(self): + model_dir = tempfile.mkdtemp('missing_variables_dict') +- if gfile.Exists(model_dir): +- gfile.DeleteRecursively(model_dir) ++ if tf.gfile.Exists(model_dir): ++ tf.gfile.DeleteRecursively(model_dir) + + init_value0 = 10.0 + init_value1 = 20.0 +diff --git a/tf_slim/training/evaluation.py b/tf_slim/training/evaluation.py +index 3755467..e92cf2a 100644 +--- a/tf_slim/training/evaluation.py ++++ b/tf_slim/training/evaluation.py +@@ -141,7 +141,6 @@ import time + import tensorflow.compat.v1 as tf + # pylint: disable=g-direct-tensorflow-import + from tensorflow.python.checkpoint import checkpoint_management +-from tensorflow.python.platform import tf_logging as logging + from tensorflow.python.summary import summary + from tensorflow.python.training import basic_session_run_hooks + from tensorflow.python.training import evaluation +@@ -187,7 +186,7 @@ def wait_for_new_checkpoint(checkpoint_dir, + Returns: + a new checkpoint path, or None if the timeout was reached. + """ +- logging.info('Waiting for new checkpoint at %s', checkpoint_dir) ++ tf.logging.info('Waiting for new checkpoint at %s', checkpoint_dir) + stop_time = time.time() + timeout if timeout is not None else None + while True: + checkpoint_path = checkpoint_management.latest_checkpoint(checkpoint_dir) +@@ -196,7 +195,7 @@ def wait_for_new_checkpoint(checkpoint_dir, + return None + time.sleep(seconds_to_sleep) + else: +- logging.info('Found new checkpoint at %s', checkpoint_path) ++ tf.logging.info('Found new checkpoint at %s', checkpoint_path) + return checkpoint_path + + +@@ -249,7 +248,7 @@ def checkpoints_iterator(checkpoint_dir, + if new_checkpoint_path is None: + if not timeout_fn: + # timed out +- logging.info('Timed-out waiting for a checkpoint.') ++ tf.logging.info('Timed-out waiting for a checkpoint.') + return + if timeout_fn(): + # The timeout_fn indicated that we are truly done. +@@ -447,14 +446,18 @@ def evaluate_repeatedly(checkpoint_dir, + + with monitored_session.MonitoredSession( + session_creator=session_creator, hooks=hooks) as session: +- logging.info('Starting evaluation at ' + +- time.strftime('%Y-%m-%d-%H:%M:%S', time.gmtime())) ++ tf.logging.info( ++ 'Starting evaluation at ' ++ + time.strftime('%Y-%m-%d-%H:%M:%S', time.gmtime()) ++ ) + if eval_ops is not None: + while not session.should_stop(): + session.run(eval_ops, feed_dict) + +- logging.info('Finished evaluation at ' + +- time.strftime('%Y-%m-%d-%H:%M:%S', time.gmtime())) ++ tf.logging.info( ++ 'Finished evaluation at ' ++ + time.strftime('%Y-%m-%d-%H:%M:%S', time.gmtime()) ++ ) + num_evaluations += 1 + + if (max_number_of_evaluations is not None and +diff --git a/tf_slim/training/evaluation_test.py b/tf_slim/training/evaluation_test.py +index 596592a..30e2a60 100644 +--- a/tf_slim/training/evaluation_test.py ++++ b/tf_slim/training/evaluation_test.py +@@ -45,7 +45,6 @@ from tensorflow.python.ops import metrics + from tensorflow.python.ops import state_ops + from tensorflow.python.ops import variables as variables_lib + +-from tensorflow.python.platform import gfile + from tensorflow.python.platform import test + from tensorflow.python.summary import summary as summary_lib + from tensorflow.python.summary import summary_iterator +@@ -70,8 +69,8 @@ class CheckpointIteratorTest(test.TestCase): + + def testReturnsSingleCheckpointIfOneCheckpointFound(self): + checkpoint_dir = tempfile.mkdtemp('one_checkpoint_found') +- if not gfile.Exists(checkpoint_dir): +- gfile.MakeDirs(checkpoint_dir) ++ if not tf.gfile.Exists(checkpoint_dir): ++ tf.gfile.MakeDirs(checkpoint_dir) + + global_step = variables.get_or_create_global_step() + saver = saver_lib.Saver() # Saves the global step. +@@ -88,8 +87,8 @@ class CheckpointIteratorTest(test.TestCase): + + def testReturnsSingleCheckpointIfOneShardedCheckpoint(self): + checkpoint_dir = tempfile.mkdtemp('one_checkpoint_found_sharded') +- if not gfile.Exists(checkpoint_dir): +- gfile.MakeDirs(checkpoint_dir) ++ if not tf.gfile.Exists(checkpoint_dir): ++ tf.gfile.MakeDirs(checkpoint_dir) + + global_step = variables.get_or_create_global_step() + +@@ -333,8 +332,8 @@ class EvaluateRepeatedlyTest(test.TestCase): + + def testEvaluationLoopTimeout(self): + checkpoint_dir = tempfile.mkdtemp('evaluation_loop_timeout') +- if not gfile.Exists(checkpoint_dir): +- gfile.MakeDirs(checkpoint_dir) ++ if not tf.gfile.Exists(checkpoint_dir): ++ tf.gfile.MakeDirs(checkpoint_dir) + + # We need a variable that the saver will try to restore. + variables.get_or_create_global_step() +@@ -464,8 +463,8 @@ class EvaluateRepeatedlyTest(test.TestCase): + def testSummariesAreFlushedToDisk(self): + checkpoint_dir = tempfile.mkdtemp('summaries_are_flushed') + logdir = tempfile.mkdtemp('summaries_are_flushed_eval') +- if gfile.Exists(logdir): +- gfile.DeleteRecursively(logdir) ++ if tf.gfile.Exists(logdir): ++ tf.gfile.DeleteRecursively(logdir) + + # Train a Model to completion: + self._train_model(checkpoint_dir, num_steps=300) +@@ -491,8 +490,8 @@ class EvaluateRepeatedlyTest(test.TestCase): + + def testSummaryAtEndHookWithoutSummaries(self): + logdir = tempfile.mkdtemp('summary_at_end_hook_without_summaires') +- if gfile.Exists(logdir): +- gfile.DeleteRecursively(logdir) ++ if tf.gfile.Exists(logdir): ++ tf.gfile.DeleteRecursively(logdir) + + with ops.Graph().as_default(): + # Purposefully don't add any summaries. The hook will just dump the +diff --git a/tf_slim/training/training_test.py b/tf_slim/training/training_test.py +index 555f68a..6a09025 100644 +--- a/tf_slim/training/training_test.py ++++ b/tf_slim/training/training_test.py +@@ -38,7 +38,6 @@ from tensorflow.python.ops import gradients_impl + from tensorflow.python.ops import math_ops + from tensorflow.python.ops import variables as variables_lib2 + +-from tensorflow.python.platform import gfile + from tensorflow.python.platform import test + from tensorflow.python.training import basic_session_run_hooks + from tensorflow.python.training import gradient_descent +@@ -386,10 +385,10 @@ class TrainTest(test.TestCase): + logdir1 = tempfile.mkdtemp('tmp_logs1/') + logdir2 = tempfile.mkdtemp('tmp_logs2/') + +- if gfile.Exists(logdir1): # For running on jenkins. +- gfile.DeleteRecursively(logdir1) +- if gfile.Exists(logdir2): # For running on jenkins. +- gfile.DeleteRecursively(logdir2) ++ if tf.gfile.Exists(logdir1): # For running on jenkins. ++ tf.gfile.DeleteRecursively(logdir1) ++ if tf.gfile.Exists(logdir2): # For running on jenkins. ++ tf.gfile.DeleteRecursively(logdir2) + + # First, train the model one step (make sure the error is high). + with ops.Graph().as_default(): +@@ -462,8 +461,8 @@ class TrainTest(test.TestCase): + + def testTrainAllVarsHasLowerLossThanTrainSubsetOfVars(self): + logdir = tempfile.mkdtemp('tmp_logs3/') +- if gfile.Exists(logdir): # For running on jenkins. +- gfile.DeleteRecursively(logdir) ++ if tf.gfile.Exists(logdir): # For running on jenkins. ++ tf.gfile.DeleteRecursively(logdir) + + # First, train only the weights of the model. + with ops.Graph().as_default(): +-- +2.40.1 + diff --git a/recipe/patches/0020-Update-legacy-reference-to-variable_scope.variable-i.patch b/recipe/patches/0020-Update-legacy-reference-to-variable_scope.variable-i.patch new file mode 100644 index 0000000..ada3804 --- /dev/null +++ b/recipe/patches/0020-Update-legacy-reference-to-variable_scope.variable-i.patch @@ -0,0 +1,37 @@ +From 7c760601d967c848bec3a821787d2fb2fc591e83 Mon Sep 17 00:00:00 2001 +From: Fiona Lang +Date: Wed, 26 Apr 2023 12:41:44 -0700 +Subject: [PATCH 20/30] Update legacy reference to variable_scope.variable in + preparation for its deletion. + +PiperOrigin-RevId: 527345410 +Change-Id: I1a1fe50bd5cc8ba6ca47e7a0aa30d12996ba12ec +--- + tf_slim/ops/variables.py | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/tf_slim/ops/variables.py b/tf_slim/ops/variables.py +index e15ca6e..cbb58b5 100644 +--- a/tf_slim/ops/variables.py ++++ b/tf_slim/ops/variables.py +@@ -145,7 +145,7 @@ def local_variable(initial_value, + Returns: + New variable. + """ +- return variable_scope.variable( ++ return tf.Variable( + initial_value, + trainable=False, + collections=[ops.GraphKeys.LOCAL_VARIABLES], +@@ -169,7 +169,7 @@ def global_variable(initial_value, + Returns: + New variable. + """ +- return variable_scope.variable( ++ return tf.Variable( + initial_value, + trainable=False, + collections=[ops.GraphKeys.GLOBAL_VARIABLES], +-- +2.40.1 + diff --git a/recipe/patches/0021-Internal-Code-Change.patch b/recipe/patches/0021-Internal-Code-Change.patch new file mode 100644 index 0000000..b2f691a --- /dev/null +++ b/recipe/patches/0021-Internal-Code-Change.patch @@ -0,0 +1,140 @@ +From 8b44cf62d11d718b7568e26a00475b407b3c733d Mon Sep 17 00:00:00 2001 +From: Brian Wieder +Date: Fri, 28 Apr 2023 13:52:53 -0700 +Subject: [PATCH 21/30] Internal Code Change + +PiperOrigin-RevId: 527978155 +Change-Id: I324377be8f71a6e5d500440eb6704ca39dbfa800 +--- + tf_slim/data/parallel_reader.py | 5 +++-- + tf_slim/evaluation_test.py | 5 ++--- + tf_slim/summaries_test.py | 5 ++--- + tf_slim/training/training.py | 11 +++++++---- + 4 files changed, 14 insertions(+), 12 deletions(-) + +diff --git a/tf_slim/data/parallel_reader.py b/tf_slim/data/parallel_reader.py +index 98ee36b..d197d12 100644 +--- a/tf_slim/data/parallel_reader.py ++++ b/tf_slim/data/parallel_reader.py +@@ -19,13 +19,14 @@ from __future__ import absolute_import + from __future__ import division + from __future__ import print_function + ++import tensorflow as tf ++ + # pylint:disable=g-direct-tensorflow-import + from tensorflow.python.framework import dtypes as tf_dtypes + from tensorflow.python.framework import ops + from tensorflow.python.ops import data_flow_ops + from tensorflow.python.ops import io_ops + from tensorflow.python.ops import math_ops +-from tensorflow.python.platform import gfile + from tensorflow.python.summary import summary + from tensorflow.python.training import input as tf_input + from tensorflow.python.training import queue_runner +@@ -312,7 +313,7 @@ def get_data_files(data_sources): + data_files += get_data_files(source) + else: + if '*' in data_sources or '?' in data_sources or '[' in data_sources: +- data_files = gfile.Glob(data_sources) ++ data_files = tf.compat.v1.gfile.Glob(data_sources) + else: + data_files = [data_sources] + if not data_files: +diff --git a/tf_slim/evaluation_test.py b/tf_slim/evaluation_test.py +index 7b24b87..6ae1276 100644 +--- a/tf_slim/evaluation_test.py ++++ b/tf_slim/evaluation_test.py +@@ -43,7 +43,6 @@ from tensorflow.python.ops import math_ops + from tensorflow.python.ops import metrics + from tensorflow.python.ops import variables + from tensorflow.python.platform import flags +-from tensorflow.python.platform import gfile + from tensorflow.python.platform import test + from tensorflow.python.summary import summary_iterator + from tensorflow.python.training import input # pylint: disable=redefined-builtin +@@ -214,9 +213,9 @@ class EvaluationTest(test.TestCase): + variables.local_variables_initializer()) + # Create checkpoint and log directories: + chkpt_dir = tempfile.mkdtemp('tmp_logs') +- gfile.MakeDirs(chkpt_dir) ++ tf.gfile.MakeDirs(chkpt_dir) + logdir = tempfile.mkdtemp('tmp_logs2') +- gfile.MakeDirs(logdir) ++ tf.gfile.MakeDirs(logdir) + + # Save initialized variables to a checkpoint directory: + saver = saver_lib.Saver() +diff --git a/tf_slim/summaries_test.py b/tf_slim/summaries_test.py +index f7cdb72..5dd91b5 100644 +--- a/tf_slim/summaries_test.py ++++ b/tf_slim/summaries_test.py +@@ -28,7 +28,6 @@ from tf_slim import summaries + # pylint:disable=g-direct-tensorflow-import + from tensorflow.python.framework import ops + from tensorflow.python.ops import array_ops +-from tensorflow.python.platform import test + from tensorflow.python.summary import summary + from tensorflow.python.summary import summary_iterator + # pylint:enable=g-direct-tensorflow-import +@@ -38,7 +37,7 @@ def setUpModule(): + tf.disable_eager_execution() + + +-class SummariesTest(test.TestCase): ++class SummariesTest(tf.test.TestCase): + + def assert_scalar_summary(self, output_dir, names_to_values): + """Asserts that the given output directory contains written summaries. +@@ -104,4 +103,4 @@ class SummariesTest(test.TestCase): + + + if __name__ == '__main__': +- test.main() ++ tf.test.main() +diff --git a/tf_slim/training/training.py b/tf_slim/training/training.py +index 1ece335..b4884a7 100644 +--- a/tf_slim/training/training.py ++++ b/tf_slim/training/training.py +@@ -246,6 +246,8 @@ from __future__ import absolute_import + from __future__ import division + from __future__ import print_function + ++import tensorflow as tf ++ + # pylint: disable=g-direct-tensorflow-import + + from tensorflow.python.framework import indexed_slices +@@ -254,7 +256,6 @@ from tensorflow.python.ops import array_ops + from tensorflow.python.ops import clip_ops + from tensorflow.python.ops import control_flow_ops + from tensorflow.python.ops import variables as tf_variables +-from tensorflow.python.platform import tf_logging as logging + from tensorflow.python.summary import summary + from tensorflow.python.training import monitored_session + from tensorflow.python.training import optimizer as tf_optimizer +@@ -293,7 +294,7 @@ def add_gradients_summaries(grads_and_vars): + summary.scalar(var.op.name + '_gradient_norm', + clip_ops.global_norm([grad_values]))) + else: +- logging.info('Var %s has no gradient', var.op.name) ++ tf.compat.v1.logging.info('Var %s has no gradient', var.op.name) + + return summaries + +@@ -423,8 +424,10 @@ def create_train_op(total_loss, + else: + update_ops = set(update_ops) + if not global_update_ops.issubset(update_ops): +- logging.warning('update_ops in create_train_op does not contain all the ' +- 'update_ops in GraphKeys.UPDATE_OPS') ++ tf.compat.v1.logging.warning( ++ 'update_ops in create_train_op does not contain all the ' ++ 'update_ops in GraphKeys.UPDATE_OPS' ++ ) + + # Make sure update_ops are computed before total_loss. + if update_ops: +-- +2.40.1 + diff --git a/recipe/patches/0022-Delete-remnants-of-toollog-removal.patch b/recipe/patches/0022-Delete-remnants-of-toollog-removal.patch new file mode 100644 index 0000000..79cf452 --- /dev/null +++ b/recipe/patches/0022-Delete-remnants-of-toollog-removal.patch @@ -0,0 +1,27 @@ +From a8caa41e0d8ab04150d234516aa1bd1ac04bd4b3 Mon Sep 17 00:00:00 2001 +From: Juan Martinez Castellanos +Date: Fri, 12 May 2023 11:36:07 -0700 +Subject: [PATCH 22/30] Delete remnants of `toollog` removal. + +PiperOrigin-RevId: 531561668 +Change-Id: I35d4538dc81b5ce322e7c03559aff59e312e64b4 +--- + tf_slim/evaluation_test.py | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/tf_slim/evaluation_test.py b/tf_slim/evaluation_test.py +index 6ae1276..a38fac8 100644 +--- a/tf_slim/evaluation_test.py ++++ b/tf_slim/evaluation_test.py +@@ -288,7 +288,7 @@ class SingleEvaluationTest(test.TestCase): + labels=self._labels, predictions=self._predictions) + + dumping_root = tempfile.mkdtemp('tfdbg_dump_dir') +- dumping_hook = hooks.DumpingDebugHook(dumping_root, log_usage=False) ++ dumping_hook = hooks.DumpingDebugHook(dumping_root) + try: + # Run the evaluation and verify the results: + accuracy_value = evaluation.evaluate_once( +-- +2.40.1 + diff --git a/recipe/patches/0023-NumPy-Fix-uses-of-functions-deprecated-in-NumPy-1.25.patch b/recipe/patches/0023-NumPy-Fix-uses-of-functions-deprecated-in-NumPy-1.25.patch new file mode 100644 index 0000000..6c70e53 --- /dev/null +++ b/recipe/patches/0023-NumPy-Fix-uses-of-functions-deprecated-in-NumPy-1.25.patch @@ -0,0 +1,61 @@ +From 7da63e771944af333958ce0760b01f9e8e0b7cee Mon Sep 17 00:00:00 2001 +From: Peter Hawkins +Date: Thu, 8 Jun 2023 10:27:39 -0700 +Subject: [PATCH 23/30] [NumPy] Fix uses of functions deprecated in NumPy 1.25. + +NumPy 1.25 deprecates a number of function aliases (https://github.com/numpy/numpy/releases/tag/v1.25.0rc1) + +This change replaces uses of the deprecated names with their recommended replacements: +* `np.round_` -> `np.round` +* `np.product` -> `np.prod` +* `np.cumproduct` -> `np.cumprod` +* `np.sometrue` -> `np.any` +* `np.alltrue` -> `np.all` + +The deprecated functions will issue a `DeprecationWarning` under NumPy 1.25, and will be removed in NumPy 2.0. + +PiperOrigin-RevId: 538824879 +Change-Id: Icd6a0f4b8fd81bcf0b544e62f4313e41c6adf0ff +--- + tf_slim/layers/layers_test.py | 4 ++-- + tf_slim/metrics/metric_ops_large_test.py | 2 +- + 2 files changed, 3 insertions(+), 3 deletions(-) + +diff --git a/tf_slim/layers/layers_test.py b/tf_slim/layers/layers_test.py +index 0aa91d3..b2b69da 100644 +--- a/tf_slim/layers/layers_test.py ++++ b/tf_slim/layers/layers_test.py +@@ -2703,7 +2703,7 @@ class BatchNormTest(test.TestCase): + def _runBatchNormalizationWithFormat(self, shape, data_format, is_training): + channels = shape[-1] + with self.session(use_gpu=True) as sess: +- images = np.arange(np.product(shape), dtype=np.float32).reshape(shape) ++ images = np.arange(np.prod(shape), dtype=np.float32).reshape(shape) + beta = init_ops.constant_initializer( + np.arange(2, channels + 2, dtype=np.float32)) + gamma = init_ops.constant_initializer( +@@ -2789,7 +2789,7 @@ class BatchNormTest(test.TestCase): + + def _runFusedBatchNorm(self, shape, dtype): + channels = shape[1] +- images = np.arange(np.product(shape), dtype=dtype).reshape(shape) ++ images = np.arange(np.prod(shape), dtype=dtype).reshape(shape) + beta = init_ops.constant_initializer( + np.arange(2, channels + 2, dtype=np.float32)) + gamma = init_ops.constant_initializer( +diff --git a/tf_slim/metrics/metric_ops_large_test.py b/tf_slim/metrics/metric_ops_large_test.py +index 8f653ee..d621df0 100644 +--- a/tf_slim/metrics/metric_ops_large_test.py ++++ b/tf_slim/metrics/metric_ops_large_test.py +@@ -63,7 +63,7 @@ class StreamingPrecisionRecallAtEqualThresholdsLargeTest(test.TestCase): + # Since we use random values, we won't know the tp/fp/tn/fn values, but + # tp and fp at threshold 0 should be the total number of positive and + # negative labels, hence their sum should be total number of pixels. +- expected_value = 1.0 * np.product(shape) * num_updates ++ expected_value = 1.0 * np.prod(shape) * num_updates + got_value = prdata.tp[0] + prdata.fp[0] + # They should be at least within 1. + self.assertNear(got_value, expected_value, 1.0) +-- +2.40.1 + diff --git a/recipe/patches/0024-Use-ExitStack-and-call-ops.device-device-only-when-d.patch b/recipe/patches/0024-Use-ExitStack-and-call-ops.device-device-only-when-d.patch new file mode 100644 index 0000000..ced409e --- /dev/null +++ b/recipe/patches/0024-Use-ExitStack-and-call-ops.device-device-only-when-d.patch @@ -0,0 +1,39 @@ +From e0380eb4a70e205e7fed4d71ed515c6dec224b91 Mon Sep 17 00:00:00 2001 +From: TF-Slim Team +Date: Thu, 22 Jun 2023 07:27:09 -0700 +Subject: [PATCH 24/30] Use ExitStack and call ops.device(device) only when + device is not None, instead of using ops.device(device or '') blindly. This + is to deal with the special legacy behavior of tf.device(''). + +PiperOrigin-RevId: 542553364 +Change-Id: Ia2b52cb0dd729ec3bed0afafa05701560a771f6b +--- + tf_slim/ops/variables.py | 5 ++++- + 1 file changed, 4 insertions(+), 1 deletion(-) + +diff --git a/tf_slim/ops/variables.py b/tf_slim/ops/variables.py +index cbb58b5..3f4fc59 100644 +--- a/tf_slim/ops/variables.py ++++ b/tf_slim/ops/variables.py +@@ -18,6 +18,7 @@ from __future__ import absolute_import + from __future__ import division + from __future__ import print_function + ++import contextlib + import functools + import re + import tensorflow.compat.v1 as tf +@@ -239,7 +240,9 @@ def variable(name, + if custom_getter is not None: + getter = functools.partial( + custom_getter, reuse=variable_scope.get_variable_scope().reuse) +- with ops.device(device or ''): ++ with contextlib.ExitStack() as es: ++ if device is not None: ++ es.enter_context(ops.device(device)) + return getter( + name, + shape=shape, +-- +2.40.1 + diff --git a/recipe/patches/0025-Fix-streaming_concat-crashes-on-specific-and-relativ.patch b/recipe/patches/0025-Fix-streaming_concat-crashes-on-specific-and-relativ.patch new file mode 100644 index 0000000..d7c3f9a --- /dev/null +++ b/recipe/patches/0025-Fix-streaming_concat-crashes-on-specific-and-relativ.patch @@ -0,0 +1,65 @@ +From 9fed2edf2fe1ad9e720e85dfecf38b2093d57039 Mon Sep 17 00:00:00 2001 +From: Alex Kantchelian +Date: Fri, 23 Jun 2023 07:04:10 -0700 +Subject: [PATCH 25/30] Fix streaming_concat crashes on specific and relatively + large inputs. + +A loss of precision issue in _next_array_size() results in invalid minimum array sizes for specific, relatively large inputs. Such array sizes are occasionally encountered for (indirect) users of streaming_concat performing large-scale metric computations, leading to hard-to-reproduce evaluation job crashes. Affected users typically see a runtime error mentioning the strided slice assignment operation `append_values_op = array[size:new_size].assign(batch_values)` with the following message template: `Cannot broadcast input shape [x] into final shape [y]`, where x > y. + +For instance, for the default 1.5 growth factor, the smallest input which results in an error is 7,371,556. For this input, _next_array_size() returns 7,371,555 which is one less than the requested minimal array size. + +PiperOrigin-RevId: 542849164 +Change-Id: Ia998381d0e03b99168a73e3dd7c29c58890cc2b8 +--- + tf_slim/metrics/metric_ops.py | 5 +++-- + tf_slim/metrics/metric_ops_test.py | 17 +++++++++++++++++ + 2 files changed, 20 insertions(+), 2 deletions(-) + +diff --git a/tf_slim/metrics/metric_ops.py b/tf_slim/metrics/metric_ops.py +index ded2f25..dc54177 100644 +--- a/tf_slim/metrics/metric_ops.py ++++ b/tf_slim/metrics/metric_ops.py +@@ -3541,9 +3541,10 @@ def _next_array_size(required_size, growth_factor=1.5): + Returns: + tf.Tensor with dtype=int32 giving the next array size. + """ ++ required_size = math_ops.cast(required_size, dtypes.float64) ++ growth_factor = math_ops.cast(growth_factor, dtypes.float64) + exponent = math_ops.ceil( +- math_ops.log(math_ops.cast(required_size, dtypes.float32)) / +- math_ops.log(math_ops.cast(growth_factor, dtypes.float32))) ++ math_ops.log(required_size) / math_ops.log(growth_factor)) + return math_ops.cast(math_ops.ceil(growth_factor**exponent), dtypes.int32) + + +diff --git a/tf_slim/metrics/metric_ops_test.py b/tf_slim/metrics/metric_ops_test.py +index a5fe9e8..3e6b214 100644 +--- a/tf_slim/metrics/metric_ops_test.py ++++ b/tf_slim/metrics/metric_ops_test.py +@@ -6756,6 +6756,23 @@ class StreamingConcatTest(tf1.test.TestCase): + self.assertEqual(next_array_size(5, growth_factor=2).eval(), 8) + self.assertEqual(next_array_size(6, growth_factor=2).eval(), 8) + ++ def testNextArraySizeHandlesLargeSizes(self): ++ # Tests that next_array_size() always returns a large-enough array size. ++ # Test around the boundaries where off-by-one errors are most likely. ++ growth_factor = 1.5 ++ validity_limit = 2**30 ++ exponent_limit = math.ceil( ++ math.log(validity_limit) / math.log(growth_factor) ++ ) ++ required_size = array_ops.placeholder(dtypes_lib.int32, []) ++ outputed_size = _next_array_size(required_size, growth_factor) ++ with self.cached_session(): ++ for exponent in range(exponent_limit): ++ center = math.ceil(growth_factor**exponent) ++ for x in range(max(1, center - 100), center + 100): ++ self.assertGreaterEqual( ++ outputed_size.eval(feed_dict={required_size: x}), x) ++ + def testStreamingConcat(self): + with self.cached_session() as sess: + values = array_ops.placeholder(dtypes_lib.int32, [None]) +-- +2.40.1 + diff --git a/recipe/patches/0026-Update-ops.Tensor-references-to-third_party-tensorfl.patch b/recipe/patches/0026-Update-ops.Tensor-references-to-third_party-tensorfl.patch new file mode 100644 index 0000000..9f8723a --- /dev/null +++ b/recipe/patches/0026-Update-ops.Tensor-references-to-third_party-tensorfl.patch @@ -0,0 +1,92 @@ +From b6dea832ec5cf5c8709513dc9a8e25ec4d9ee778 Mon Sep 17 00:00:00 2001 +From: Fiona Lang +Date: Tue, 11 Jul 2023 10:57:43 -0700 +Subject: [PATCH 26/30] Update ops.Tensor references to + //third_party/tensorflow/python/framework/tensor.py. + +PiperOrigin-RevId: 547238499 +Change-Id: I59aa34cab5ffe38cbd932080c1ca739753dee0dd +--- + tf_slim/layers/optimizers.py | 3 ++- + tf_slim/layers/utils.py | 5 ++++- + tf_slim/learning.py | 2 +- + tf_slim/metrics/metric_ops_test.py | 4 ++-- + 4 files changed, 9 insertions(+), 5 deletions(-) + +diff --git a/tf_slim/layers/optimizers.py b/tf_slim/layers/optimizers.py +index ea5ca2f..d87d133 100644 +--- a/tf_slim/layers/optimizers.py ++++ b/tf_slim/layers/optimizers.py +@@ -24,6 +24,7 @@ import six + from tensorflow.python.framework import dtypes + from tensorflow.python.framework import indexed_slices + from tensorflow.python.framework import ops ++from tensorflow.python.framework import tensor + from tensorflow.python.ops import array_ops + from tensorflow.python.ops import check_ops + from tensorflow.python.ops import clip_ops +@@ -170,7 +171,7 @@ def optimize_loss(loss, + # Learning rate variable, with possible decay. + lr = None + if learning_rate is not None: +- if (isinstance(learning_rate, ops.Tensor) and ++ if (isinstance(learning_rate, tensor.Tensor) and + learning_rate.get_shape().ndims == 0): + lr = learning_rate + elif isinstance(learning_rate, float): +diff --git a/tf_slim/layers/utils.py b/tf_slim/layers/utils.py +index 5a4a664..e251e5c 100644 +--- a/tf_slim/layers/utils.py ++++ b/tf_slim/layers/utils.py +@@ -24,6 +24,7 @@ from collections import OrderedDict + + # pylint: disable=g-direct-tensorflow-import + from tensorflow.python.framework import ops ++from tensorflow.python.framework import tensor as tensor_lib + from tensorflow.python.framework import tensor_shape + from tensorflow.python.framework import tensor_util + from tensorflow.python.ops import cond +@@ -160,7 +161,9 @@ def constant_value(value_or_tensor_or_var, dtype=None): + if value_or_tensor_or_var is None: + raise ValueError('value_or_tensor_or_var cannot be None') + value = value_or_tensor_or_var +- if isinstance(value_or_tensor_or_var, (ops.Tensor, variables.Variable)): ++ if isinstance( ++ value_or_tensor_or_var, (tensor_lib.Tensor, variables.Variable) ++ ): + if dtype and value_or_tensor_or_var.dtype != dtype: + raise ValueError('It has the wrong type %s instead of %s' % ( + value_or_tensor_or_var.dtype, dtype)) +diff --git a/tf_slim/learning.py b/tf_slim/learning.py +index 5e95058..f5e2d46 100644 +--- a/tf_slim/learning.py ++++ b/tf_slim/learning.py +@@ -338,7 +338,7 @@ def multiply_gradients(grads_and_vars, gradient_multipliers): + raise ValueError('Requested multiple of `None` gradient.') + + multiplier = gradient_multipliers[key] +- if not isinstance(multiplier, ops.Tensor): ++ if not isinstance(multiplier, tf.Tensor): + multiplier = constant_op.constant(multiplier, dtype=grad.dtype) + + if isinstance(grad, indexed_slices.IndexedSlices): +diff --git a/tf_slim/metrics/metric_ops_test.py b/tf_slim/metrics/metric_ops_test.py +index 3e6b214..d66257a 100644 +--- a/tf_slim/metrics/metric_ops_test.py ++++ b/tf_slim/metrics/metric_ops_test.py +@@ -6940,10 +6940,10 @@ class CountTest(tf1.test.TestCase): + + def testReturnType(self): + c, op = metrics.count(array_ops.ones([4, 3])) +- self.assertIsInstance(c, ops.Tensor) ++ self.assertIsInstance(c, tf2.Tensor) + # Note: If resource variables are enabeld the result is a Variable + # (AssignAdd) +- self.assertIsInstance(op, (ops.Operation, ops.Tensor, tf2.Variable)) ++ self.assertIsInstance(op, (ops.Operation, tf2.Tensor, tf2.Variable)) + + def testBasic(self): + with self.cached_session() as sess: +-- +2.40.1 + diff --git a/recipe/patches/0027-Update-legacy-references-to-tensor.Tensor.patch b/recipe/patches/0027-Update-legacy-references-to-tensor.Tensor.patch new file mode 100644 index 0000000..26b655c --- /dev/null +++ b/recipe/patches/0027-Update-legacy-references-to-tensor.Tensor.patch @@ -0,0 +1,44 @@ +From 4e86923aa2fa22fe58aa47ddb8f5bfce5341b361 Mon Sep 17 00:00:00 2001 +From: Fiona Lang +Date: Fri, 11 Aug 2023 11:42:40 -0700 +Subject: [PATCH 27/30] Update legacy references to tensor.Tensor. + +PiperOrigin-RevId: 556031440 +Change-Id: I6c25fbd4d8afeb5cbd8b9c68a611c2ac22eff5f4 +--- + tf_slim/layers/rev_block_lib.py | 5 +++-- + 1 file changed, 3 insertions(+), 2 deletions(-) + +diff --git a/tf_slim/layers/rev_block_lib.py b/tf_slim/layers/rev_block_lib.py +index 4d52bfc..f453f67 100644 +--- a/tf_slim/layers/rev_block_lib.py ++++ b/tf_slim/layers/rev_block_lib.py +@@ -41,6 +41,7 @@ from tensorflow.python import tf2 + from tensorflow.python.eager import backprop + from tensorflow.python.framework import dtypes + from tensorflow.python.framework import ops as framework_ops ++from tensorflow.python.framework import tensor as tensor_lib + from tensorflow.python.ops import array_ops + from tensorflow.python.ops import control_flow_ops + from tensorflow.python.ops import control_flow_util +@@ -505,7 +506,7 @@ def recompute_grad(fn, use_data_dep=_USE_DEFAULT, tupleize_grads=False): + closed_over_vars = dict(zip(fn.__code__.co_freevars, + [c.cell_contents for c in fn.__closure__])) + for var_name, value in six.iteritems(closed_over_vars): +- if isinstance(value, (framework_ops.Tensor, variables_lib.Variable)): ++ if isinstance(value, (tensor_lib.Tensor, variables_lib.Variable)): + raise ValueError( + "fn decorated with @recompute_grad closes over Tensor %s " + "(local variable name: %s). The decorated fn must not close over " +@@ -597,7 +598,7 @@ def _recompute_grad(fn, args, use_data_dep=_USE_DEFAULT, tupleize_grads=False): + """See recompute_grad.""" + has_is_recompute_kwarg = "is_recomputing" in tf_inspect.getargspec(fn).args + for arg in args: +- if not isinstance(arg, (framework_ops.Tensor, variables_lib.Variable)): ++ if not isinstance(arg, (tensor_lib.Tensor, variables_lib.Variable)): + raise ValueError("All inputs to function must be Tensors") + use_data_dep_ = use_data_dep + if use_data_dep_ == _USE_DEFAULT: +-- +2.40.1 + diff --git a/recipe/patches/0028-Move-references-to-TF-resource-variable-toggle-funct.patch b/recipe/patches/0028-Move-references-to-TF-resource-variable-toggle-funct.patch new file mode 100644 index 0000000..a4c9651 --- /dev/null +++ b/recipe/patches/0028-Move-references-to-TF-resource-variable-toggle-funct.patch @@ -0,0 +1,94 @@ +From 0532a6febeb5c3f468921cc3d90965e7fb7b043d Mon Sep 17 00:00:00 2001 +From: Fiona Lang +Date: Tue, 31 Oct 2023 15:23:30 -0700 +Subject: [PATCH 28/30] Move references to TF resource variable toggle + functions to their new location. + +PiperOrigin-RevId: 578319458 +Change-Id: I9beb6a7ee5cf08b1928797e23fe98ab0fab6bd06 +--- + tf_slim/layers/optimizers_test.py | 5 +++-- + tf_slim/metrics/metric_ops_test.py | 4 ++-- + tf_slim/ops/variables_test.py | 7 ++++--- + 3 files changed, 9 insertions(+), 7 deletions(-) + +diff --git a/tf_slim/layers/optimizers_test.py b/tf_slim/layers/optimizers_test.py +index 8d821a6..430e533 100644 +--- a/tf_slim/layers/optimizers_test.py ++++ b/tf_slim/layers/optimizers_test.py +@@ -32,6 +32,7 @@ from tensorflow.python.framework import random_seed + from tensorflow.python.ops import array_ops + from tensorflow.python.ops import init_ops + from tensorflow.python.ops import math_ops ++from tensorflow.python.ops import resource_variables_toggle + from tensorflow.python.ops import state_ops + from tensorflow.python.ops import variable_scope + from tensorflow.python.ops import variables +@@ -45,11 +46,11 @@ def setUpModule(): + + def disable_resource_variables(f): + def wrapper(*args, **kwargs): +- variable_scope.disable_resource_variables() ++ resource_variables_toggle.disable_resource_variables() + try: + f(*args, **kwargs) + finally: +- variable_scope.enable_resource_variables() ++ resource_variables_toggle.enable_resource_variables() + return wrapper + + +diff --git a/tf_slim/metrics/metric_ops_test.py b/tf_slim/metrics/metric_ops_test.py +index d66257a..daefab0 100644 +--- a/tf_slim/metrics/metric_ops_test.py ++++ b/tf_slim/metrics/metric_ops_test.py +@@ -39,7 +39,7 @@ from tensorflow.python.ops import array_ops + from tensorflow.python.ops import data_flow_ops + from tensorflow.python.ops import math_ops + from tensorflow.python.ops import random_ops +-from tensorflow.python.ops import variable_scope ++from tensorflow.python.ops import resource_variables_toggle + from tensorflow.python.ops import variable_v1 + from tensorflow.python.ops import variables + +@@ -6726,7 +6726,7 @@ class StreamingConcatTest(tf1.test.TestCase): + + def setUp(self): + super(StreamingConcatTest, self).setUp() +- variable_scope.enable_resource_variables() ++ resource_variables_toggle.enable_resource_variables() + + def testVars(self): + metrics.streaming_concat(values=array_ops.ones((10,))) +diff --git a/tf_slim/ops/variables_test.py b/tf_slim/ops/variables_test.py +index a87f5d9..69a9912 100644 +--- a/tf_slim/ops/variables_test.py ++++ b/tf_slim/ops/variables_test.py +@@ -40,6 +40,7 @@ from tensorflow.python.ops import init_ops + from tensorflow.python.ops import nn_ops + from tensorflow.python.ops import partitioned_variables + from tensorflow.python.ops import resource_variable_ops ++from tensorflow.python.ops import resource_variables_toggle + from tensorflow.python.ops import variable_scope + from tensorflow.python.ops import variable_v1 + from tensorflow.python.ops import variables as variables_lib +@@ -54,13 +55,13 @@ def setUpModule(): + + @contextlib.contextmanager + def temporary_disable_resource_variables(): +- enabled = variable_scope.resource_variables_enabled() ++ enabled = resource_variables_toggle.resource_variables_enabled() + try: +- variable_scope.disable_resource_variables() ++ resource_variables_toggle.disable_resource_variables() + yield + finally: + if enabled: +- variable_scope.enable_resource_variables() ++ resource_variables_toggle.enable_resource_variables() + + + class LocalVariableTest(test.TestCase): +-- +2.40.1 + diff --git a/recipe/patches/0029-Update-outdated-references-to-functions-imported-by-.patch b/recipe/patches/0029-Update-outdated-references-to-functions-imported-by-.patch new file mode 100644 index 0000000..4c79a24 --- /dev/null +++ b/recipe/patches/0029-Update-outdated-references-to-functions-imported-by-.patch @@ -0,0 +1,121 @@ +From dbe1d0b0e9d82ecf6307b670f23b45c29b4cb193 Mon Sep 17 00:00:00 2001 +From: Fiona Lang +Date: Wed, 1 Nov 2023 11:29:42 -0700 +Subject: [PATCH 29/30] Update outdated references to functions imported by + standard_ops.py to their actual locations. + +PiperOrigin-RevId: 578583336 +Change-Id: I91f4970eb185d31a24d69ce1b45371454ff9ca2a +--- + tf_slim/layers/layers.py | 7 +++---- + tf_slim/layers/regularizers.py | 7 +++---- + tf_slim/layers/summaries.py | 18 +++++++++--------- + 3 files changed, 15 insertions(+), 17 deletions(-) + +diff --git a/tf_slim/layers/layers.py b/tf_slim/layers/layers.py +index c91cc1d..86030fd 100644 +--- a/tf_slim/layers/layers.py ++++ b/tf_slim/layers/layers.py +@@ -45,7 +45,6 @@ from tensorflow.python.ops import linalg_ops + from tensorflow.python.ops import math_ops + from tensorflow.python.ops import nn + from tensorflow.python.ops import sparse_ops +-from tensorflow.python.ops import standard_ops + from tensorflow.python.ops import variable_scope + from tensorflow.python.ops import variables as tf_variables + from tensorflow.python.training import moving_averages +@@ -2585,8 +2584,8 @@ def one_hot_encoding(labels, + with ops.name_scope(scope, 'OneHotEncoding', [labels, num_classes]) as sc: + labels = ops.convert_to_tensor(labels) + if labels.dtype == dtypes.int32: +- labels = standard_ops.to_int64(labels) +- outputs = standard_ops.one_hot( ++ labels = math_ops.to_int64(labels) ++ outputs = array_ops.one_hot( + labels, num_classes, on_value=on_value, off_value=off_value) + return utils.collect_named_outputs(outputs_collections, sc, outputs) + +@@ -3301,7 +3300,7 @@ def legacy_fully_connected(x, + trainable=trainable) + x_2_dim = x if len(dims) <= 2 else array_ops.reshape( + x, [-1, num_input_units]) +- y = standard_ops.matmul(x_2_dim, w) ++ y = math_ops.matmul(x_2_dim, w) + + if bias_init is not None: + bias_collections = set( +diff --git a/tf_slim/layers/regularizers.py b/tf_slim/layers/regularizers.py +index d84a424..2067df7 100644 +--- a/tf_slim/layers/regularizers.py ++++ b/tf_slim/layers/regularizers.py +@@ -26,7 +26,6 @@ from tensorflow.python.framework import constant_op + from tensorflow.python.framework import ops + from tensorflow.python.ops import math_ops + from tensorflow.python.ops import nn +-from tensorflow.python.ops import standard_ops + + __all__ = ['l1_regularizer', + 'l2_regularizer', +@@ -66,9 +65,9 @@ def l1_regularizer(scale, scope=None): + my_scale = ops.convert_to_tensor(scale, + dtype=weights.dtype.base_dtype, + name='scale') +- return standard_ops.multiply( ++ return math_ops.multiply( + my_scale, +- standard_ops.reduce_sum(standard_ops.abs(weights)), ++ math_ops.reduce_sum(math_ops.abs(weights)), + name=name) + + return l1 +@@ -105,7 +104,7 @@ def l2_regularizer(scale, scope=None): + my_scale = ops.convert_to_tensor(scale, + dtype=weights.dtype.base_dtype, + name='scale') +- return standard_ops.multiply(my_scale, nn.l2_loss(weights), name=name) ++ return math_ops.multiply(my_scale, nn.l2_loss(weights), name=name) + + return l2 + +diff --git a/tf_slim/layers/summaries.py b/tf_slim/layers/summaries.py +index cbda467..57f76f8 100644 +--- a/tf_slim/layers/summaries.py ++++ b/tf_slim/layers/summaries.py +@@ -24,7 +24,7 @@ import re + # pylint: disable=g-direct-tensorflow-import + from tensorflow.python.framework import dtypes + from tensorflow.python.framework import ops +-from tensorflow.python.ops import standard_ops ++from tensorflow.python.ops import math_ops + from tensorflow.python.summary import summary + + __all__ = [ +@@ -88,17 +88,17 @@ def summarize_activation(op): + if op.op.type in ('Relu', 'Softplus', 'Relu6'): + # Using inputs to avoid floating point equality and/or epsilons. + _add_scalar_summary( +- standard_ops.reduce_mean( +- standard_ops.to_float( +- standard_ops.less(op.op.inputs[ +- 0], standard_ops.cast(0.0, op.op.inputs[0].dtype)))), ++ math_ops.reduce_mean( ++ math_ops.to_float( ++ math_ops.less(op.op.inputs[ ++ 0], math_ops.cast(0.0, op.op.inputs[0].dtype)))), + '%s/zeros' % op.op.name) + if op.op.type == 'Relu6': + _add_scalar_summary( +- standard_ops.reduce_mean( +- standard_ops.to_float( +- standard_ops.greater(op.op.inputs[ +- 0], standard_ops.cast(6.0, op.op.inputs[0].dtype)))), ++ math_ops.reduce_mean( ++ math_ops.to_float( ++ math_ops.greater(op.op.inputs[ ++ 0], math_ops.cast(6.0, op.op.inputs[0].dtype)))), + '%s/sixes' % op.op.name) + return _add_histogram_summary(op, '%s/activation' % op.op.name) + +-- +2.40.1 + diff --git a/recipe/21-avoid_layer_apply.patch b/recipe/patches/0030-Remove-call-to-layer.apply-and-just-use-__call__.patch similarity index 95% rename from recipe/21-avoid_layer_apply.patch rename to recipe/patches/0030-Remove-call-to-layer.apply-and-just-use-__call__.patch index 25c793c..65b5efd 100644 --- a/recipe/21-avoid_layer_apply.patch +++ b/recipe/patches/0030-Remove-call-to-layer.apply-and-just-use-__call__.patch @@ -1,14 +1,14 @@ -From 2f4f346d3cc51da6f10c2dd01cbf23e025acfc07 Mon Sep 17 00:00:00 2001 +From 277dab3d20d6207cf119a2ddf2161c61ebf06b16 Mon Sep 17 00:00:00 2001 From: Mark Harfouche Date: Wed, 13 Jul 2022 12:48:03 -0400 -Subject: [PATCH] Remove call to layer.apply and just use __call__ +Subject: [PATCH 30/30] Remove call to layer.apply and just use __call__ --- tf_slim/layers/layers.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tf_slim/layers/layers.py b/tf_slim/layers/layers.py -index f8cb8e9..1da4de5 100644 +index 86030fd..a04819e 100644 --- a/tf_slim/layers/layers.py +++ b/tf_slim/layers/layers.py @@ -115,7 +115,7 @@ def avg_pool2d(inputs, @@ -119,3 +119,6 @@ index f8cb8e9..1da4de5 100644 # Add variables to collections. _add_variable_to_collections(layer.depthwise_kernel, +-- +2.40.1 + From 1da6d6884fb67e6c9e3490efa16f9d43f69498f1 Mon Sep 17 00:00:00 2001 From: Mark Harfouche Date: Tue, 28 Nov 2023 08:32:03 -0500 Subject: [PATCH 2/2] Fixup patch location --- recipe/meta.yaml | 60 ++++++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/recipe/meta.yaml b/recipe/meta.yaml index 4bbadca..8a6d47d 100644 --- a/recipe/meta.yaml +++ b/recipe/meta.yaml @@ -11,37 +11,37 @@ source: # https://github.com/google-research/tf-slim/pull/21 # git checkout remove_layer_apply # git format-patch 8f0215e924996d7287392241bc8d8b1133d0c5ca - - 0001-Internal-change.patch - - 0002-Set-the-default-value-for-the-use_gpu-param-to-True-.patch - - 0003-Fix-a-NaN-issue-with-streaming_covariance.patch - - 0004-Remove-the-private-TF-API-usage-of-layers.patch - - 0005-Internal-Google-change.patch - - 0006-Fix-TensorFlow-checkpoint-and-trackable-imports.patch - - 0007-NumPy-Fix-NumPy-1.23-compatibility-problems-in-tf_sl.patch - - 0008-Fix-tests-broken-by-previous-change-list-due-to-smal.patch - - 0009-NumPy-Remove-references-to-deprecated-NumPy-type-ali.patch - - 0010-NumPy-Remove-references-to-deprecated-NumPy-type-ali.patch - - 0011-Remove-legacy-references-from-ops.py.patch - - 0012-Redirect-references-to-stack-and-unstack-to-their-ne.patch - - 0013-Refactor-case-and-case_v2-out-of-control_flow_ops.py.patch - - 0014-Move-control_flow_ops.Assert-into-its-own-file-contr.patch - - 0015-Move-control_flow_ops.while_loop-into-its-own-file-w.patch - - 0016-Redirect-references-from-control_flow_ops.cond-to-co.patch - - 0017-Update-some-isinstance-checks-of-tf.compat.v1.Variab.patch - - 0018-Update-references-from-variables.VariableV1-to-its-n.patch - - 0019-Update-references-from-tensorflow.python.platform-to.patch - - 0020-Update-legacy-reference-to-variable_scope.variable-i.patch - - 0021-Internal-Code-Change.patch - - 0022-Delete-remnants-of-toollog-removal.patch - - 0023-NumPy-Fix-uses-of-functions-deprecated-in-NumPy-1.25.patch - - 0024-Use-ExitStack-and-call-ops.device-device-only-when-d.patch - - 0025-Fix-streaming_concat-crashes-on-specific-and-relativ.patch - - 0026-Update-ops.Tensor-references-to-third_party-tensorfl.patch - - 0027-Update-legacy-references-to-tensor.Tensor.patch - - 0028-Move-references-to-TF-resource-variable-toggle-funct.patch - - 0029-Update-outdated-references-to-functions-imported-by-.patch + - patches/0001-Internal-change.patch + - patches/0002-Set-the-default-value-for-the-use_gpu-param-to-True-.patch + - patches/0003-Fix-a-NaN-issue-with-streaming_covariance.patch + - patches/0004-Remove-the-private-TF-API-usage-of-layers.patch + - patches/0005-Internal-Google-change.patch + - patches/0006-Fix-TensorFlow-checkpoint-and-trackable-imports.patch + - patches/0007-NumPy-Fix-NumPy-1.23-compatibility-problems-in-tf_sl.patch + - patches/0008-Fix-tests-broken-by-previous-change-list-due-to-smal.patch + - patches/0009-NumPy-Remove-references-to-deprecated-NumPy-type-ali.patch + - patches/0010-NumPy-Remove-references-to-deprecated-NumPy-type-ali.patch + - patches/0011-Remove-legacy-references-from-ops.py.patch + - patches/0012-Redirect-references-to-stack-and-unstack-to-their-ne.patch + - patches/0013-Refactor-case-and-case_v2-out-of-control_flow_ops.py.patch + - patches/0014-Move-control_flow_ops.Assert-into-its-own-file-contr.patch + - patches/0015-Move-control_flow_ops.while_loop-into-its-own-file-w.patch + - patches/0016-Redirect-references-from-control_flow_ops.cond-to-co.patch + - patches/0017-Update-some-isinstance-checks-of-tf.compat.v1.Variab.patch + - patches/0018-Update-references-from-variables.VariableV1-to-its-n.patch + - patches/0019-Update-references-from-tensorflow.python.platform-to.patch + - patches/0020-Update-legacy-reference-to-variable_scope.variable-i.patch + - patches/0021-Internal-Code-Change.patch + - patches/0022-Delete-remnants-of-toollog-removal.patch + - patches/0023-NumPy-Fix-uses-of-functions-deprecated-in-NumPy-1.25.patch + - patches/0024-Use-ExitStack-and-call-ops.device-device-only-when-d.patch + - patches/0025-Fix-streaming_concat-crashes-on-specific-and-relativ.patch + - patches/0026-Update-ops.Tensor-references-to-third_party-tensorfl.patch + - patches/0027-Update-legacy-references-to-tensor.Tensor.patch + - patches/0028-Move-references-to-TF-resource-variable-toggle-funct.patch + - patches/0029-Update-outdated-references-to-functions-imported-by-.patch # https://github.com/google-research/tf-slim/pull/21 - - 0030-Remove-call-to-layer.apply-and-just-use-__call__.patch + - patches/0030-Remove-call-to-layer.apply-and-just-use-__call__.patch build: noarch: python