Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Algorithm::load() not available for script wrappers #4969

Closed
opencv-pushbot opened this Issue Jul 27, 2015 · 24 comments

Comments

@opencv-pushbot
Copy link
Contributor

opencv-pushbot commented Jul 27, 2015

Transferred from http://code.opencv.org/issues/4279

|| be rak on 2015-04-14 14:32
|| Priority: Normal
|| Affected: branch 'master' (3.0-dev)
|| Category: ml
|| Tracker: Bug
|| Difficulty: 
|| PR: 
|| Platform: Any / Any

Algorithm::load() not available for script wrappers

while trying to fix the ml-related python samples, i found
that it's impossible to load a serialized state from python atm.

adding a respective method like:

CV_WRAP static Ptr<SVM> load(const String &fn)
{
    return Algorithm::load<SVM>(fn);
}

to each of the ml classes would fix it, but hopefully there might be a better way (without changing the interface)

History

Vadim Pisarevsky on 2015-04-27 11:12
-   Category set to ml
Maksim Shabunin on 2015-04-29 09:21
-   Target version set to 3.0

bastelflp added a commit to bastelflp/opencv that referenced this issue Dec 13, 2015

Python samples adapted for Python3 compatibility
Common fixes:
- print function
- int / float division
- map, zip iterators in py3 but lists in py2

Known bugs with opencv 3.0.0
- digits.py, called via digits_video.py: opencv#4969
- gaussian_mix.py: opencv#4232
- video_v4l2.py: opencv#5474

Not working:
- letter_recog.py due to changed ml_StatModel.train() signature

DarwinsBuddy pushed a commit to DarwinsBuddy/opencv that referenced this issue Jan 4, 2016

Christoph Spörk
fixing issue opencv#4969 of Itseez/opencv.
Someone forgot to wrap the load function for SVMs in the
corresponding ml python module. Fixed that.
@sandeep-ps

This comment has been minimized.

Copy link

sandeep-ps commented Feb 25, 2016

Could anyone share the current status of this issue?

Aravind-Suresh added a commit to Aravind-Suresh/opencv-1 that referenced this issue Feb 26, 2016

fixing issue opencv#4969 of Itseez/opencv.
Someone forgot to wrap the load function for SVMs in the
corresponding ml python module. Fixed that.
@evan01

This comment has been minimized.

Copy link

evan01 commented Jun 10, 2016

Has anyone fixed this??

@lonewolf9277

This comment has been minimized.

Copy link

lonewolf9277 commented Aug 25, 2016

Can someone please solve this bug? it's kind of urgent

@brian-yu

This comment has been minimized.

Copy link

brian-yu commented Sep 12, 2016

Any updates on this issue?

@evan01

This comment has been minimized.

Copy link

evan01 commented Sep 12, 2016

Apparently they just never ended up writing the wrapper for this. My vote, use sci-kit. I ended up doing this and it worked a lot better anyways. I also used PIL for the loading and saving of the trained network.

@brian-yu

This comment has been minimized.

Copy link

brian-yu commented Sep 12, 2016

@evan01 I will look into it, thank you.

@DuinoDu

This comment has been minimized.

Copy link

DuinoDu commented Sep 14, 2016

So is it a good suggestion for pythoners to use sci-kit rather than cv2.ml ?

@DuinoDu

This comment has been minimized.

Copy link

DuinoDu commented Sep 22, 2016

I found that you can use

self.model = cv2.ml.SVM_load(filename)

instead.

@techfort

This comment has been minimized.

Copy link
Contributor

techfort commented Sep 29, 2016

@DuinoDu really? there doesn't seem to be any such function as of cv2.version 3.1.0, which version are you on?

@DuinoDu

This comment has been minimized.

Copy link

DuinoDu commented Sep 29, 2016

I just git clone from github. It should be version 3.1.0

@techfort

This comment has been minimized.

Copy link
Contributor

techfort commented Sep 29, 2016

hey @DuinoDu ok so i'm on 3.1.0 cloned and built about a week ago.
this is the output of
chaos9:section2 joe$ python -c "import cv2; print cv2.__version__; help(cv2.ml)" > log

I don't see any SVM_load?

3.1.0
Help on module cv2.ml in cv2:

NAME
    cv2.ml

FILE
    (built-in)

FUNCTIONS
    ANN_MLP_create(...)
        ANN_MLP_create() -> retval

    Boost_create(...)
        Boost_create() -> retval

    DTrees_create(...)
        DTrees_create() -> retval

    EM_create(...)
        EM_create() -> retval

    KNearest_create(...)
        KNearest_create() -> retval

    LogisticRegression_create(...)
        LogisticRegression_create() -> retval

    NormalBayesClassifier_create(...)
        NormalBayesClassifier_create() -> retval

    RTrees_create(...)
        RTrees_create() -> retval

    SVM_create(...)
        SVM_create() -> retval

    TrainData_create(...)
        TrainData_create(samples, layout, responses[, varIdx[, sampleIdx[, sampleWeights[, varType]]]]) -> retval

    TrainData_getSubVector(...)
        TrainData_getSubVector(vec, idx) -> retval

DATA
    ANN_MLP_BACKPROP = 0
    ANN_MLP_GAUSSIAN = 2
    ANN_MLP_IDENTITY = 0
    ANN_MLP_NO_INPUT_SCALE = 2
    ANN_MLP_NO_OUTPUT_SCALE = 4
    ANN_MLP_RPROP = 1
    ANN_MLP_SIGMOID_SYM = 1
    ANN_MLP_UPDATE_WEIGHTS = 1
    BOOST_DISCRETE = 0
    BOOST_GENTLE = 3
    BOOST_LOGIT = 2
    BOOST_REAL = 1
    Boost_DISCRETE = 0
    Boost_GENTLE = 3
    Boost_LOGIT = 2
    Boost_REAL = 1
    COL_SAMPLE = 1
    DTREES_PREDICT_AUTO = 0
    DTREES_PREDICT_MASK = 768
    DTREES_PREDICT_MAX_VOTE = 512
    DTREES_PREDICT_SUM = 256
    DTrees_PREDICT_AUTO = 0
    DTrees_PREDICT_MASK = 768
    DTrees_PREDICT_MAX_VOTE = 512
    DTrees_PREDICT_SUM = 256
    EM_COV_MAT_DEFAULT = 1
    EM_COV_MAT_DIAGONAL = 1
    EM_COV_MAT_GENERIC = 2
    EM_COV_MAT_SPHERICAL = 0
    EM_DEFAULT_MAX_ITERS = 100
    EM_DEFAULT_NCLUSTERS = 5
    EM_START_AUTO_STEP = 0
    EM_START_E_STEP = 1
    EM_START_M_STEP = 2
    KNEAREST_BRUTE_FORCE = 1
    KNEAREST_KDTREE = 2
    KNearest_BRUTE_FORCE = 1
    KNearest_KDTREE = 2
    LOGISTIC_REGRESSION_BATCH = 0
    LOGISTIC_REGRESSION_MINI_BATCH = 1
    LOGISTIC_REGRESSION_REG_DISABLE = -1
    LOGISTIC_REGRESSION_REG_L1 = 0
    LOGISTIC_REGRESSION_REG_L2 = 1
    LogisticRegression_BATCH = 0
    LogisticRegression_MINI_BATCH = 1
    LogisticRegression_REG_DISABLE = -1
    LogisticRegression_REG_L1 = 0
    LogisticRegression_REG_L2 = 1
    ROW_SAMPLE = 0
    STAT_MODEL_COMPRESSED_INPUT = 2
    STAT_MODEL_PREPROCESSED_INPUT = 4
    STAT_MODEL_RAW_OUTPUT = 1
    STAT_MODEL_UPDATE_MODEL = 1
    SVM_C = 0
    SVM_CHI2 = 4
    SVM_COEF = 4
    SVM_CUSTOM = -1
    SVM_C_SVC = 100
    SVM_DEGREE = 5
    SVM_EPS_SVR = 103
    SVM_GAMMA = 1
    SVM_INTER = 5
    SVM_LINEAR = 0
    SVM_NU = 3
    SVM_NU_SVC = 101
    SVM_NU_SVR = 104
    SVM_ONE_CLASS = 102
    SVM_P = 2
    SVM_POLY = 1
    SVM_RBF = 2
    SVM_SIGMOID = 3
    StatModel_COMPRESSED_INPUT = 2
    StatModel_PREPROCESSED_INPUT = 4
    StatModel_RAW_OUTPUT = 1
    StatModel_UPDATE_MODEL = 1
    TEST_ERROR = 0
    TRAIN_ERROR = 1
    VAR_CATEGORICAL = 1
    VAR_NUMERICAL = 0
    VAR_ORDERED = 0```
@DuinoDu

This comment has been minimized.

Copy link

DuinoDu commented Sep 29, 2016

It is my output

LogisticRegression_create(...)
        LogisticRegression_create() -> retval

    NormalBayesClassifier_create(...)
        NormalBayesClassifier_create() -> retval

    RTrees_create(...)
        RTrees_create() -> retval

    SVMSGD_create(...)
        SVMSGD_create() -> retval

    SVM_create(...)
        SVM_create() -> retval

    SVM_load(...)
        SVM_load(filepath) -> retval

    TrainData_create(...)

@techfort

This comment has been minimized.

Copy link
Contributor

techfort commented Sep 29, 2016

@DuinoDu can you please confirm your version by doing cv2.__version__

@DuinoDu

This comment has been minimized.

Copy link

DuinoDu commented Sep 30, 2016

3.1.0-dev

@David-Estevez David-Estevez referenced this issue Dec 4, 2016

Closed

SVM training for wrinkle detection #20

10 of 11 tasks complete
@crearo

This comment has been minimized.

Copy link

crearo commented Dec 22, 2016

Any updates on this? I'm trying to use OpenCV3.1 on Android using the Java wrapper to do face detection using Hog detector with SVM.
OpenCV 3.1 (downloaded from the website) doesn't have Java wrappers for load()/read() in the SVM or StatModel class, and I really want to avoid using JNI to do C++ calls for the same. (Though yes I know the wrapper does precisely this internally).
I can't modify the wrappers as they are autogenerated, and I can't modify the libopencv_java3.so bundle, because it is a shared lib. Could I possibly make my own wrapper for SVM and StatModel that will work with the rest of classes of the Java wrapper?

@crearo

This comment has been minimized.

Copy link

crearo commented Dec 28, 2016

OpenCV 3.2 fixes it! Thanks!

@mshabunin mshabunin closed this Dec 29, 2016

@spidgorny

This comment has been minimized.

Copy link

spidgorny commented May 25, 2017

What about KNN_load() which is still missing in opencv-python (3.2.0.7)?

@alalek

This comment has been minimized.

Copy link
Contributor

alalek commented May 25, 2017

opencv-python

We don't support this package here.

@Gaelan

This comment has been minimized.

Copy link

Gaelan commented Sep 19, 2017

I'm still having this issue on 3.3 (Mac, installed via Homebrew, cv2.__version__ reports 3.3.0). cv2.face.LBPHFaceRecognizer_create().load doesn't exist.

@imakin

This comment has been minimized.

Copy link

imakin commented Oct 7, 2017

just compiled the latest stable version and still no load method for python

just why though...

but as stated when this issue was closed, tried version 3.2 you can use the load method in python

@mehakhafeez

This comment has been minimized.

Copy link

mehakhafeez commented Oct 21, 2017

can anyone plz tell me which type of svm is used in this
Classification SVM Type 1 (also known as C-SVM classification)
Classification SVM Type 2 (also known as nu-SVM classification)
Regression SVM Type 1 (also known as epsilon-SVM regression)
Regression SVM Type 2 (also known as nu-SVM regression)
???? and what is happening is that type plz some body help me i dont have much time///??

@qzqzzz

This comment has been minimized.

Copy link

qzqzzz commented Apr 2, 2018

Any updates on the original reported issue?

@kayamuhendiss

This comment has been minimized.

Copy link

kayamuhendiss commented Apr 15, 2018

Hi,I want to Error.
NameError: name 'unichr' is not defined
I changed Unichr to chr. I get an error again.

@yongcong1415

This comment has been minimized.

Copy link

yongcong1415 commented Dec 17, 2018

I found that you can use

self.model = cv2.ml.SVM_load(filename)

instead.

how to release the model,TKS;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.