Ask Your Question
1

How to load ANN in opencv 3.xxx

asked 2017-05-31 06:10:19 -0600

damiya14 gravatar image

i have trained an ANN and saved it. now i want to load it and input images in to it and classify. how can i do this? example code will be so helpful. Thanks

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2017-05-31 07:10:44 -0600

LBerger gravatar image

updated 2017-06-02 07:32:54 -0600

You can do this :

Ptr<ANN_MLP> modeleANN;
modeleANN = ANN_MLP::load("opencv_ml_ann_mlp.yml");

or

Ptr<ANN_MLP> modeleANN;
modeleANN = Algorithm::load<ANN_MLP>("opencv_ml_ann_mlp.yml");

your model is ready to predict :

modeleANN->predict(feature, result);
Point pos;
minMaxLoc(result, &minX, &maxX, NULL, &pos);
cout << modeleANN->getDefaultName() << " \tclass = " << pos.x << "\t network output "<<result<<"\n";
edit flag offensive delete link more

Comments

1

Thank You!!

damiya14 gravatar imagedamiya14 ( 2017-06-02 07:16:24 -0600 )edit

i want to input one image in to the model and get the classification. how can i do this?

damiya14 gravatar imagedamiya14 ( 2017-06-05 04:09:51 -0600 )edit

use reshape :

    Mat x=imread("lena.jpg",IMREAD_COLOR);
    x=x.reshape(1,x.rows*x.cols*x.channels()).t();

x is now an image of 1 rows and 786432 columns = 512 rows *512 column *3 channel

LBerger gravatar imageLBerger ( 2017-06-05 05:41:15 -0600 )edit

i used that method but i get a SOGSEGV error.

in my training method the input is 1 row and 6400 cols (80x80 gray scale image). and in my prediction part i give the same size Mat in to the network but still get an error.

damiya14 gravatar imagedamiya14 ( 2017-06-05 06:09:28 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-05-31 06:10:19 -0600

Seen: 541 times

Last updated: Jun 02 '17