How would I deal with an attribute error with mediapipe solutions? - python

I get an attribute error if I use the function:
def faceDetection():
if results.detections:
for detection in results.detection:
print(id, detection)
AttributeError: type object 'SolutionOutputs' has no attribute
'detections'
is the error I get if I try running, specifically it calls it on the results.detections: line
it works fine in this youtube tutorial
at 1:43:56
I don't really know how to read the github code but here's the link
I do have
mpFD = mp.solutions.face_detection # FD = face_detection
fD = mpFD.FaceDetection()
defined before the function already.
Is this an issue with my code or is it something else?

This error depends on the Python version you are using. You need to use the version minimum Python 3.9 but most probably you are using Python 3.6.
It would be better to create an environment with conda by specifying Python version and install mediapipe in there and try to run your code again. The error will disappear.
Here is an example how to establish environment to run mediapipe examples.

It wasn't a problem with the mediapipe library, but I hadn't initialized results as the faceDetections solutions, but I had results as a value for the hands solution module.

Related

TA-LIB module has no attribute 'add_all_ta_features'

I'm trying to use TA-lib for a hobby project. I found some code-snippets as reference telling me to do the following;
import talib as ta
ta.add_all_ta_features("some parameters here")
i get the following error when running the code:
ta.add_all_ta_features( AttributeError: module 'talib' has no attribute 'add_all_ta_features'
It looks like i need to manualy add all the features i want as i cant find the attribute .add_all_ta_features in the talib folder.
i've installed TA-Lib and made it a 64-bit library using Visual studio and managed to run TA-Lib in other projects before but have never used the .add_all_ta_features-attribute.
Does anybody know how i can fix this? Google seems to not return any usefull results when searched for this. The documentation i'm following also does not mention anything about this attribute.
i tried using pandas_ta and tried using the Google colab space, but both return the same error.
Found the problem. I was trying to use TA-Lib as TA, but nowhere was it specified that we need a seperate library, not findable through the python package mangager simply called TA.
Thanks!

Error in prediction using sknn.mlp

I use Anaconda on a Windows 10 laptop with Python 2.7 and Spark 2.1. Built a deep learning model using Sknn.mlp package. I have completed the model. When I try to predict using the predict function, it throws an error. I run the same code on my Mac and it works just fine. Wondering what is wrong with my windows packages.
'NoneType' object is not callable
I verified input data. It is numpy.array and it does not have null value. Its dimension is same as training one and all attributed are the same. Not sure what it can be.
I don't work with Python on Windows, so this answer will be very vague, but maybe it will guide you in the right direction. Sometimes there are cross-platform errors due to one module still not being updated for the OS, frequently when another related module gets an update. I recall something happened to me with a django application which required somebody more familiar with Windows to fix it for me.
Maybe you could try with an environment using older versions of your modules until you find the culprit.
I finally solved the problem on windows. Here is the solution in case you face it.
The Theano package was faulty. I installed the latest version from github and then it threw another error as below:
RuntimeError: To use MKL 2018 with Theano you MUST set "MKL_THREADING_LAYER=GNU" in your environment.
In order to solve this, I created a variable named MKL_Threading_Layer under user environment variable and passed GNU. Reset the kernel and it was working.
Hope it helps!

pack individual .jpg image files into RecordIO (.rec) files

I'm trying to go through the MXNET tutorial (https://statist-bhfz.github.io/cats_dogs_finetune), but have trouble making the RecordIO ".rec" files used to process the pictures.
I have tried the suggested approach:
python C:/mxnet-20170203/tools/im2rec.py --list=1 --recursive=1 --train-ratio=0.8 cats_dogs train_pad_224x224
python C:/mxnet-20170203/tools/im2rec.py --num-thread=4 --pass-through=1 cats_dogs_train.lst train_pad_224x224
python C:/mxnet-20170203/tools/im2rec.py --num-thread=4 --pass-through=1 cats_dogs_val.lst train_pad_224x224
But i get the error: "AttributeError: 'module' object has no attribute 'MXIndexedRecordIO'"
when doing so.
Is there a way to generate the ".rec" files in R directly? And if not, how do i get pass the error?
Thanks.
Kr,
Daniel
The error you are getting seems related to the fact that you are trying to use a newer version of im2rec.py than the one that came with your installed version of mxnet, hence the missing modules.
try using the im2rec.py script located in your own mxnet installation folder, somewhere like this python2.7/site-packages/mxnet/tools/im2rec.py
Also note that if you upgrade your version of mxnet, the syntax of im2rec has changed to:
im2rec.py --list --recursive --train-ratio=0.8 cats_dogs train_pad_224x224

python-opencv AttributeError: 'module' object has no attribute 'createBackgroundSubtractorGMG'

I am trying to follow the tutorial given in:
https://opencv-python-tutroals.readthedocs.org/en/latest/py_tutorials/py_video/py_bg_subtraction/py_bg_subtraction.html
While trying the third example (BackgroundSubtractorGMG) I get this error:
AttributeError: 'module' object has no attribute 'createBackgroundSubtractorGMG'
I got the same error for the earlier examples. But I followed the explanation given in this post. some how, the same trick did not work here.
If there is some one who has managed to solve it, please help me out.
Using Python 2.7.3 & opencv 2.4.6.1 on Ubuntu 12.04
In OpenCV 3.0.0-dev, you have to compile with the contrib repos and then it's in the bgsegm sub-module. I.e. just call cv2.bgsegm.createBackgroundSubtractorGMG()
cv2.bgsegm.createBackgroundSubtractorGMG()
cv2.createBackgroundSubtractorMOG2()
cv2.bgsegm.createBackgroundSubtractorMOG(),
**this worked for me **
oh dear, that's another one of those stories ...
with 2.4.6, you only can use BackgroundSubtractorMOG from python. (full stop)
as of 2.4.8, it seems, the BackgroundSubtractorMOG2 problem got fixed, but the BackgroundSubtractorGMG is still missing.
with both versions, you use a plain constructor to create one.
in 3.0 (master), they changed the syntax, you now have to call 'createBackgroundSubtractorGMG', 'createBackgroundSubtractorMOG2' and such (that's what your tutorial might be refering to). but now you can use all 3 versions at least.
so in any way, if you want to use BackgroundSubtractorMOG2 , you'll have to update to 2.4.8, if you need BackgroundSubtractorGMG, you'll need 3.0 (which is 'bleeding edge' in a way, but the new interface has the far better control over the params needed, imho).
bgsegm was in contrib module of opencv, but after the update I am not sure.
But still,
if you have not built contrib module:
pip install opencv-contrib-python
Make sure no console is running that has imported cv2 while you execute your installing process.
Run the cmd as Administration
It worked for me.

error while using FREAK

I'm trying to create Descriptor extractor using FREAK. but
at the following line:
freakExtractor = cv2.DescriptorExtractor_create('FREAK')
I get an error saying:
freakExtractor = cv2.DescriptorExtractor_create('FREAK')
AttributeError: 'module' object has no attribute 'DescriptorExtractor_create'
can someone tell me what is the exact problem and why i'm getting this error?
I'm using ubuntu 12.10 with opencv 2.4.3 and python 2.7.
I think,
cv2.DescriptorExtractor_create('FREAK')
is not a part of python interface, just use the latest opencv for that then it will work or you simply can write the code in c++ which is availabe in that version in c++.

Categories