Still loads previous version after upgrading latest version OpenCV 4.4.0 - opencv

I upgraded OpenCV 4.4.0 from OpenCV 4.2.x with pip command :
pip install --upgrade opencv-python==4.4.0.40
and checked the upgrade completed :
Collecting opencv-python==4.4.0.40
|████████████████████████████████| 33.5 MB 283 kB/s
Requirement already satisfied, skipping upgrade: numpy>=1.17.3 in c:\users\kangs\anaconda3\lib\site-packages (from opencv-python==4.4.0.40) (1.18.5)
Found existing installation: opencv-python 4.3.0.36
Successfully uninstalled opencv-python-4.3.0.36
PS C:\Users\kangs\Documents\TELPA\Source\numberplateRecognition> python
Python 3.8.3 (default, Jul 2 2020, 17:30:36) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'4.4.0'
>>> exit()
However, I still get this error message when I run this code :
cv2.dnn.readNet(WEIGHTS, CFG)
Error message :
Traceback (most recent call last):
File "c:\Users\kangs\Documents\TELPA\Source\numberplateRecognition\number_plate_v4c.py", line 54, in <module>
File "c:\Users\kangs\Documents\TELPA\Source\numberplateRecognition\algorithm\detection\yolodetector.py", line 39, in __init__
self.load_dir(dir_path)
File "c:\Users\kangs\Documents\TELPA\Source\numberplateRecognition\algorithm\detection\yolodetector.py", line 50, in load_dir
self.load_files(file_list)
File "c:\Users\kangs\Documents\TELPA\Source\numberplateRecognition\algorithm\detection\yolodetector.py", line 78, in load_files
self.net = cv2.dnn.readNet(WEIGHTS, CFG)
cv2.error: OpenCV(4.2.0) C:\projects\opencv-python\opencv\modules\dnn\src\darknet\darknet_io.cpp:686: error: (-212:Parsing error) Unsupported activation: mish in function 'cv::dnn::darknet::ReadDarknetFromCfgStream'
I found out that the code still linked to the previous library OpenCV 4.2.0.
Can someone please let me know why this happens and how to solve this problem?

Related

How to set up Raspberry Pi Buster and Intel NCS2 and OpenVINO with OpenCV trackers

Is there a definitive set of instructions to implement OpenCV trackers with OpenVINO and the now-obsolete NCS2 on a RPi 4b - Buster?
My understanding that the last OpenVINO to support the NCS2 was v2020.3.
I attempted to cross-compile using:
https://github.com/opencv/opencv/wiki/Intel-OpenVINO-backend#raspbian-buster
After installing opencv/opencv-contrib 4.5.5 from source:
$ python3
Python 3.7.3 (default, Oct 31 2022, 14:04:00)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'4.5.5'
>>> tracker = cv2.TrackerCSRT_create()
>>>
However, in a test.py script I have:
...
import cv2
net = cv2.dnn.readNetFromCaffe(_weights, _model)
net.setPreferableTarget(cv2.dnn.DNN_TARGET_MYRIAD)
...
detections = net.forward()
I get the error relating to DNN_TARGET_MYRIAD:
cv2.error: OpenCV(4.5.5) /home/pi/opencv/modules/dnn/src/dnn.cpp:1414: error: (-215:Assertion failed) preferableBackend != DNN_BACKEND_OPENCV || preferableTarget == DNN_TARGET_CPU || preferableTarget == DNN_TARGET_OPENCL || preferableTarget == DNN_TARGET_OPENCL_FP16 in function 'setUpNet'
I then used this to install OpenVINO:
https://docs.openvino.ai/latest/openvino_docs_install_guides_installing_openvino_raspbian.html
but using this version of OpenVINO (as the last to support the NCS2):
https://storage.openvinotoolkit.org/repositories/openvino/packages/2020.3/l_openvino_toolkit_runtime...
I exported the paths to the new post cross-compiled opencv_install directory:
$ export PYTHONPATH=/home/pi/Desktop/opencv_install/lib/python2.7/dist-packages/:$PYTHONPATH
$ export PYTHONPATH=/home/pi/Desktop/opencv_install/lib/python3.7/site-packages/:$PYTHONPATH
$ export LD_LIBRARY_PATH=/home/pi/Desktop/opencv_install/lib/:$LD_LIBRARY_PATH
I set up the NCS2 with no errors :
$ sudo usermod -a -G users "$(whoami)"
$ sh /opt/intel/openvino_2020.3/install_dependencies/install_NCS_udev_rules.sh
then:
$ source /opt/intel/openvino_2020.3/bin/setupvars.sh
and then checked:
$ python3
Python 3.7.3 (default, Oct 31 2022, 14:04:00)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'4.3.0-openvino-2020.3.0'
>>> tracker = cv2.TrackerCSRT_create()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'cv2' has no attribute 'TrackerCSRT_create'
>>>
If I open a new terminal and $ source /opt/intel/openvino_2020.3/bin/setupvars.sh
then run a test.py script:
...
import cv2
net = cv2.dnn.readNetFromCaffe(_weights, _model)
net.setPreferableTarget(cv2.dnn.DNN_TARGET_MYRIAD)
...
detections = net.forward()
...
I get a segmentation fault error.
So far I have not edited any of the setup scripts.
Thanks for any help! I'd like to put this NCS2 to work.
Generally, if you are able to run some OpenVINO demo with NCS2 after following this installation guide, then you should be able to use that OpenCV functionality (ensured that you had installed the correct OpenCV).
It's recommended to use the recent OpenVINO and OpenCV version.
As indicated in this OpenVINO System Requirements, the current recommended OpenCV version is 4.5.

snips-nlu not getting installed on docker

Issue:
I am installing snips in docker with step 1 given in To Reproduce section. I am ending with No module named 'distutils.msvccompiler' error. I am running everything on Linux based system. is there alternative way to install snips-nlu in docker?
To Reproduce
Created installSnips.sh (following) file for installing rust, rust setup tool
pip3 install numpy
pip3 install scipy
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
pip3 install setuptools-rust
source ~/.cargo/env
pip3 install snips-nlu
while running installSnips.sh pip3 install snip-nlu enter in following error
Building wheel for scikit-learn (setup.py) ... error
error: subprocess-exited-with-error
× python setup.py bdist_wheel did not run successfully.
│ exit code: 1
╰─> [26 lines of output]
Partial import of sklearn during the build process.
/tmp/pip-install-h9opcxf9/scikit-learn_fc42ebd0e5804549ad6f611dced79620/setup.py:123: DeprecationWarning:
`numpy.distutils` is deprecated since NumPy 1.23.0, as a result
of the deprecation of `distutils` itself. It will be removed for
Python >= 3.12. For older Python versions it will remain present.
It is recommended to use `setuptools < 60.0` for those Python versions.
For more details, see:
https://numpy.org/devdocs/reference/distutils_status_migration.html
from numpy.distutils.command.build_ext import build_ext # noqa
Traceback (most recent call last):
File "<string>", line 2, in <module>
File "<pip-setuptools-caller>", line 34, in <module>
File "/tmp/pip-install-h9opcxf9/scikit-learn_fc42ebd0e5804549ad6f611dced79620/setup.py", line 303, in <module>
setup_package()
File "/tmp/pip-install-h9opcxf9/scikit-learn_fc42ebd0e5804549ad6f611dced79620/setup.py", line 295, in setup_package
from numpy.distutils.core import setup
File "/home/drjslab/.local/lib/python3.10/site-packages/numpy/distutils/core.py", line 24, in <module>
from numpy.distutils.command import config, config_compiler, \
File "/home/drjslab/.local/lib/python3.10/site-packages/numpy/distutils/command/config.py", line 19, in <module>
from numpy.distutils.mingw32ccompiler import generate_manifest
File "/home/drjslab/.local/lib/python3.10/site-packages/numpy/distutils/mingw32ccompiler.py", line 28, in <module>
from distutils.msvccompiler import get_build_version as get_build_msvc_version
ModuleNotFoundError: No module named 'distutils.msvccompiler'
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for scikit-learn
Running setup.py clean for scikit-learn
Failed to build scikit-learn
Installing collected packages: requests, pyaml, packaging, scikit-learn, deprecation
Attempting uninstall: scikit-learn
Found existing installation: scikit-learn 1.1.2
Uninstalling scikit-learn-1.1.2:
Successfully uninstalled scikit-learn-1.1.2
Running setup.py install for scikit-learn ... error
error: subprocess-exited-with-error
× Running setup.py install for scikit-learn did not run successfully.
│ exit code: 1
╰─> [26 lines of output]
Partial import of sklearn during the build process.
/tmp/pip-install-h9opcxf9/scikit-learn_fc42ebd0e5804549ad6f611dced79620/setup.py:123: DeprecationWarning:
`numpy.distutils` is deprecated since NumPy 1.23.0, as a result
of the deprecation of `distutils` itself. It will be removed for
Python >= 3.12. For older Python versions it will remain present.
It is recommended to use `setuptools < 60.0` for those Python versions.
For more details, see:
https://numpy.org/devdocs/reference/distutils_status_migration.html
from numpy.distutils.command.build_ext import build_ext # noqa
Traceback (most recent call last):
File "<string>", line 2, in <module>
File "<pip-setuptools-caller>", line 34, in <module>
File "/tmp/pip-install-h9opcxf9/scikit-learn_fc42ebd0e5804549ad6f611dced79620/setup.py", line 303, in <module>
setup_package()
File "/tmp/pip-install-h9opcxf9/scikit-learn_fc42ebd0e5804549ad6f611dced79620/setup.py", line 295, in setup_package
from numpy.distutils.core import setup
File "/home/drjslab/.local/lib/python3.10/site-packages/numpy/distutils/core.py", line 24, in <module>
from numpy.distutils.command import config, config_compiler, \
File "/home/drjslab/.local/lib/python3.10/site-packages/numpy/distutils/command/config.py", line 19, in <module>
from numpy.distutils.mingw32ccompiler import generate_manifest
File "/home/drjslab/.local/lib/python3.10/site-packages/numpy/distutils/mingw32ccompiler.py", line 28, in <module>
from distutils.msvccompiler import get_build_version as get_build_msvc_version
ModuleNotFoundError: No module named 'distutils.msvccompiler'
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
Rolling back uninstall of scikit-learn
Moving to /home/drjslab/.local/lib/python3.10/site-packages/scikit_learn-1.1.2.dist-info/
from /home/drjslab/.local/lib/python3.10/site-packages/~cikit_learn-1.1.2.dist-info
Moving to /home/drjslab/.local/lib/python3.10/site-packages/scikit_learn.libs/
from /home/drjslab/.local/lib/python3.10/site-packages/~cikit_learn.libs
Moving to /home/drjslab/.local/lib/python3.10/site-packages/sklearn/
from /home/drjslab/.local/lib/python3.10/site-packages/~klearn
error: legacy-install-failure
× Encountered error while trying to install package.
╰─> scikit-learn
note: This is an issue with the package mentioned above, not pip.
Environment:
Base OS: Ubuntu 20.04
Base Python version: 3.8
snips-nlu version:Latest
Docker OS: Ubuntu 20.04
Docker Python: 3.10.4
It seems a recent update of setuptools broke numpy.distutils which is a dependency of scikit-learn.
https://github.com/pypa/setuptools/pull/3505
A reported possible solution is to install setuptools<65 with pip install --no-use-pep517

