Error importing model_builder from object_detection.builders - TF and Keras - keras

this line is suddenly causing an error, it worked recently. It's a colab notebook written by someone else, so not sure where to start.
!pip install -U --pre tensorflow=="2.9.1"
# uncomment the next line if you want to delete an existing models directory
#!rm -rf ./models/
# clone the Tensorflow Model Garden
!git clone --depth 1 https://github.com/tensorflow/models.git
# install the Object Detection API
!cd models/research/ && protoc object_detection/protos/\*.proto --python_out=. && cp object_detection/packages/tf2/setup.py . && python -m pip install .
# import module for building the detection model
from object_detection.builders import model_builder\`
Error:
AttributeError Traceback (most recent call last)
\<ipython-input-11-5796d1f2862b\> in \<module\>
11
12 # import module for building the detection model
\---\> 13 from object_detection.builders import model_builder
14
15 # import module for utilities in Colab
11 frames
/usr/local/lib/python3.8/dist-packages/keras/saving/legacy/saved_model/load_context.py in \<module\>
66
67
\---\> 68 tf.__internal__.register_load_context_function(in_load_context)
AttributeError: module 'tensorflow.compat.v2.__internal__' has no attribute 'register_load_context_function'
Using Google Colab
TF version = 2.9.1
Any help appreciated!
Tried uninstalling keras

Related

ModuleNotFoundError: No module named 'pycocotools._mask'

I'm trying to train Mask-R CNN model from cocoapi(https://github.com/cocodataset/cocoapi), and this error code keep come out.
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-8-83356bb9cf95> in <module>
19 sys.path.append(os.path.join(ROOT_DIR, "samples/coco/")) # To find local version
20
---> 21 from pycocotools.coco import coco
22
23 get_ipython().run_line_magic('matplotlib', 'inline ')
~/Desktop/coco/PythonAPI/pycocotools/coco.py in <module>
53 import copy
54 import itertools
---> 55 from . import mask as maskUtils
56 import os
57 from collections import defaultdict
~/Desktop/coco/PythonAPI/pycocotools/mask.py in <module>
1 __author__ = 'tsungyi'
2
----> 3 import pycocotools._mask as _mask
4
5 # Interface for manipulating masks stored in RLE format.
ModuleNotFoundError: No module named 'pycocotools._mask'
I tried all the methods on the github 'issues' tab, but it is not working to me at all. Is there are another solution for this? I'm using Python 3.6, Linux.
The answer is summarise from these three GitHub issues
1.whether you have installed cython in the correct version. Namely, you should install cython for python2/3 if you use python2/3
pip install cython
2.whether you have downloaded the whole .zip file from this github project. Namely, you should download all the things here even though you only need PythonAPI
git clone https://github.com/cocodataset/cocoapi.git
or
unzip the zip file
3.whether you open Terminal and run "make" under the correct folder. The correct folder is the one that "Makefile" is located in
cd path/to/coco/PythonAPI/Makefile
make
Almost, the question can be solved.
If not, 4 and 5 may help.
4.whether you have already installed gcc in the correct version
5.whether you have already installed python-dev in the correct version. Namely you should install python3-dev (you may try "sudo apt-get install python3-dev"), if you use python3.
Try cloning official repo and run below commands
python setup.py install
make

while attempting to import module of sklearn in Jupiter notebook as well as in PYCHARM, i continuously get following error

i have installed scikit-learn using pip command, however while trying to import module of sklearn in Jupiter notebook as well as in PYCHARM, i continuously get following error. I am working in python3.9. I am new to the interface, so it is requested to suggest solution for this issue.
ImportError Traceback (most recent call last)
in
----> 1 import sklearn.linear_model as lm
/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/sklearn/init.py in
79 # it and importing it first would fail if the OpenMP dll cannot be found.
80 from . import _distributor_init # noqa: F401
---> 81 from . import __check_build # noqa: F401
82 from .base import clone
83 from .utils._show_versions import show_versions
/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/sklearn/__check_build/init.py in
44 from ._check_build import check_build # noqa
45 except ImportError as e:
---> 46 raise_build_error(e)
/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/sklearn/__check_build/init.py in raise_build_error(e)
29 else:
30 dir_content.append(filename + '\n')
---> 31 raise ImportError("""%s
32 ___________________________________________________________________________
33 Contents of %s:
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/sklearn/__check_build/_check_build.cpython-39-darwin.so, 2): Symbol not found: ____chkstk_darwin
Referenced from: /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/sklearn/__check_build/../.dylibs/libomp.dylib
Expected in: /usr/lib/libSystem.B.dylib
in /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/sklearn/__check_build/../.dylibs/libomp.dylib
Contents of /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/sklearn/__check_build:
init.py pycache _check_build.cpython-39-darwin.so
setup.py
It seems that scikit-learn has not been built correctly.
If you have installed scikit-learn from source, please do not forget
to build the package before using it: run python setup.py install or
make in the source directory.
If you have used an installer, please check that it is suited for your
Python version, your operating system and your platform
thanks
As you can see in this bug report, the new sklearn version 0.24 crashes on MacOS<10.15 systems.
Until this bug is fixed, the developers suggest installing the previous version using pip install -U scikit-learn==0.23.

Python 3.8: Error running different Python environments from base directory's Jupyter Notebook

I've recently had to do a reformat of my work computer, and am reinstalling Anaconda. I generally keep Anaconda's root (base) folder untouched, and create separate environments when I need to work with specialist Python modules instead of cluttering the (base) environment.
In the past, I was able to successfully run these different environments from the Jupyter Notebook installed in the (base) environment. I would go about doing so by installing ipykernel in the new environment (e.g. my-env), and then running the following commands:
(base) activate my-env
(my-env) conda install ipykernel
(my-env) python -m ipykernel install --name "my-env" --display-name "My Python"
This would be done successfully, and give me the following message:
Installed kernelspec my-env in C:\ProgramData\jupyter\kernels\my-env
However, when I tried testing out the link in Jupyter Notebook using a standard import matplotlib.pyplot as plt command, I get the following error message:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-a0d2faabd9e9> in <module>
----> 1 import matplotlib.pyplot as plt
C:\Anaconda3\envs\my-env\lib\site-packages\matplotlib\__init__.py in <module>
105 # cbook must import matplotlib only within function
106 # definitions, so it is safe to import from it here.
--> 107 from . import cbook, rcsetup
108 from matplotlib.cbook import MatplotlibDeprecationWarning, sanitize_sequence
109 from matplotlib.cbook import mplDeprecation # deprecated
C:\Anaconda3\envs\my-env\lib\site-packages\matplotlib\cbook\__init__.py in <module>
26 import weakref
27
---> 28 import numpy as np
29
30 import matplotlib
C:\Anaconda3\envs\my-env\lib\site-packages\numpy\__init__.py in <module>
141 from .core import *
142 from . import compat
--> 143 from . import lib
144 # NOTE: to be revisited following future namespace cleanup.
145 # See gh-14454 and gh-15672 for discussion.
C:\Anaconda3\envs\my-env\lib\site-packages\numpy\lib\__init__.py in <module>
23 # Private submodules
24 from .type_check import *
---> 25 from .index_tricks import *
26 from .function_base import *
27 from .nanfunctions import *
C:\Anaconda3\envs\my-env\lib\site-packages\numpy\lib\index_tricks.py in <module>
9 from numpy.core.numerictypes import find_common_type, issubdtype
10
---> 11 import numpy.matrixlib as matrixlib
12 from .function_base import diff
13 from numpy.core.multiarray import ravel_multi_index, unravel_index
C:\Anaconda3\envs\my-env\lib\site-packages\numpy\matrixlib\__init__.py in <module>
2
3 """
----> 4 from .defmatrix import *
5
6 __all__ = defmatrix.__all__
C:\Anaconda3\envs\my-env\lib\site-packages\numpy\matrixlib\defmatrix.py in <module>
9 # While not in __all__, matrix_power used to be defined here, so we import
10 # it for backward compatibility.
---> 11 from numpy.linalg import matrix_power
12
13
C:\Anaconda3\envs\my-env\lib\site-packages\numpy\linalg\__init__.py in <module>
71 """
72 # To get sub-modules
---> 73 from .linalg import *
74
75 from numpy._pytesttester import PytestTester
C:\Anaconda3\envs\my-env\lib\site-packages\numpy\linalg\linalg.py in <module>
31 from numpy.core import overrides
32 from numpy.lib.twodim_base import triu, eye
---> 33 from numpy.linalg import lapack_lite, _umath_linalg
34
35
ImportError: DLL load failed: The specified module could not be found.
Could someone advise me on what might be the issue? If it helps, my (base) environment has a python version of 3.8.3 and a notebook version of 6.0.3, whereas my new my-env environment has modules downloaded from conda-forge. It has a python version of 3.7.8 and an ipykernel version of 5.3.4.
Thanks in advance!
UPDATE 26 Oct 2020
As requested, I have included the list of modules I have in both the (base) environment and the (my-env) environment. In general, the packages in (base) have been kept updated with respect to the anaconda module, whereas the packages in (my-env) are kept up-to-date with respect to hyperspy, which is stored in the conda-forge repository.
I have created PasteBin entries for them, as they exceed the character limit for this post.
Link to list of modules in (base)
Link to list of modules in (my-env)
I also tried importing modules other than matplotlib and numpy, and was able to import abc and time without issue, for example. This seems to be an issue with the (base) version of Jupyter Notebook not being compatible with the numpy found in the (my-env) environment.
The error message is indicating the error is arising from the numpy library. The fact that your Python and Ipkernel versions are different between your (base) and your (my-env) is further indication that there is incompatibility between your environments.
Can you provide the output from
conda list
from each environment?
When I tried to create a Python=3.8.3 environment the numpy version installed is numpy-1.19.2-py38hf89b668_1
I used the command
conda create -n foo -c conda-forge python=3.8.3 numpy
When I tried to create a Python=3.7.8 environment the numpy version installed is numpy-1.19.2-py37h7008fea_1
I used the command
conda create -n foo -c conda-forge python=3.7.8 numpy
In addition, why don't you consider installing ipkernel / jupyter notebook libraries that are consistent with respective versions of Python in each environment? This would always be the best solution to ensure dependencies are correctly aligned.
I also attempted to install ipykernel in both python=3.8.3 and python=3.7.8 along with ipykernel without specifying version number.
Here are the versions of ipykernel that condaautomatically chooses:
for python=3.8.3: ipykernel-5.3.4 | py38h1cdfbd6_1
for python=3.7.8: ipykernel-5.3.4 | py37hc6149b9_1
From what you have written your ipykernel versions are different. I do think this discrepancy is most likely coming from these differences of ipykernel versions
When you check your environments, verify that the channel source for ipykernel is the same.
One Solution: Consider downgrading the ipykernel in (base) to 5.3.4 version.

ImportError: No module named 'sklearn.__check_build._check_build'

ModuleNotFoundError Traceback (most recent call last)
~\AppData\Roaming\Python\Python36\site-packages\sklearn\__check_build\__init__.py in <module>()
43 try:
---> 44 from ._check_build import check_build # noqa
45 except ImportError as e:
ModuleNotFoundError: No module named
'sklearn.__check_build._check_build'
During handling of the above exception, another exception occurred:
ImportError Traceback (most recent call last)
<ipython-input-1-f14d678f34eb> in <module>()
1 from keras.models import Sequential
2 from keras.layers import Dense, Dropout
----> 3 from sklearn.model_selection import train_test_split
4 import numpy
5 import pandas as pd
~\AppData\Roaming\Python\Python36\site-packages\sklearn\__init__.py in <module>()
61 # process, as it may not be compiled yet
62 else:
---> 63 from . import __check_build
64 from .base import clone
65 from .utils._show_versions import show_versions
~\AppData\Roaming\Python\Python36\site-packages\sklearn\__check_build\__init__.py in <module>()
44 from ._check_build import check_build # noqa
45 except ImportError as e:
---> 46 raise_build_error(e)
~\AppData\Roaming\Python\Python36\site-packages\sklearn\__check_build\__init__.py in raise_build_error(e)
39 to build the package before using it: run `python setup.py install` or
40 `make` in the source directory.
---> 41 %s""" % (e, local_dir, ''.join(dir_content).strip(), msg))
42
43 try:
ImportError: No module named 'sklearn.__check_build._check_build'
Contents of C:\Users\owaisaaa\AppData\Roaming\Python\Python36\site-packages\sklearn\__check_build:
setup.py _check_build.cp36-win32.pyd__init__.py
__pycache__
It seems that scikit-learn has not been built correctly.
If you have installed scikit-learn from source, please do not forget
to build the package before using it: run python setup.py install or
make in the source directory.
If you have used an installer, please check that it is suited for your
Python version, your operating system and your platform.
I recently used the pycharm on the same machine and downloaded the packages in it. From that moment onward I am getting the above mentioned error in my jupyter notebook.
Try installing scipy and restarting python shell
Upgrading scikit-learn worked for me:
$ pip install --upgrade scikit-learn

Error while uploading Networkit python module with Jupyter notebook

I installed the Networkit module with conda install -c vgauthier networkit. If I import it in a notebook (import networkit as nk) I get this error:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-2-a4c0096fb06c> in <module>()
----> 1 import networkit as nk
//anaconda/envs/py36/lib/python3.6/site-packages/networkit/__init__.py in <module>()
41 # local imports
42 from . import stopwatch
---> 43 from . import graph
44 from . import graphio
45 from . import community
//anaconda/envs/py36/lib/python3.6/site-packages/networkit/graph.py in <module>()
1 # extension imports
----> 2 from _NetworKit import Graph, SpanningForest, GraphTools, RandomMaximumSpanningForest, UnionMaximumSpanningForest
ImportError: dlopen(//anaconda/envs/py36/lib/python3.6/site-packages/_NetworKit.cpython-36m-darwin.so, 2): Library not loaded: #rpath/libomp.dylib
Referenced from: //anaconda/envs/py36/lib/python3.6/site-packages/_NetworKit.cpython-36m-darwin.so
Reason: image not found
Anyone able to explain why?
​
I happened to have the same problem for networkit via pip. It is because the networkit installed by anaconda does not link to your gcc compiler correctly, a simple fix is to download the networkit's source code and run python3 setup.py install to install it.
I had the same problem:
https://github.com/kit-parco/networkit/issues/172
It's because of anaconda Python. Re-install it using:
conda install -c vgauthier networkit
installing it with conda instead of pip solved the problem for me. See instructions here.

Resources