# Cannot register 2 metrics with the same name: /tensorflow/api/keras/optimizers

**URL:** <https://discuss.ai.google.dev/t/cannot-register-2-metrics-with-the-same-name-tensorflow-api-keras-optimizers/28519>\
**Category:** Build\
**Tags:** help\_request\
**Created:** [July 14, 2021, 6:48pm UTC](https://discuss.ai.google.dev/t/cannot-register-2-metrics-with-the-same-name-tensorflow-api-keras-optimizers/28519 "2021-07-14T18:48:43Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Deven\_Desai](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/deven_desai/32/6398_2.png) [@Deven\_Desai](https://discuss.ai.google.dev/u/Deven_Desai)\
**Post date:** [July 14, 2021, 6:48pm UTC](https://discuss.ai.google.dev/t/cannot-register-2-metrics-with-the-same-name-tensorflow-api-keras-optimizers/28519/1 "2021-07-14T18:48:43Z")

</div>

We are starting to see this error in some of the unit tests, within recent docker containers we are creating.

```auto
2021-07-14 02:13:34.052676: E tensorflow/core/lib/monitoring/collection_registry.cc:77] Cannot register 2 metrics with the same name: /tensorflow/api/keras/optimizers

```

see this in the tip of develop branch (which is a fork of the upstream/master branch) and in the tip of our r2.6 branch (which is a fork of the upstream/r2.6 branch)

see this in about 10+ of the unit tests…these ones

```auto
  21134://tensorflow/python/compiler/xla:xla_test_gpu FAILED in 3 out of 3 in 3.6s                                                                                                                                                      
  21139://tensorflow/python/keras/benchmarks:eager_microbenchmarks_test_gpu FAILED in 3 out of 3 in 3.6s                                                                                                                                                      
  21144://tensorflow/python/keras/benchmarks:model_components_benchmarks_test_gpu FAILED in 3 out of 3 in 3.5s                                                                                                                                                     
  21149://tensorflow/python/keras/benchmarks/keras_examples_benchmarks:antirectifier_benchmark_test_gpu FAILED in 3 out of 3 in 3.4s                                                                                                                               
  21154://tensorflow/python/keras/benchmarks/keras_examples_benchmarks:bidirectional_lstm_benchmark_test_gpu FAILED in 3 out of 3 in 3.5s                                                                                                                          
  21159://tensorflow/python/keras/benchmarks/keras_examples_benchmarks:cifar10_cnn_benchmark_test_gpu FAILED in 3 out of 3 in 3.6s                                                                                                                                 
  21164://tensorflow/python/keras/benchmarks/keras_examples_benchmarks:mnist_conv_benchmark_test_gpu FAILED in 3 out of 3 in 3.5s                                                                                                                                  
  21169://tensorflow/python/keras/benchmarks/keras_examples_benchmarks:mnist_conv_custom_training_benchmark_test_gpu FAILED in 3 out of 3 in 3.7s                                                                                                                  
  21174://tensorflow/python/keras/benchmarks/keras_examples_benchmarks:mnist_hierarchical_rnn_benchmark_test_gpu FAILED in 3 out of 3 in 3.5s                                                                                                                      
  21179://tensorflow/python/keras/benchmarks/keras_examples_benchmarks:mnist_irnn_benchmark_test_gpu FAILED in 3 out of 3 in 3.5s                                                                                                                                  
  21184://tensorflow/python/keras/benchmarks/keras_examples_benchmarks:reuters_mlp_benchmark_test_gpu FAILED in 3 out of 3 in 3.5s                                                                                                                                 
  21189://tensorflow/python/keras/benchmarks/keras_examples_benchmarks:text_classification_transformer_benchmark_test_gpu FAILED in 3 out of 3 in 3.7s                                                                                                             
  21194://tensorflow/python/ops/numpy_ops:np_interop_test_gpu FAILED in 3 out of 3 in 29.1s         

```

Anyone else running into this?

Any insight as to what might be causing this?

---

<div class="post-metadata">

**Author:** ![Deven\_Desai](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/deven_desai/32/6398_2.png) [@Deven\_Desai](https://discuss.ai.google.dev/u/Deven_Desai)\
**Post date:** [July 14, 2021, 6:57pm UTC](https://discuss.ai.google.dev/t/cannot-register-2-metrics-with-the-same-name-tensorflow-api-keras-optimizers/28519/2 "2021-07-14T18:57:36Z")

</div>

The docker containers we build, use this script to install all the pip packages

> <https://github.com/ROCm/tensorflow-upstream/blob/develop-upstream/tensorflow/tools/ci_build/install/install_pip_packages.sh>

which in turn seems to install the `keras-nightly` package

> <https://github.com/ROCm/tensorflow-upstream/blob/develop-upstream/tensorflow/tools/ci_build/install/install_pip_packages.sh#L98>

is that still the correct thing to do? and is that co-related to the error we are getting?

thanks

---

<div class="post-metadata">

**Author:** ![Bhack](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/bhack/32/6388_2.png) [@Bhack](https://discuss.ai.google.dev/u/Bhack)\
**Post date:** [July 14, 2021, 8:32pm UTC](https://discuss.ai.google.dev/t/cannot-register-2-metrics-with-the-same-name-tensorflow-api-keras-optimizers/28519/3 "2021-07-14T20:32:41Z")

</div>

On 2.6 branch is

> <https://github.com/tensorflow/tensorflow/blob/v2.6.0-rc1/tensorflow/tools/ci_build/release/requirements_common.txt#L27>

Or not?

---

<div class="post-metadata">

**Author:** ![Deven\_Desai](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/deven_desai/32/6398_2.png) [@Deven\_Desai](https://discuss.ai.google.dev/u/Deven_Desai)\
**Post date:** [July 15, 2021, 12:31am UTC](https://discuss.ai.google.dev/t/cannot-register-2-metrics-with-the-same-name-tensorflow-api-keras-optimizers/28519/4 "2021-07-15T00:31:58Z")

</div>

pinning the version numbers worked…thank you @Bhack

---

<div class="post-metadata">

**Author:** ![Avner\_Safrani](https://avatars.discourse-cdn.com/v4/letter/a/f04885/32.png) [@Avner\_Safrani](https://discuss.ai.google.dev/u/Avner_Safrani)\
**Post date:** [October 11, 2021, 3:02am UTC](https://discuss.ai.google.dev/t/cannot-register-2-metrics-with-the-same-name-tensorflow-api-keras-optimizers/28519/6 "2021-10-11T03:02:02Z")

</div>

Hello Bhack,  
I saw your reply to Deven\_Desai. I’m having a similar problem.  
I have installed tensorflow on Jetson Nano of Nvidia. The installation went well but when I load a tensorflow model stored on hdf5 file, I’m getting this error:

2021-10-10 16:39:06.985798: 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 “benchmarkObjectDetection.py”, line 25, in   
nn\_loaded\_model = tf.keras.models.load\_model(filepath\_for\_model, compile = False) # IMPORTANT! the compile = False input is crucial for loading the model as the custom loss function is unknown in the compilation phase; we can only use the model for prediction this way.  
File “/usr/local/lib/python3.6/dist-packages/tensorflow/python/util/lazy\_loader.py”, line 62, in **getattr**  
module = self.\_load()  
File “/usr/local/lib/python3.6/dist-packages/tensorflow/python/util/lazy\_loader.py”, line 45, in \_load  
module = importlib.import\_module(self. **name** )  
File “/usr/lib/python3.6/importlib/ **init**.py”, line 126, in import\_module  
return \_bootstrap.\_gcd\_import(name[level:], package, level)  
File “”, line 994, in \_gcd\_import  
File “”, line 971, in \_find\_and\_load  
File “”, line 941, in \_find\_and\_load\_unlocked  
File “”, line 219, in \_call\_with\_frames\_removed  
File “”, line 994, in \_gcd\_import  
File “”, line 971, in \_find\_and\_load  
File “”, line 941, in \_find\_and\_load\_unlocked  
File “”, line 219, in \_call\_with\_frames\_removed  
File “”, line 994, in \_gcd\_import  
File “”, line 971, in \_find\_and\_load  
File “”, line 941, in \_find\_and\_load\_unlocked  
File “”, line 219, in \_call\_with\_frames\_removed  
File “”, line 994, in \_gcd\_import  
File “”, line 971, in \_find\_and\_load  
File “”, line 955, in \_find\_and\_load\_unlocked  
File “”, line 665, in \_load\_unlocked  
File “”, line 678, in exec\_module  
File “”, line 219, in \_call\_with\_frames\_removed  
File “/usr/local/lib/python3.6/dist-packages/keras/ **init**.py”, line 25, in   
from keras import models  
File “/usr/local/lib/python3.6/dist-packages/keras/models.py”, line 20, in   
from keras import metrics as metrics\_module  
File “/usr/local/lib/python3.6/dist-packages/keras/metrics.py”, line 26, in   
from keras import activations  
File “/usr/local/lib/python3.6/dist-packages/keras/activations.py”, line 20, in   
from keras.layers import advanced\_activations  
File “/usr/local/lib/python3.6/dist-packages/keras/layers/ **init**.py”, line 23, in   
from keras.engine.input\_layer import Input  
File “/usr/local/lib/python3.6/dist-packages/keras/engine/input\_layer.py”, line 21, in   
from keras.engine import base\_layer  
File “/usr/local/lib/python3.6/dist-packages/keras/engine/base\_layer.py”, line 43, in   
from keras.mixed\_precision import loss\_scale\_optimizer  
File “/usr/local/lib/python3.6/dist-packages/keras/mixed\_precision/loss\_scale\_optimizer.py”, line 18, in   
from keras import optimizers  
File “/usr/local/lib/python3.6/dist-packages/keras/optimizers.py”, line 26, in   
from keras.optimizer\_v2 import adadelta as adadelta\_v2  
File “/usr/local/lib/python3.6/dist-packages/keras/optimizer\_v2/adadelta.py”, line 22, in   
from keras.optimizer\_v2 import optimizer\_v2  
File “/usr/local/lib/python3.6/dist-packages/keras/optimizer\_v2/optimizer\_v2.py”, line 37, in   
“/tensorflow/api/keras/optimizers”, “keras optimizer usage”, “method”)  
File “/usr/local/lib/python3.6/dist-packages/tensorflow/python/eager/monitoring.py”, line 361, in **init**  
len(labels), name, description, \*labels)  
File “/usr/local/lib/python3.6/dist-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.

I would appreciate very much any help on this problem.  
Thanks!

---

<div class="post-metadata">

**Author:** ![Bhack](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/bhack/32/6388_2.png) [@Bhack](https://discuss.ai.google.dev/u/Bhack)\
**Post date:** [October 11, 2021, 10:57am UTC](https://discuss.ai.google.dev/t/cannot-register-2-metrics-with-the-same-name-tensorflow-api-keras-optimizers/28519/8 "2021-10-11T10:57:42Z")

</div>

Can list with `pip` what TensorFlow and Keras versions you have installed?

---

<div class="post-metadata">

**Author:** ![Avner\_Safrani](https://avatars.discourse-cdn.com/v4/letter/a/f04885/32.png) [@Avner\_Safrani](https://discuss.ai.google.dev/u/Avner_Safrani)\
**Post date:** [October 12, 2021, 7:36am UTC](https://discuss.ai.google.dev/t/cannot-register-2-metrics-with-the-same-name-tensorflow-api-keras-optimizers/28519/10 "2021-10-12T07:36:36Z")

</div>

Thank you very much Bhack!  
This is what I get:

Name: tensorflow  
Version: 2.6.0+nv21.9

Name: keras  
Version: 2.7.0rc0

Thank you!  
Avner

---

<div class="post-metadata">

**Author:** ![Bhack](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/bhack/32/6388_2.png) [@Bhack](https://discuss.ai.google.dev/u/Bhack)\
**Post date:** [October 12, 2021, 1:08pm UTC](https://discuss.ai.google.dev/t/cannot-register-2-metrics-with-the-same-name-tensorflow-api-keras-optimizers/28519/12 "2021-10-12T13:08:10Z")

</div>

Can you try to install and test It in a `venv`:

> **[Install TensorFlow with pip](https://www.tensorflow.org/install/pip#2.-create-a-virtual-environment-recommended)**

---

<div class="post-metadata">

**Author:** ![Avner\_Safrani](https://avatars.discourse-cdn.com/v4/letter/a/f04885/32.png) [@Avner\_Safrani](https://discuss.ai.google.dev/u/Avner_Safrani)\
**Post date:** [October 12, 2021, 3:18pm UTC](https://discuss.ai.google.dev/t/cannot-register-2-metrics-with-the-same-name-tensorflow-api-keras-optimizers/28519/14 "2021-10-12T15:18:26Z")

</div>

Hi,  
Can you please explain what you think is the problem and why the installation within a venv should help? It is just that I have installed tensorflow as per the instruction on Nvidia site for Jetsons…and I’m not sure how the installation in venv will affect the performance. BTW, when I run a simple tensorflow calculation, the code runs with no issue.  
Thanks.

---

<div class="post-metadata">

**Author:** ![Bhack](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/bhack/32/6388_2.png) [@Bhack](https://discuss.ai.google.dev/u/Bhack)\
**Post date:** [October 12, 2021, 3:23pm UTC](https://discuss.ai.google.dev/t/cannot-register-2-metrics-with-the-same-name-tensorflow-api-keras-optimizers/28519/15 "2021-10-12T15:23:16Z")

</div>

It just to check that the env Is clean.

E.g. see TF 2.6 with Keras 2.7rc0

---

<div class="post-metadata">

**Author:** ![Avner\_Safrani](https://avatars.discourse-cdn.com/v4/letter/a/f04885/32.png) [@Avner\_Safrani](https://discuss.ai.google.dev/u/Avner_Safrani)\
**Post date:** [October 14, 2021, 2:03pm UTC](https://discuss.ai.google.dev/t/cannot-register-2-metrics-with-the-same-name-tensorflow-api-keras-optimizers/28519/17 "2021-10-14T14:03:59Z")

</div>

Hi,  
I followed the instruction on the link you sent me. After setting up the venv I’m trying to install tensroflow using pip but I’m getting the following message:

avner@avner-desktop:~$ source ./venv/bin/activate  
(venv) avner@avner-desktop:~$ pip install tensorflow  
ERROR: Could not find a version that satisfies the requirement tensorflow from versions: none)  
ERROR: No matching distribution found for tensorflow

I also tried to specify versions of tensorflow but was not successful.  
Any suggestions? I’m running on Jetson with ubunto 18.04.

Thanks.

---

<div class="post-metadata">

**Author:** ![Bhack](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/bhack/32/6388_2.png) [@Bhack](https://discuss.ai.google.dev/u/Bhack)\
**Post date:** [October 14, 2021, 4:16pm UTC](https://discuss.ai.google.dev/t/cannot-register-2-metrics-with-the-same-name-tensorflow-api-keras-optimizers/28519/18 "2021-10-14T16:16:55Z")

</div>

Jest but the venv you need to follow the Jetson steps `Set up the Virtual Environment`:

> **[Installing TensorFlow for Jetson Platform - NVIDIA Docs](https://docs.nvidia.com/deeplearning/frameworks/install-tf-jetson-platform/index.html#install_multiple_versions_tensorflow)**
>
> This guide provides instructions for installing TensorFlow for Jetson Platform.

---

<div class="post-metadata">

**Author:** ![Avner\_Safrani](https://avatars.discourse-cdn.com/v4/letter/a/f04885/32.png) [@Avner\_Safrani](https://discuss.ai.google.dev/u/Avner_Safrani)\
**Post date:** [October 17, 2021, 9:03am UTC](https://discuss.ai.google.dev/t/cannot-register-2-metrics-with-the-same-name-tensorflow-api-keras-optimizers/28519/19 "2021-10-17T09:03:48Z")

</div>

Thanks Bhack.  
The virtual environment doesn’t help. However, I reinstalled tensorflow with different version 2.5.0 (instead of 2.6.0) and with Nvidia TensorFlow container 21.07 and it works great!

Instead of using (doesn’t work for me, by default installing tf 2.6.0 version and no container):  
“sudo pip3 install --pre --extra-index-url [Index of /compute/redist/jp/v46](https://developer.download.nvidia.com/compute/redist/jp/v46) tensorflow”

I used (runs excellent):

“sudo pip3 install --extra-index-url [Index of /compute/redist/jp/v46](https://developer.download.nvidia.com/compute/redist/jp/v46) tensorflow==2.5.0+nv21.07”

Thanks a lot for you help!

---

<div class="post-metadata">

**Author:** ![Bhack](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/bhack/32/6388_2.png) [@Bhack](https://discuss.ai.google.dev/u/Bhack)\
**Post date:** [October 17, 2021, 2:27pm UTC](https://discuss.ai.google.dev/t/cannot-register-2-metrics-with-the-same-name-tensorflow-api-keras-optimizers/28519/20 "2021-10-17T14:27:44Z")

</div>

Cause you need to always check the `NVIDIA TensorFlow Container Versions ` e.g. if you check for TF 2.6.0 the minimum required is 21.09:

> **[TensorFlow Release 21.09 - NVIDIA Docs](https://docs.nvidia.com/deeplearning/frameworks/tensorflow-release-notes/rel_21-09.html#rel_21-09)**
>
> NVIDIA Optimized Frameworks such as Kaldi, NVIDIA Optimized Deep Learning Framework (powered by Apache MXNet), NVCaffe, PyTorch, and TensorFlow (which includes DLProf and TF-TRT) offer flexibility with designing and training custom (DNNs for machine...

---

<div class="post-metadata">

**Author:** ![Avner\_Safrani](https://avatars.discourse-cdn.com/v4/letter/a/f04885/32.png) [@Avner\_Safrani](https://discuss.ai.google.dev/u/Avner_Safrani)\
**Post date:** [October 17, 2021, 2:29pm UTC](https://discuss.ai.google.dev/t/cannot-register-2-metrics-with-the-same-name-tensorflow-api-keras-optimizers/28519/21 "2021-10-17T14:29:55Z")

</div>

Correct. However, the installation without the container is not working for me.  
Thanks.

---

<div class="post-metadata">

**Author:** ![Bhack](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/bhack/32/6388_2.png) [@Bhack](https://discuss.ai.google.dev/u/Bhack)\
**Post date:** [October 17, 2021, 2:32pm UTC](https://discuss.ai.google.dev/t/cannot-register-2-metrics-with-the-same-name-tensorflow-api-keras-optimizers/28519/22 "2021-10-17T14:32:50Z")

</div>

Without container you need to double check yourself the required python, CUDA, cudnn versions etc. for the specific TF version.
