Error Importing Tensorflow "alreadyexistserror: Another Metric With The Same Name Already Exists."
Solution 1:
TL;DR: Ensure the Keras version matches the Tensorflow version
I am experiencing the same thing with:
- Windows
- Python3.8
- Tensorflow-2.6.1
The core issue appears to be that there are two Keras packages installed:
<site-packages>/keras
<site-packages/tensorflow/python/keras
If you look at the release notes for 2.6: https://github.com/tensorflow/tensorflow/releases/tag/v2.6.0
Keras been split into a separate PIP package (keras), and its code has been moved to the GitHub repositorykeras-team/keras. The API endpoints for tf.keras stay unchanged, but are now backed by the keras PIP package. The existing code in tensorflow/python/keras is a staled copy and will be removed in future release (2.7). Please remove any imports to tensorflow.python.keras and replace them with public tf.keras API instead.
For some reason, it is still importing from both packages which is triggering the valid exception (only one Keras instance should be imported)
Digging a bit further, it looks like Keras-2.7 was being installed, reverting to Keras-2.6 resolved the issue:
pip install keras==2.6.*
For some reason: https://github.com/tensorflow/tensorflow/blob/v2.6.1/tensorflow/tools/pip_package/setup.py#L106
Is not working, maybe a bug in PIP?
Solution 2:
Tensorflow constructs singletons as side effects during import. Importing twice results in the singletons being created again, which is not supported. Please never import twice.
Solution 3:
After some query, the issue should be related to the Keras package version of the problem. One solution, that I do not know why yet, but verified, is as follows: 1 --> uninstall the existing Keras package (the blogger is currently wrong version 2.7) by:
pip uninstall keras
2 --> install a specific version of the Keras package; I have installed version 2.6.0 with:
pip install keras==2.6.0
Solution 4:
I also experienced this error after mixing the installation of tensorflow dependencies with both pip and conda. I was unable to fix by uninstalling/reinstalling tensorflow via either pip or conda.
My fix was installing tensorflow (v2.6.0) in a new virtual environment via the latest version of pip.
Solution 5:
Solved!- I had same issue, and what I did is to delete my virtual environment and create new one, reinstall required libraries!
Post a Comment for "Error Importing Tensorflow "alreadyexistserror: Another Metric With The Same Name Already Exists.""