Another metric with the same name already exists - python-3.x

I have problem with this code:
from tensorflow.keras.models import Sequential
and got this errors:
Traceback (most recent call last):
File "K:\test.py", line 1, in <module>
from tensorflow.keras.models import Sequential
File "G:\Program Files\Python37\lib\site-packages\keras\api\_v2\keras\__init__.py", line 10, in <module>
from keras import __version__
File "G:\Program Files\Python37\lib\site-packages\keras\__init__.py", line 25, in <module>
from keras import models
File "G:\Program Files\Python37\lib\site-packages\keras\models.py", line 20, in <module>
from keras import metrics as metrics_module
File "G:\Program Files\Python37\lib\site-packages\keras\metrics.py", line 26, in <module>
from keras import activations
File "G:\Program Files\Python37\lib\site-packages\keras\activations.py", line 20, in <module>
from keras.layers import advanced_activations
File "G:\Program Files\Python37\lib\site-packages\keras\layers\__init__.py", line 23, in <module>
from keras.engine.input_layer import Input
File "G:\Program Files\Python37\lib\site-packages\keras\engine\input_layer.py", line 21, in <module>
from keras.engine import base_layer
File "G:\Program Files\Python37\lib\site-packages\keras\engine\base_layer.py", line 43, in <module>
from keras.mixed_precision import loss_scale_optimizer
File "G:\Program Files\Python37\lib\site-packages\keras\mixed_precision\loss_scale_optimizer.py", line 18, in <module>
from keras import optimizers
File "G:\Program Files\Python37\lib\site-packages\keras\optimizers.py", line 26, in <module>
from keras.optimizer_v2 import adadelta as adadelta_v2
File "G:\Program Files\Python37\lib\site-packages\keras\optimizer_v2\adadelta.py", line 22, in <module>
from keras.optimizer_v2 import optimizer_v2
File "G:\Program Files\Python37\lib\site-packages\keras\optimizer_v2\optimizer_v2.py", line 37, in <module>
"/tensorflow/api/keras/optimizers", "keras optimizer usage", "method")
File "G:\Program Files\Python37\lib\site-packages\tensorflow\python\eager\monitoring.py", line 361, in __init__
len(labels), name, description, *labels)
File "G:\Program Files\Python37\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
I have seen
this post
and didn't get the meaning of
never import twice

you can fix the problem by downgrading Keras version to 2.6.0,
Even you only installed TensorFlow, it installs Keras==2.7.1 as a partial dependency. Simply, this version difference causes the error.
In IPython Kernel or In an active environment,
pip install keras==2.6.0
In a deployment environment, like docker,
add keras==2.6.0 line at the last line in the requirements.txt.

Follow these three steps below:
pip uninstall tensorflow
delete all keras related files in PC directory:
\Anaconda3\Lib\site-packages
reinstall tensorflow
This has solved my problem.

Related

While trying to encode a pointcloud I keep getting the same errors. I have tried to changing my environment and updating Glibcxx version and yet

$ python vmuc.py compress /home2/kubra/JPEG/Stanford_Area_2.ply ../models/Geometry-only/Codec/0.00025/checkpoint_best_loss.pth.tar ../results/G0.00025
Traceback (most recent call last):
File "/home2/kubra/JPEG/JPEG_PCC_VM/jpeg-pleno-pc-vm-main/src/vmuc.py", line 13, in <module>
import loss_functions
File "/home2/kubra/JPEG/JPEG_PCC_VM/jpeg-pleno-pc-vm-main/src/loss_functions.py", line 3, in <module>
from sklearn.neighbors import NearestNeighbors
File "/home/kubra/anaconda3/envs/myenv/lib/python3.9/site-packages/sklearn/__init__.py", line 82, in <module>
from .base import clone
File "/home/kubra/anaconda3/envs/myenv/lib/python3.9/site-packages/sklearn/base.py", line 17, in <module>
from .utils import _IS_32BIT
File "/home/kubra/anaconda3/envs/myenv/lib/python3.9/site-packages/sklearn/utils/__init__.py", line 29, in <module>
from .fixes import parse_version, threadpool_info
File "/home/kubra/anaconda3/envs/myenv/lib/python3.9/site-packages/sklearn/utils/fixes.py", line 19, in <module>
import scipy.stats
File "/home/kubra/anaconda3/envs/myenv/lib/python3.9/site-packages/scipy/stats/__init__.py", line 467, in <module>
from ._stats_py import *
File "/home/kubra/anaconda3/envs/myenv/lib/python3.9/site-packages/scipy/stats/_stats_py.py", line 39, in <module>
from scipy.spatial.distance import cdist
File "/home/kubra/anaconda3/envs/myenv/lib/python3.9/site-packages/scipy/spatial/__init__.py", line 105, in <module>
from ._kdtree import *
File "/home/kubra/anaconda3/envs/myenv/lib/python3.9/site-packages/scipy/spatial/_kdtree.py", line 5, in <module>
from ._ckdtree import cKDTree, cKDTreeNode
ImportError: /lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.29' not found (required by /home/kubra/anaconda3/envs/myenv/lib/python3.9/site-packages/scipy/spatial/_ckdtree.cpython-39-x86_64-linux-gnu.so)``
I'm currently working on point clouds codec. I tried encoding a point cloud but I keep getting the same error:
"/lib/x86_64-linux-gnu/libstdc++.so.6: version \`GLIBCXX_3.4.29' not found (required by /home/kubra/anaconda3/envs/myenv/lib/python3.9/site-packages/scipy/spatial/\_ckdtree.cpython-39-x86_64-linux-gnu.so)"
It says, apparently the version of GLIBCXX is not found whatsoever.. I tried updating my libstdc, creating new env with updated packages etc but it didnt workk for me. I have no idea of why it doesn't work and what I need to do. Could anyone please tell me what should I do?

