Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimizer import raises an error with keras 2.7 #15585

Closed
frgfm opened this issue Nov 4, 2021 · 1 comment
Closed

Optimizer import raises an error with keras 2.7 #15585

frgfm opened this issue Nov 4, 2021 · 1 comment

Comments

@frgfm
Copy link

frgfm commented Nov 4, 2021

System information.

  • Have I written custom code (as opposed to using a stock example script provided in Keras): no
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Ubuntu 20.04 LTS
  • TensorFlow installed from (source or binary): binary
  • TensorFlow version (use command below): 2.6.0
  • Python version: 3.8.10
  • Bazel version (if compiling from source): N/A
  • GPU model and memory: NVIDIA GeForce RTX 2070 with Max-Q Design

Describe the problem.

I encountered a CI problem with a build job today that wasn't happening yesterday. So I checked the difference in terms of dependency and the only difference was keras. So I inspected the traceback and ended up tracking the import from keras that causes trouble. Please note this is a big issue, because the original call was from tensorflow from tensorflow.keras.utils import img_to_array and the underlying troubling import is from keras.

Describe the current behavior.

Running the standalone code throws a AlreadyExistsError

Describe the expected behavior.

Not raising an error.

  • Do you want to contribute a PR? (yes/no): happy to do so, but I'm not sure how to solve this
  • If yes, please read this page for instructions
  • Briefly describe your candidate solution(if contributing):

Standalone code to reproduce the issue.

from keras import optimizers

Source code / logs.

---------------------------------------------------------------------------
AlreadyExistsError                        Traceback (most recent call last)
<ipython-input-1-d1acaf7a1f6f> in <module>
----> 1 from keras import optimizers

~/miniconda3/lib/python3.8/site-packages/keras/__init__.py in <module>
     23 
     24 # See b/110718070#comment18 for more details about this import.
---> 25 from keras import models
     26 
     27 from keras.engine.input_layer import Input

~/miniconda3/lib/python3.8/site-packages/keras/models.py in <module>
     18 import tensorflow.compat.v2 as tf
     19 from keras import backend
---> 20 from keras import metrics as metrics_module
     21 from keras import optimizer_v1
     22 from keras.engine import functional

~/miniconda3/lib/python3.8/site-packages/keras/metrics.py in <module>
     24 
     25 import numpy as np
---> 26 from keras import activations
     27 from keras import backend
     28 from keras.engine import base_layer

~/miniconda3/lib/python3.8/site-packages/keras/activations.py in <module>
     18 
     19 from keras import backend
---> 20 from keras.layers import advanced_activations
     21 from keras.utils.generic_utils import deserialize_keras_object
     22 from keras.utils.generic_utils import serialize_keras_object

~/miniconda3/lib/python3.8/site-packages/keras/layers/__init__.py in <module>
     21 
     22 # Generic layers.
---> 23 from keras.engine.input_layer import Input
     24 from keras.engine.input_layer import InputLayer
     25 from keras.engine.input_spec import InputSpec

~/miniconda3/lib/python3.8/site-packages/keras/engine/input_layer.py in <module>
     19 from keras import backend
     20 from keras.distribute import distributed_training_utils
---> 21 from keras.engine import base_layer
     22 from keras.engine import keras_tensor
     23 from keras.engine import node as node_module

~/miniconda3/lib/python3.8/site-packages/keras/engine/base_layer.py in <module>
     41 from keras.engine import node as node_module
     42 from keras.mixed_precision import autocast_variable
---> 43 from keras.mixed_precision import loss_scale_optimizer
     44 from keras.mixed_precision import policy
     45 from keras.saving.saved_model import layer_serialization

~/miniconda3/lib/python3.8/site-packages/keras/mixed_precision/loss_scale_optimizer.py in <module>
     16 
     17 from keras import backend
---> 18 from keras import optimizers
     19 from keras.mixed_precision import loss_scale as keras_loss_scale_module
     20 from keras.optimizer_v2 import optimizer_v2

~/miniconda3/lib/python3.8/site-packages/keras/optimizers.py in <module>
     24 from keras.optimizer_v1 import Optimizer
     25 from keras.optimizer_v1 import TFOptimizer
---> 26 from keras.optimizer_v2 import adadelta as adadelta_v2
     27 from keras.optimizer_v2 import adagrad as adagrad_v2
     28 from keras.optimizer_v2 import adam as adam_v2

~/miniconda3/lib/python3.8/site-packages/keras/optimizer_v2/adadelta.py in <module>
     20 import numpy as np
     21 from keras import backend_config
---> 22 from keras.optimizer_v2 import optimizer_v2
     23 from tensorflow.python.util.tf_export import keras_export
     24 

~/miniconda3/lib/python3.8/site-packages/keras/optimizer_v2/optimizer_v2.py in <module>
     34 
     35 
---> 36 keras_optimizers_gauge = tf.__internal__.monitoring.BoolGauge(
     37     "/tensorflow/api/keras/optimizers", "keras optimizer usage", "method")
     38 

~/miniconda3/lib/python3.8/site-packages/tensorflow/python/eager/monitoring.py in __init__(self, name, description, *labels)
    358       *labels: The label list of the new metric.
    359     """
--> 360     super(BoolGauge, self).__init__('BoolGauge', _bool_gauge_methods,
    361                                     len(labels), name, description, *labels)
    362 

~/miniconda3/lib/python3.8/site-packages/tensorflow/python/eager/monitoring.py in __init__(self, metric_name, metric_methods, label_length, *args)
    133           self._metric_name, len(self._metric_methods)))
    134 
--> 135     self._metric = self._metric_methods[self._label_length].create(*args)
    136 
    137   def __del__(self):

AlreadyExistsError: Another metric with the same name already exists.
@qlzh727
Copy link
Member

qlzh727 commented Nov 4, 2021

Please see #15579 for more details. The issue should now be mitigated by using tf 2.6.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants