Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix error: Cannot register 2 metrics with the same name: /tensorflow/api/keras/optimizers

When I am trying to run a Python code for deep learning utilizing the TensorFlow library, I am getting the following error:

2021-10-24 10:07:13.619481: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
2021-10-24 10:07:13.619752: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
2021-10-24 10:07:18.797570: E tensorflow/core/lib/monitoring/collection_registry.cc:77] `Cannot register 2 metrics with the same name: /tensorflow/api/keras/optimizers`
Traceback (most recent call last):
  File "C:\Users\Admin\Downloads\Compressed\Face-Mask-Detection-master\detect_mask_image.py", line 5, in <module>
    from tensorflow.keras.applications.mobilenet_v2 import preprocess_input
  File "C:\Python39\lib\site-packages\keras\api\_v2\keras\__init__.py", line 8, in <module>
    from keras import __version__
  File "C:\Python39\lib\site-packages\keras\__init__.py", line 25, in <module>
    from keras import models
  File "C:\Python39\lib\site-packages\keras\models.py", line 20, in <module>
    from keras import metrics as metrics_module
  File "C:\Python39\lib\site-packages\keras\metrics.py", line 26, in <module>
    from keras import activations
  File "C:\Python39\lib\site-packages\keras\activations.py", line 20, in <module>
    from keras.layers import advanced_activations
  File "C:\Python39\lib\site-packages\keras\layers\__init__.py", line 23, in <module>
    from keras.engine.input_layer import Input
  File "C:\Python39\lib\site-packages\keras\engine\input_layer.py", line 21, in <module>
    from keras.engine import base_layer
  File "C:\Python39\lib\site-packages\keras\engine\base_layer.py", line 43, in <module>
    from keras.mixed_precision import loss_scale_optimizer
  File "C:\Python39\lib\site-packages\keras\mixed_precision\loss_scale_optimizer.py", line 18, in <module>
    from keras import optimizers
  File "C:\Python39\lib\site-packages\keras\optimizers.py", line 26, in <module>
    from keras.optimizer_v2 import adadelta as adadelta_v2
  File "C:\Python39\lib\site-packages\keras\optimizer_v2\adadelta.py", line 22, in <module>
    from keras.optimizer_v2 import optimizer_v2
  File "C:\Python39\lib\site-packages\keras\optimizer_v2\optimizer_v2.py", line 36, in <module>
    keras_optimizers_gauge = tf.__internal__.monitoring.BoolGauge(
  File "C:\Python39\lib\site-packages\tensorflow\python\eager\monitoring.py", line 360, in __init__
    super(BoolGauge, self).__init__('BoolGauge', _bool_gauge_methods,
  File "C:\Python39\lib\site-packages\tensorflow\python\eager\monitoring.py", line 135, in __init__
    self._metric = self._metric_methods[self._label_length].create(*args)
tensorflow.python.framework.errors_impl.
AlreadyExistsError: Another metric with the same name already exists.

Environment:

Python version: 3.9

OS: Windows

Library: TensorFlow API

like image 618
GEOFFREY ZIMBA Avatar asked Oct 24 '21 08:10

GEOFFREY ZIMBA


1 Answers

This appears to be a bug with tensorflow 2.6 see https://forums.developer.nvidia.com/t/unable-to-import-keras-models-on-tensorflow-2-6-0-jetpack-v46/191904

I had the same issue and solved it by downgrading to tensorflow 2.5 until the issue is resolved in a future update.

**Edit: 2.7 is out and seems to have fixed the issue.

*Note: I am using tensorflow with my CPU, not a GPU.

like image 146
LogDog23 Avatar answered Sep 21 '22 20:09

LogDog23