ModuleNotFoundError: No module named 'official.modeling.optimization' - tensorflow

Please give solution on the following error. The tricky part is that the verification and testing is running "OK" but when I run command for training it throws following error.
The system details are as follows
Win10 - python 3.7.6
cuda 10.1 cudnn - 7.6.5
opencv - 4.5.1.48
tensorflow / tensorflow-gpu ==2.2.0
object_detection-0.1
protoc - 3.17.3
tf-models-official
tensorflow-model-optimization
Paths are already created
(Working on jupyter notebook on TFOD-API)
Traceback (most recent call last): File
"Tensorflow\models\research\object_detection\model_main_tf2.py", line
32, in
from object_detection import model_lib_v2 File "D:\Code_kida\ANPR\Tensorflow\models\research\object_detection\model_lib_v2.py",
line 31, in
from object_detection import model_lib File "D:\Code_kida\ANPR\Tensorflow\models\research\object_detection\model_lib.py",
line 34, in
from object_detection.builders import optimizer_builder File "D:\Code_kida\ANPR\Tensorflow\models\research\object_detection\builders\optimizer_builder.py",
line 25, in
from official.modeling.optimization import ema_optimizer ModuleNotFoundError: No module named 'official.modeling.optimization'

Make sure that the folder "D:\Code_kida\ANPR\Tensorflow\models\official" is exist and it has "modeling/optimization/ema_optimizer.py" inside.
I had the same error and that was the fix for me. might work for you too. or whoever comes here in the future

Related

Conda with Python3.9 using numpy in Python3.10

