Coder Social home page Coder Social logo

Comments (4)

mbeyeler avatar mbeyeler commented on August 18, 2024

Thanks for posting. It is not immediately clear to me what is causing this error. It seems to be caused by the train function of the OpenCV classifier.

I suspect either X_train or y_train_bin on L256 has length 1, and that is causing some issues with the classifier's train function. Can you add a print statement right before that to see what X_train[data_id, :], y_train_bin, and self.params look like?

from opencv-python-blueprints.

Algabri avatar Algabri commented on August 18, 2024

Thanks, @mbeyeler
The outputs are:

X_train [[  85.   96.  127. ...,  100.  104.  113.]
 [  19.   18.   17. ...,   71.  103.  132.]
 [  93.   92.  186. ...,   11.    8.    9.]
 ..., 
 [  22.   20.   21. ...,   76.   62.   44.]
 [  30.   29.   30. ...,   28.   28.   29.]
 [  75.   89.   90. ...,  241.  225.  233.]]
 - strategy one-vs-one
    - train
y_train_bin [0 1 0 ..., 1 1 0]

from opencv-python-blueprints.

mbeyeler avatar mbeyeler commented on August 18, 2024

Looks all good. I think the problem is that they changed the OpenCV API to train(samples, layout, responses), similar to what is explained here.

Try adding a layout parameter to L256:

self.classifiers[svm_id].train(X_train[data_id, :], cv2.ml.ROW_SAMPLE, y_train_bin)

from opencv-python-blueprints.

Algabri avatar Algabri commented on August 18, 2024

Thanks, yes.
It is fine now.
Sorry, @mbeyeler. I wrote this answer before appearing this error.
I already change it to self.classifiers.append(cv2.ml.SVM_create()) but it is still giving error.
Another error:

Traceback (most recent call last):
  File "/home/redhwan/Downloads/opencv-python-blueprints-master/chapter6/chapter6.py", line 78, in <module>
    main()
  File "/home/redhwan/Downloads/opencv-python-blueprints-master/chapter6/chapter6.py", line 49, in main
    acc, prec, rec = MCS.evaluate(X_test, y_test)
  File "/home/redhwan/Downloads/opencv-python-blueprints-master/chapter6/classifiers.py", line 298, in evaluate
    y_hat = self.classifiers[svm_id].predict_all(X_test_id)
AttributeError: 'cv2.ml_SVM' object has no attribute 'predict_all'

from opencv-python-blueprints.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.