How to fix "ImportError: DLL load failed while importing _arpack: The specified procedure could not be found."?

After installing a fresh copy of Anaconda 3 for my windows 10 and running my code, I am receiving this error message and I am not sure why "scipy" modules are not imported correctly.
I need help to figure this out.
$ D:/Users/username/Anaconda3/python.exe d:/Users/username/Desktop/sol-tl/sol_357.py
Traceback (most recent call last):
File "d:\Users\username\Desktop\some_name\my_script.py", line 37, in <module>
from fluorescence.calculator import (electron_plotter, enter_computation_scheme, total_plotter)
File "d:\Users\username\Desktop\sol-tl\fluorescence\calculator.py", line 18, in <module>
from fluorescence.imports_module import (np, List, Tuple, Path, perf_counter, ode, odeint,
File "d:\Users\username\Desktop\sol-tl\fluorescence\imports_module.py", line 25, in <module>
from scipy.optimize import curve_fit
File "D:\Users\username\Anaconda3\lib\site-packages\scipy\optimize\__init__.py", line 400, in <module>
from .optimize import *
File "D:\Users\username\Anaconda3\lib\site-packages\scipy\optimize\optimize.py", line 36, in <module>
from ._numdiff import approx_derivative
File "D:\Users\username\Anaconda3\lib\site-packages\scipy\optimize\_numdiff.py", line 6, in <module>
from scipy.sparse.linalg import LinearOperator
File "D:\Users\username\Anaconda3\lib\site-packages\scipy\sparse\linalg\__init__.py", line 114, in <module>
from .eigen import *
File "D:\Users\username\Anaconda3\lib\site-packages\scipy\sparse\linalg\eigen\__init__.py", line 9, in <module>
from .arpack import *
File "D:\Users\username\Anaconda3\lib\site-packages\scipy\sparse\linalg\eigen\arpack\__init__.py", line 20, in <module>
from .arpack import *
File "D:\Users\username\Anaconda3\lib\site-packages\scipy\sparse\linalg\eigen\arpack\arpack.py", line 42, in <module>
from . import _arpack
ImportError: DLL load failed while importing _arpack: The specified procedure could not be found.
Thinking that the new release of Anaconda (3.9.12) is having issues with “Scipy” package, I removed the package from Conda and re-installed it using pip. Now, the code runs happily.

RuntimeError: module compiled against API version 0xe but this version of numpy is 0xd when importing sentence-transformers

I want to use sentence-transformers. To do this, I installed sentence-transformers as follows:
pip install sentence-transformers
Then, I did my import as follows:
from sentence_transformers import SentenceTransformer
Which resulted in the following error:
RuntimeError: module compiled against API version 0xe but this version of numpy is 0xd
The entire Traceback is:
Traceback (most recent call last):
File "<ipython-input-112-dbcd88385343>", line 1, in <module>
from sentence_transformers import SentenceTransformer
File "C:\Users\20200016\AppData\Roaming\Python\Python38\site-packages\sentence_transformers\__init__.py", line 3, in <module>
from .datasets import SentencesDataset, ParallelSentencesDataset
File "C:\Users\20200016\AppData\Roaming\Python\Python38\site-packages\sentence_transformers\datasets\__init__.py", line 3, in <module>
from .ParallelSentencesDataset import ParallelSentencesDataset
File "C:\Users\20200016\AppData\Roaming\Python\Python38\site-packages\sentence_transformers\datasets\ParallelSentencesDataset.py", line 4, in <module>
from .. import SentenceTransformer
File "C:\Users\20200016\AppData\Roaming\Python\Python38\site-packages\sentence_transformers\SentenceTransformer.py", line 27, in <module>
from .models import Transformer, Pooling, Dense
File "C:\Users\20200016\AppData\Roaming\Python\Python38\site-packages\sentence_transformers\models\__init__.py", line 1, in <module>
from .Transformer import Transformer
File "C:\Users\20200016\AppData\Roaming\Python\Python38\site-packages\sentence_transformers\models\Transformer.py", line 2, in <module>
from transformers import AutoModel, AutoTokenizer, AutoConfig
File "C:\Users\20200016\AppData\Roaming\Python\Python38\site-packages\transformers\file_utils.py", line 1985, in __getattr__
value = getattr(module, name)
File "C:\Users\20200016\AppData\Roaming\Python\Python38\site-packages\transformers\file_utils.py", line 1984, in __getattr__
module = self._get_module(self._class_to_module[name])
File "C:\Users\20200016\AppData\Roaming\Python\Python38\site-packages\transformers\file_utils.py", line 1993, in _get_module
return importlib.import_module("." + module_name, self.__name__)
File "C:\Users\20200016\Anaconda3\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "C:\Users\20200016\AppData\Roaming\Python\Python38\site-packages\transformers\models\auto\modeling_auto.py", line 24, in <module>
from ..albert.modeling_albert import (
File "C:\Users\20200016\AppData\Roaming\Python\Python38\site-packages\transformers\models\albert\modeling_albert.py", line 51, in <module>
from .configuration_albert import AlbertConfig
File "C:\Users\20200016\AppData\Roaming\Python\Python38\site-packages\transformers\models\albert\configuration_albert.py", line 21, in <module>
from ...onnx import OnnxConfig
File "C:\Users\20200016\AppData\Roaming\Python\Python38\site-packages\transformers\onnx\__init__.py", line 17, in <module>
from .convert import export, validate_model_outputs
File "C:\Users\20200016\AppData\Roaming\Python\Python38\site-packages\transformers\onnx\convert.py", line 23, in <module>
from .. import PreTrainedModel, PreTrainedTokenizer, TensorType, TFPreTrainedModel, is_torch_available
File "C:\Users\20200016\AppData\Roaming\Python\Python38\site-packages\transformers\file_utils.py", line 1984, in __getattr__
module = self._get_module(self._class_to_module[name])
File "C:\Users\20200016\AppData\Roaming\Python\Python38\site-packages\transformers\file_utils.py", line 1993, in _get_module
return importlib.import_module("." + module_name, self.__name__)
File "C:\Users\20200016\Anaconda3\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "C:\Users\20200016\AppData\Roaming\Python\Python38\site-packages\transformers\modeling_tf_utils.py", line 27, in <module>
import tensorflow as tf
File "C:\Users\20200016\Anaconda3\lib\site-packages\tensorflow\__init__.py", line 37, in <module>
from tensorflow.python.tools import module_util as _module_util
File "C:\Users\20200016\Anaconda3\lib\site-packages\tensorflow\python\__init__.py", line 37, in <module>
from tensorflow.python.eager import context
File "C:\Users\20200016\Anaconda3\lib\site-packages\tensorflow\python\eager\context.py", line 35, in <module>
from tensorflow.python.client import pywrap_tf_session
File "C:\Users\20200016\Anaconda3\lib\site-packages\tensorflow\python\client\pywrap_tf_session.py", line 19, in <module>
from tensorflow.python.client._pywrap_tf_session import *
ImportError: SystemError: <built-in method __contains__ of dict object at 0x0000021655B72740> returned a result with an error set
I have tried upgrading Numpy:
pip install numpy --upgrade
But this returns:
Requirement already up-to-date: numpy in c:\...\site-packages (1.22.2)
What goes wrong here? And how can I overcome this error?
I have had a similar problem, and in my case upgrading numpy solve it. I checked the requirements.txt for the sentencetransformer but they stated no specific version.
Additionally you can try to install the SentenceTransformer without the dependecies pip install --no-deps sentence-transformers and install them manually afterwards. By downloading the requirements.txt and install it via pip install -r requirements.txt. In this process you can also more easily see whether there are any conflicts with some packages, maybe the information will e.g., help you to figure out which exact numpy version is needed.

ImportError when I change the directory in cmd

I am trying to import sklearn using cmd, I am changing the directory to a folder where I saved previous python files, however, I can't import sklearn in that particular folder and this is what I get:
>>> import sklearn
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\VER\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\__init__.py", line 64, in <module>
from .base import clone
File "C:\Users\VER\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\base.py", line 14, in <module>
from .utils.fixes import signature
File "C:\Users\VER\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\utils\__init__.py", line 14, in <module>
from . import _joblib
File "C:\Users\VER\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\utils\_joblib.py", line 22, in <module>
from ..externals import joblib
File "C:\Users\VER\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\externals\joblib\__init__.py", line 119, in <module>
from .parallel import Parallel
File "C:\Users\VER\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\externals\joblib\parallel.py", line 28, in <module>
from ._parallel_backends import (FallbackToBackend, MultiprocessingBackend,
File "C:\Users\VER\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\externals\joblib\_parallel_backends.py", line 22, in <module>
from .executor import get_memmapping_executor
File "C:\Users\VER\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\externals\joblib\executor.py", line 14, in <module>
from .externals.loky.reusable_executor import get_reusable_executor
File "C:\Users\VER\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\externals\joblib\externals\loky\__init__.py", line 6, in <module>
from ._base import Executor, Future
File "C:\Users\VER\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\externals\joblib\externals\loky\_base.py", line 22, in <module>
from concurrent.futures import wait, as_completed
File "C:\Users\VER\AppData\Local\Programs\Python\Python36\lib\concurrent\futures\__init__.py", line 17, in <module>
from concurrent.futures.process import ProcessPoolExecutor
File "C:\Users\VER\AppData\Local\Programs\Python\Python36\lib\concurrent\futures\process.py", line 52, in <module>
from queue import Full
ImportError: cannot import name 'Full'
>>>
A file or folder is occupying a python file's namespace, for example, 'time.py'.
In this case, it is 'queue.py'
You need to remove it or you will not be able to import the module.
This is because python defaults to importing from the folder containing the program, and you must have a file overwriting 'queue.py' there.
I myself have experienced the error when attempting to import matplotlib into a file named 'copy', as a deep, deep dependency of matplotlib was named 'copy.py'

Error while importing load_model from keras.model

I am trying to import my keras model which I have saved as .h5 file. But the very first line of my import gives me error. This is the line which gives error
from keras.models import load_model
I checked all the dependencies and that is ok. I have Keras 2.2.4. Error that I am getting:
Using TensorFlow backend.
Traceback (most recent call last):
File "drive1.py", line 1, in <module>
from keras.models import load_model
File "E:\python3.6.6\lib\site-packages\keras\__init__.py", line 3, in <module>
from . import utils
File "E:\python3.6.6\lib\site-packages\keras\utils\__init__.py", line 6, in <module>
from . import conv_utils
File "E:\python3.6.6\lib\site-packages\keras\utils\conv_utils.py", line 9, in <module>
from .. import backend as K
File "E:\python3.6.6\lib\site-packages\keras\backend\__init__.py", line 89, in <module>
from .tensorflow_backend import *
File "E:\python3.6.6\lib\site-packages\keras\backend\tensorflow_backend.py", line 5, in <module>
import tensorflow as tf
File "C:\Users\Dhruv\AppData\Roaming\Python\Python36\site-packages\tensorflow\__init__.py", line 24, in <module>
from tensorflow.python import * # pylint: disable=redefined-builtin
File "C:\Users\Dhruv\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\__init__.py", line 52, in <module>
from tensorflow.core.framework.graph_pb2 import *
File "C:\Users\Dhruv\AppData\Roaming\Python\Python36\site-packages\tensorflow\core\framework\graph_pb2.py", line 6, in <module>
from google.protobuf import descriptor as _descriptor
File "E:\python3.6.6\lib\site-packages\google\protobuf\__init__.py", line 37, in <module>
__import__('pkg_resources').declare_namespace(__name__)
File "E:\python3.6.6\lib\site-packages\pkg_resources.py", line 1479, in <module>
register_loader_type(importlib_bootstrap.SourceFileLoader, DefaultProvider)
AttributeError: module 'importlib._bootstrap' has no attribute 'SourceFileLoader'
I feel like there is some package versions mismatch but not sure what should I check further. I am using pip for installing packages.
Finally from some reference I found that there was some version mismatch between my python and pip. Actually I was should have focused on following error message:
__import__('pkg_resources').declare_namespace(__name__)
And the thing which helped was
python -m ensurepip --upgrade

Resources