I'm trying to install statsmodels in Oracle Machine Learning in Conda enviroment.
My conda version is:
%conda
info
active environment : None
shell level : 0
user config file : /u01/.condarc
populated config files : /usr/share/conda/condarc.d/defaults.yaml
/u01/.condarc
conda version : 4.6.14
conda-build version : not installed
python version : 3.6.8.final.0
base environment : /usr (read only)
channel URLs : https://repo.anaconda.com/pkgs/main/linux-64
https://repo.anaconda.com/pkgs/main/noarch
https://repo.anaconda.com/pkgs/free/linux-64
https://repo.anaconda.com/pkgs/free/noarch
https://repo.anaconda.com/pkgs/r/linux-64
https://repo.anaconda.com/pkgs/r/noarch
package cache : /u01/.conda/pkgs
/var/cache/conda/pkgs
envs directories : /u01/.conda/envs
/usr/envs
platform : linux-64
user-agent : conda/4.6.14 requests/2.27.1 CPython/3.6.8 Linux/5.4.17-2136.314.6.3.el7uek.x86_64 oracle/7.9 glibc/2.17
UID:GID : 65000:65000
netrc file : None
offline mode : False
I created the conda enviroment with the next command:
%conda
create -n arima_enviroment python=3.9 xz sqlite libuuid statsmodels numpy
I activated the enviroment with:
%conda
activate arima_enviroment
Test the enviroment with:
%python
import sys
import platform
print("sys.version:", sys.version)
print("sys.version_info:", sys.version_info)
print("platform.python_version:", platform.python_version())
sys.version: 3.9.12 (main, Jun 1 2022, 11:38:51) [GCC 7.5.0]
sys.version_info: sys.version_info(major=3, minor=9, micro=12, releaselevel='final', serial=0)
platform.python_version: 3.9.12
Then I execute the next command for import the ARIMA model.
%python
from statsmodels.tsa.arima_model import arima
But give me the next error:
Fail to execute line 2: from statsmodels.tsa.arima_model import arima
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/numpy/core/__init__.py", line 23, in <module>
from . import multiarray
File "/usr/local/lib/python3.10/site-packages/numpy/core/multiarray.py", line 10, in <module>
from . import overrides
File "/usr/local/lib/python3.10/site-packages/numpy/core/overrides.py", line 6, in <module>
from numpy.core._multiarray_umath import (
ModuleNotFoundError: No module named 'numpy.core._multiarray_umath'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/tmp/1675189382222-0/zeppelin_python.py", line 206, in <module>
exec(code, _zcUserQueryNameSpace)
File "<stdin>", line 2, in <module>
File "/u01/.conda/active_env/lib/python3.9/site-packages/statsmodels/tsa/__init__.py", line 1, in <module>
from statsmodels.tools._testing import PytestTester
File "/u01/.conda/active_env/lib/python3.9/site-packages/statsmodels/tools/__init__.py", line 1, in <module>
from .tools import add_constant, categorical
File "/u01/.conda/active_env/lib/python3.9/site-packages/statsmodels/tools/tools.py", line 4, in <module>
import numpy as np
File "/usr/local/lib/python3.10/site-packages/numpy/__init__.py", line 144, in <module>
from . import core
File "/usr/local/lib/python3.10/site-packages/numpy/core/__init__.py", line 49, in <module>
raise ImportError(msg)
ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.
We have compiled some common reasons and troubleshooting tips at:
https://numpy.org/devdocs/user/troubleshooting-importerror.html
Please note and check the following:
* The Python version is: Python3.9 from "/u01/.conda/active_env/bin/python3"
* The NumPy version is: "1.22.1"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: No module named 'numpy.core._multiarray_umath'
Why conda is using Numpy in Python 3.10 folder and not the Numpy version installed in Python 3.9? How can repair it?

No module named 'tensorflow_datasets.image.cityscapes'

I installed TensorFlow Datasets using conda, as:
conda install -c anaconda tensorflow-datasets
I've tried importing Cityscapes:
from tensorflow_datasets.image.cityscapes import Cityscapes
but this raises the following error:
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
ModuleNotFoundError: No module named 'tensorflow_datasets.image.cityscapes'
How can I fix it?
PS: I can import the following without errors:
import tensorflow_datasets as tfds
Edit:
I've already downloaded Cityscapes data, as recommended in the official guide.

"ImportError: DLL load failed: The specified module could not be found" when trying to import gensim

While trying to import gensim, I run into the following error
Traceback (most recent call last):
File "c:\Users\usr\Documents\hello\test.py", line 3, in <module>
import gensim
File "C:\Users\usr\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\gensim\__init__.py", line 5, in <module>
from gensim import parsing, corpora, matutils, interfaces, models, similarities, summarization, utils # noqa:F401
File "C:\Users\usr\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\gensim\corpora\__init__.py", line 6, in <module>
from .indexedcorpus import IndexedCorpus # noqa:F401 must appear before the other classes
File "C:\Users\usr\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\gensim\corpora\indexedcorpus.py", line 15, in <module>
from gensim import interfaces, utils
File "C:\Users\usr\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\gensim\interfaces.py", line 21, in <module>
from gensim import utils, matutils
File "C:\Users\usr\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\gensim\matutils.py", line 21, in <module>
from scipy.stats import entropy
File "C:\Users\usr\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\scipy\stats\__init__.py", line 384, in <module>
from .stats import *
File "C:\Users\usr\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\scipy\stats\stats.py", line 179, in <module>
from scipy.spatial.distance import cdist
File "C:\Users\usr\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\scipy\spatial\__init__.py", line 99, in <module>
from .qhull import *
ImportError: DLL load failed: The specified module could not be found.
I have tried uninstalling numpy, scipy and gensim using pip in the command prompt and installing them again, but this does not resolve the issue.
I have also looked at the suggestions to a similar problem here, and tried installing numpy‑1.19.0+mkl‑cp37‑cp37m‑win_amd64.whl, but it resulted in a separate error Importing the numpy c-extensions failed. Thus, I have stuck to using numpy, scipy and gensim installed via pip.
Additionally, I installed scipy version 1.4.1 as the latest 1.5.0 version will give the following error as described in this link:
Error when loading scipy: OSError: [WinError 126] The specified module could not be found
Any help is greatly appreciated!
For additional information, I am using Python 3.7 and Windows 10.
I had the same problem and tried various things, but the only thing that worked for me was to install an older version of Gensim.
pip install gensim==3.7.0

Could not find 'cudart64_100.dll' while trying to install tensorflow

I am trying to install tensorflow.
I have installed Cuda10.0 and cudnn, but I still get this error:
Traceback (most recent call last):
File "D:\python\lib\site-packages\tensorflow\python\platform\self_check.py", line 75, in preload_check
ctypes.WinDLL(build_info.cudart_dll_name)
File "D:\python\lib\ctypes\__init__.py", line 364, in __init__
self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] 找不到指定的模块。
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:/Python_test/Python算法成品/机器学习/test/test.py", line 4, in <module>
import tensorflow as tf
File "D:\python\lib\site-packages\tensorflow\__init__.py", line 40, in <module>
from tensorflow.python.tools import module_util as _module_util
File "D:\python\lib\site-packages\tensorflow\python\__init__.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow
File "D:\python\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 30, in <module>
self_check.preload_check()
File "D:\python\lib\site-packages\tensorflow\python\platform\self_check.py", line 82, in preload_check
% (build_info.cudart_dll_name, build_info.cuda_version_number))
ImportError: Could not find 'cudart64_100.dll'. TensorFlow requires that this DLL be installed in a directory that is named in your %PATH% environment variable. Download and install CUDA 10.0 from this URL: `enter code here`https://developer.nvidia.com/cuda-90-download-archive
What am I missing or doing wrong?
To fix the issue, either: Install CUDA from September 2018, which comes with cudart64_100.dll and other 32 bit *100.dlls and 64 bit *100 libraries.
Or, if you want future support:
Install the latest NVIDIA GPU Computing Toolkit.
However, because the newest version of the CUDA library is cudart64_101.dll and TensorFlow 2.0 requires the older cudart64_100.dll, also install the CUDA from September 2018.
Then copy cudart64_100.dll library from the old install of CUDA to the new one.
Or just download the library from the file attached further below and copy it into your last CUDA installation directory in program files.
For more details please refer here

ModuleNotFoundError: No module named 'nets'

Hi guys I'm having an error when I'm trying to run the training using this command:
> `python train.py --logtostderr --train_dir=training/
> --pipeline_config_path=training/ssd_mobilenet_v1_coco.config`
Traceback (most recent call last): File "train.py", line 51, in
<module> from object_detection.builders import model_builder File
"C:\tensorflow1\models\research\object_detection\builders\model_builder.py",
line 35, in <module> from object_detection.models import
faster_rcnn_inception_resnet_v2_feature_extractor as frcnn_inc_res
File
"C:\tensorflow1\models\research\object_detection\models \faster_rcnn_inception_resnet_v2_feature_extractor.py",
line 28, in <module> from nets import inception_resnet_v2
ModuleNotFoundError: No module named 'nets
The nets module is in slim folder, you need to add the slim library to PYTHONPATH:
# From tensorflow/models/research/
export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim
Try Installing pip install nets and also check the site package and environment package for installed folders (It worked for me)