First time here? Check out the FAQ!

Ask Your Question
1

How to load ANN in opencv 3.xxx

asked May 31 '17

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

Preview: (hide)

1 answer

Sort by » oldest newest most voted
1

answered May 31 '17

LBerger gravatar image

updated Jun 2 '17

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";
Preview: (hide)

Comments

1

Thank You!!

damiya14 gravatar imagedamiya14 (Jun 2 '17)edit

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

damiya14 gravatar imagedamiya14 (Jun 5 '17)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 (Jun 5 '17)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 (Jun 5 '17)edit

Question Tools

1 follower

Stats

Asked: May 31 '17

Seen: 617 times

Last updated: Jun 02 '17