I'm trying to run some sample OpenCV3 Neural Network code in Python.
import cv2
model = cv2.ml.ANN_MLP()
model.load('mlp.xml')
But this gives me the error:
module 'cv2.ml' has no attribute 'ANN_MLP'
But, there is such a class in OpenCV3 release notes http://docs.opencv.org/3.2.0/d0/dce/classcv_1_1ml_1_1ANN__MLP.html
and the code above did work on somebody's system since it is given as sample code.
I'm using Anaconda on Windows 10, with python 3.5.3 and opencv3 3.1.0.
What is going on?
Is there something obvious I'm missing here?
Does the python version of OpenCV3 not have the wrapper?
Did OpenCV3 python have a wrapper once upon a time and was removed in the newer versions?
You are getting this error beause the python version of OpenCV (i.e.) 3.1 is missing the load wrapper. You can confirm this by checking the following in the python REPL - dir(cv2.ml)
This has been resolved in ver 3.2.0+
In order to create a model by loading the ANN_MLP weights you need to do the following -
model = cv2.ml.ANN_MLP_load(filename)
Related
I am trying to use scikit mobility to recreate trajectories and stop location from GPS https://scikit-mobility.github.io/scikit-mobility/reference/data_structures.html#module-skmob.core.trajectorydataframe
By using TrajDataFrame and then I am applying
stdf = detection.stay_locations(tdf, stop_radius_factor=0.5, minutes_for_a_stop=20.0, spatial_radius_km=0.2, leaving_time=True)
my data looks the same as in example but I am getting the error ''TrajDataFrame' object has no attribute '_crs''. CRS is just optional and even when I added the error is appearing. Does anyone had the same issue?
This problem has been solved in the current version (v1.3.1), which works for versions of python >= 3.8.
If you are using it in Google Colab (for which version 3.8 is not available yet), after having installed scikit-mobility, you need to downgrade the pandas library to version 1.2.5:
!pip install pandas==1.2.5
Then, the problem should be solved. See also this solved issue: https://github.com/scikit-mobility/scikit-mobility/issues/204
I want to switch from Mathematica to Python and MxNet to continue developing a Munsell color spec application based on a backpropagation/regression neural network. I'm new to Python and MxNet so I'm a bit lost in this universe. However, I'm experienced with neural networks, C++ and Mathematica.
I'm on Windows 10. I installed Python 3.8.1 and then MxNet. Then I wanted to follow MxNet tutorial "Manipulate data with ndarray". Entering the first command line "from mxnet import nd", I get the following error:
generator = lambda: [(yield self._batchify_fn([self._dataset[idx] for idx in batch]))
^
SyntaxError: 'yield' inside list comprehension
I found a StackOverflow question where an answer indicates that using yield in this context is now an error in 3.8 but was only a warning in 3.7.
Is there a quick fix for this or should I uninstall 3.8 and install 3.7?
unless you're prepared to put in a fix to MxNet yourself and submit a pull request, your best solution is to switch versions of python. 3.7 is still very recent and shouldn't give you any trouble with any other libraries you may use. I recommend you install 3.7, but keep 3.8 on your computer and use virtualenv to create custom library install environments for each... for example, I just found this link to take you through the steps...
https://www.freecodecamp.org/news/installing-multiple-python-versions-on-windows-using-virtualenv/
I personally use anaconda and environments through that, which actually has similar steps (using anaconda prompt) no matter which OS you are on. But this can all be done without anaconda and with virtualenv as above.
I am trying to run an image recognition code. Even after installing 'utils' I am still getting error that module not found. What should I change?
Check if your python version is compatible. According to docs it's up to python 3.4 and you seem to be using 3.6. Source - https://pypi.org/project/python3-utils/#data
I have downloaded the source code of Opencv3.4.1 from github and I have built it from the source using CMake. Everything went very well and it's installed!
But When I run this script: https://github.com/opencv/opencv/blob/master/samples/dnn/object_detection.py
I get the following error:
Traceback (most recent call last):
File "object_detection.py", line 52, in <module>
net = cv.dnn.readNet(args.model, args.config, args.framework)
AttributeError: module 'cv2.dnn' has no attribute 'readNet'
System information (version)
OpenCV => 3.4.1
Operating System / Platform => Windows 64 Bit
Python =>3.6
When I run print(cv.__version__) I get 3.4.1 But I can't find the that function or any other new features in the 3.4.1 version!
I have built from the source on Ubuntu 16.04 and on Windows 10. But still no luck! the source is downloaded from Github https://github.com/opencv/opencv/archive/3.4.1.zip
Does anyone has any tips?
Thanks to api55 for his suggestion!
I could solve the problem by downloading the source code from the current master branche of opencv https://github.com/opencv/opencv
change readNet function with readNetFromDarknet
nb : if you have the failure no attribute named RedNetFromDarknet , this is because this function is implemented in opencv_3.3.1 and greater versions.
for my case it have the same problem with opencv_3.3.0 and i noticed that this function is not implemented in this version. That's why you should check if the version you are using contain this function.
I got this problem too because I had an old version of Opencv (3.x). So, I tried pip uninstall opencv-python then pip install opencv-python and now I have the newest one (4.x) and cv2.dnn.readNet is now recognized.
I installed OpenCV via sudo brew install opencv.
Then I added PYTHONPATH* to my ~/.profile as brew info opencv says**. With env I checked that the path was loaded.
Now everytime I try to import cv, Python gives following error: Fatal Python error: PyThreadState_Get: no current thread Abort trap.
What should I do?
*PYTHONPATH=/usr/local/lib/python2.7/site-packages/:
** actually, it points to folder python2.6 but 2.7 is the Python version I use and cv 2.2. supports it.
cv 2.2 might well support it, but you MUST not mix versions like that. You must use the version built for 2.7 with 2.7, and the version built for 2.6 with 2.6
I seem to think that cv is a python library that depends on a C library - in that case, you can not mix the libraries like that.
cv will need to be re-compiled against 2.7 if you have only a 2.6 version of it.
That said, this type of Fatal Error suggests a bug in the cv library, however, if you're mixing versions like this, then the result is undefined. (It might work by chance, or it might fail randomly as it has for you).