Issue installing OpenCV 4.1.2 on Jetson Nano. import cv2, No module named 'cv2'

I installed OpenCV 4.1.2 from source with CUDA support. Had no issues. and created a symbolic link from OpenCV’s installation directory to my virtualenv
ln -s /usr/local/lib/python3.6/site-packages/cv2/python3.6/cv2.cpython-36m-aarch64-linux-gnu.so cv2.so
I am having an issue with import cv2
$ python
Python 3.6.9 (default, Nov 7 2019, 10:44:02)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'cv2'
>>>
I checked site-packages directory and I can see cv2.so. I am obviously missing something.
The main issue here in my view I am not able to link to my virtualenv, in fact I am able to check my installation and its working
/usr/local/lib/python3.6/site-packages/cv2/python-3.6$ python
Python 3.6.9 (default, Nov 7 2019, 10:44:02)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>>
Issue solved a very very little mistake
I changed the name from
cv2.cpython-36m-aarch64-linux-gnu.so to cv2.so
I realized it was an issue with one of the folders, this will do the magic:
ln -s /usr/local/lib/python3.6/site-packages/cv2/python-3.6/cv2.so cv2.so
notice its python-3.6 not python3.6 after cv2

Error when running TensorFlow Federated on server

I am getting the following error when I try to load the Tensorflow Federated library on a server. I am using tensorflow_federated version 0.13.1
The Cuda version I have on the server is 10.2 . The Cudnn library is above 7.6.
What is the "libnvinfer.so.6" that is being asked?
2020-03-28 17:26:18.357394: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libnvinfer.so.6'; dlerror: libnvinfer.so.6: cannot open shared object file: No such file or directory
2020-03-28 17:26:18.410547: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libnvinfer_plugin.so.6'; dlerror: libnvinfer_plugin.so.6: cannot open shared object file: No such file or directory
2020-03-28 17:26:18.464258: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:30] Cannot dlopen some TensorRT libraries. If you would like to use Nvidia GPU with TensorRT, please make sure the missing libraries mentioned above are installed properly.
Traceback (most recent call last):
File "FedAvgREALWORLDWork.py", line 52, in <module>
import tensorflow_federated as tff
File "/user/env/lib/python3.5/site-packages/tensorflow_federated/__init__.py", line 61, in <module>
from tensorflow_federated.python import learning
File "/user/env/lib/python3.5/site-packages/tensorflow_federated/python/learning/__init__.py", line 17, in <module>
from tensorflow_federated.python.learning import framework
File "/user/env/lib/python3.5/site-packages/tensorflow_federated/python/learning/framework/__init__.py", line 20, in <module>
from tensorflow_federated.python.learning.framework.optimizer_utils import build_model_delta_optimizer_process
File "/user/env/lib/python3.5/site-packages/tensorflow_federated/python/learning/framework/optimizer_utils.py", line 176
f'({old_value.dtype}, {old_value.shape}) != '
^
SyntaxError: invalid syntax
I think that you have some librares are missing "libvinfer", for example to continue install cuda 10.1 you must install these packages
# Install TensorRT. Requires that libcudnn7 is installed above.
sudo apt-get install -y --no-install-recommends \
libnvinfer6=6.0.1-1+cuda10.1 \
libnvinfer-dev=6.0.1-1+cuda10.1 \
libnvinfer-plugin6=6.0.1-1+cuda10.1
I suggest that you See this : https://www.tensorflow.org/install/gpu
I hope that help you

install KIVY for python

I have an error when I run this:
pip install kivy
Here is the error:
Collecting kivy
Using cached Kivy-1.10.0.tar.gz
Complete output from command python setup.py egg_info:
Using distutils
Cython is missing, it's required for compiling kivy !
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-aHd9E8/kivy/setup.py", line 219, in <module>
from Cython.Distutils import build_ext
ImportError: No module named Cython.Distutils
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-aHd9E8/kivy/
So could someone help me to install this python library (for python 2.7 if possible) please, I made my researches and I did not find anything.
Install these:
brew install pkg-config sdl2 sdl2_image sdl2_ttf sdl2_mixer gstreamer
xcode-select --install
pip install Cython==0.26.1 --user
pip install https://github.com/kivy/kivy/archive/master.zip
You should be able to use kivy on MacOSX high sierra
theecodedragon$ python
Python 2.7.10 (default, Jul 15 2017, 17:16:57)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import kivy
[WARNING] [Config ] Older configuration version detected (0 instead of 20)
[WARNING] [Config ] Upgrading configuration in progress.
[INFO ] [Logger ] Record log in /Users/theecodedragon/.kivy/logs/kivy_17-11-09_0.txt
[INFO ] [Kivy ] v1.10.1.dev0, git-Unknown, 20171108
[INFO ] [Python ] v2.7.10 (default, Jul 15 2017, 17:16:57)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)]
>>>
Edit:
This works with latest version as of now:
theecodedragon$ sw_vers
ProductName: Mac OS X
ProductVersion: 10.13.1
BuildVersion: 17B48
Try installing Cython:
pip install Cython.
If it doesn't help, you may be using the wrong python installation. Refer to this answer for details.

Resources