AlreadyExistsError: Another metric with the same name already exists

Dear All,

I’ve updated Tensorflow and Keras to 2.6.0. (I use Windows 10 and Python 3.9.6)

While trying to follow this tutorial, Next-Frame Video Prediction with Convolutional LSTMs

import numpy as np
import matplotlib.pyplot as plt

import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers

I’ve faced the following issue.

---------------------------------------------------------------------------
AlreadyExistsError                        Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_16440/2264619257.py in <module>
      4 import tensorflow as tf
      5 from tensorflow import keras
----> 6 from tensorflow.keras import layers
      7 
      8 import io

c:\users\admin\appdata\local\programs\python\python39\lib\site-packages\keras\api\_v2\keras\__init__.py in <module>
      8 import sys as _sys
      9 
---> 10 from keras import __version__
     11 from keras.api._v2.keras import __internal__
     12 from keras.api._v2.keras import activations

c:\users\admin\appdata\local\programs\python\python39\lib\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

c:\users\admin\appdata\local\programs\python\python39\lib\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

c:\users\admin\appdata\local\programs\python\python39\lib\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

c:\users\admin\appdata\local\programs\python\python39\lib\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

c:\users\admin\appdata\local\programs\python\python39\lib\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

c:\users\admin\appdata\local\programs\python\python39\lib\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

c:\users\admin\appdata\local\programs\python\python39\lib\site-packages\keras\engine\base_layer.py in <module>
     40 from keras.engine import node as node_module
     41 from keras.mixed_precision import autocast_variable
---> 42 from keras.mixed_precision import loss_scale_optimizer
     43 from keras.mixed_precision import policy
     44 from keras.saving.saved_model import layer_serialization

c:\users\admin\appdata\local\programs\python\python39\lib\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

c:\users\admin\appdata\local\programs\python\python39\lib\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

c:\users\admin\appdata\local\programs\python\python39\lib\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 

c:\users\admin\appdata\local\programs\python\python39\lib\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 

c:\users\admin\appdata\local\programs\python\python39\lib\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 

c:\users\admin\appdata\local\programs\python\python39\lib\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.

Do you have an env with Python 3.7? could you try on that?

I’m asking because on Colab (Python 3.7.11), that cell worked fine.
This is just to help find the issue.

1 Like

I tried using Python 3.7.9 …

No issue here.

1 Like

hummm, can you please create a bug on the TF repo?

I’ve raised an issue

Thank you lgusm for your kind support

2 Likes

Thank you for bringing that up and creating the bug! Let’s make TF better for everyone!

When i tried to run beginner.ipynb file i a getting error-tensorflow.python.framework.errors_impl.AlreadyExistsError: Another metric with the same name already exists.

I tried running the notebook and I got some other error when showing the dataset, maybe the notebook need some update

I found the creator here https://twitter.com/amogh7joshi
but I can’t message him. It would be great to bring awareness to them.

I’ve ran the notebook again in TF 2.4, 2.5, and 2.6, and while I found the error with showing the dataset, I can’t seem to reproduce the AlreadyExistsError. Maybe try restarting your runtime or seeing if you accidentally modified the code somewhere?

1 Like

AlreadyExistsError comes in local command prompt on windows.I had installed 2.6.0 and python 3.8. i get this error when i run python beginner.py in command prompt.

Same problem here – try running this code for example: mlflow/examples/tensorflow/tf2 at master · mlflow/mlflow · GitHub .
System details: Win 10, TF 2.6.0, Python 3.8.8.
Please resolve this annoying issue which blocks my project.

Same problem here, but below issues help me to fix this error.

Import Libraries

import warnings
warnings.filterwarnings(“ignore”)
import tensorflow as tf
import os
import glob
import matplotlib.pyplot as plt

Keras API

import keras
from keras.models import Sequential
from keras.layers import Dense,Dropout,Flatten
from keras.layers import Conv2D,MaxPooling2D,Activation,AveragePooling2D,BatchNormalization
from keras.preprocessing.image import ImageDataGenerator

when I imports then it shows me

AlreadyExistsError Traceback (most recent call last)
in
7 import matplotlib.pyplot as plt
8 # Keras API
----> 9 import keras
10 from keras.models import Sequential
11 from keras.layers import Dense,Dropout,Flatten

D:\anaconda\lib\site-packages\keras_init_.py in
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

D:\anaconda\lib\site-packages\keras\models.py in
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

D:\anaconda\lib\site-packages\keras\metrics.py in
24
25 import numpy as np
—> 26 from keras import activations
27 from keras import backend
28 from keras.engine import base_layer

D:\anaconda\lib\site-packages\keras\activations.py in
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

D:\anaconda\lib\site-packages\keras\layers_init_.py in
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

D:\anaconda\lib\site-packages\keras\engine\input_layer.py in
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

D:\anaconda\lib\site-packages\keras\engine\base_layer.py in
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

D:\anaconda\lib\site-packages\keras\mixed_precision\loss_scale_optimizer.py in
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

D:\anaconda\lib\site-packages\keras\optimizers.py in
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

D:\anaconda\lib\site-packages\keras\optimizer_v2\adadelta.py in
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

D:\anaconda\lib\site-packages\keras\optimizer_v2\optimizer_v2.py in
34
35
—> 36 keras_optimizers_gauge = tf.internal.monitoring.BoolGauge(
37 “/tensorflow/api/keras/optimizers”, “keras optimizer usage”, “method”)
38

D:\anaconda\lib\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

D:\anaconda\lib\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.

How can I Fix this :confused: