Testing trained machine

131 views
Skip to first unread message

sergey....@gmail.com

unread,
Jan 18, 2013, 11:08:25 AM1/18/13
to ebl...@googlegroups.com
Hello!

I've faced some problems with testing trained machine.
I've trained lenet5 machine for MINST dataset following MNIST demo tutorial. When I load it from file and testing it with supervised_trainer it works fine.
But when I try to use it on some test image I have zero outputs for all my classes.

Here is my code for recognition of single test image:

////////////////////////////////////////////////////////////////////////////////

string class_l5_path("mnist_trained_network.mat");
parameter<fs(double)> theparam;
theparam.resize(1);
theparam.load_x(class_l5_path.c_str());
lenet5<fs(double)> l5(theparam, 32, 32, 5, 5, 2, 2, 5, 5, 2, 2, 120, 10);

// I don't have ImageMagick, so I load image using OpenCV end resize it to 32x32
Mat image_orig = imread("test_image.png");
vector<Mat> image_channels;
split(image_orig, image_channels);
Mat image;
resize(image_channels[0], image, Size(32, 32));
idx<ubyte> image_idx(32, 32);
// Copying OpenCV image in idx
for (int i = 0; i < image.rows; ++i)
for (int j = 0; j < image.cols; ++j)
image_idx.set(image.at<unsigned char>(i, j), i, j);

fstate_idx<double> stin(1, image.rows, image.cols);
idx<double> inx = stin.x.select(0, 0);
idx_copy(image_idx, inx);
fstate_idx<double> stout(1,1,1);

l5.fprop(stin, stout);
for (int i = 0; i < stout.x.dim(0); ++i)
cout << stout.x.get(i) << " ";

/////////////////////////////////////////////////////////////////////////////

So the problem is that all outputs are equal to zero (output of cout is "0 0 0 0 0 0 0 0 0 0"). Could you help and tell me what I'm doing wrong or show me where I can find a code example with using trained network on test image?

Regards,
Sergey Milyaev

soumith

unread,
Jan 18, 2013, 12:06:48 PM1/18/13
to ebl...@googlegroups.com
Hey, which version of eblearn are you using? The trunk and v1.2 no longer have fstate_idx, all state* classes have been moved to a single  "state" class.


--



sergey....@gmail.com

unread,
Jan 19, 2013, 2:51:07 AM1/19/13
to ebl...@googlegroups.com
пятница, 18 января 2013 г., 21:06:48 UTC+4 пользователь the_minion написал:
I'm using 1.1 version.

sergey....@gmail.com

unread,
Jan 21, 2013, 8:20:27 AM1/21/13
to ebl...@googlegroups.com, sergey....@gmail.com
пятница, 18 января 2013 г., 20:08:25 UTC+4 пользователь sergey....@gmail.com написал:
Problem solved.

the_minion

unread,
Jan 23, 2013, 4:25:05 PM1/23/13
to ebl...@googlegroups.com, sergey....@gmail.com
Can you post what the problem was and how you solved it? Might be useful for future users.

sergey....@gmail.com

unread,
Jan 25, 2013, 6:48:20 AM1/25/13
to ebl...@googlegroups.com, sergey....@gmail.com
четверг, 24 января 2013 г., 1:25:05 UTC+4 пользователь the_minion написал:
Sure.

I've tried to load already trained network by following code:

string class_l5_path("mnist_trained_network.mat"); // path to saved parameters
parameter<fs(double)> theparam;
theparam.resize(1);
theparam.load_x(class_l5_path.c_str());
lenet5<fs(double)> l5(theparam, 32, 32, 5, 5, 2, 2, 5, 5, 2, 2, 120, 10); // creating classifer with loaded parameters

But when I tested it on image a have all zero outputs for all classes:

l5.fprop(stin, stout);
for (int i = 0; i < stout.x.dim(0); ++i)
cout << stout.x.get(i) << " ";

So, the output was "0 0 0 0 0 0 0 0 0 0".

I've tried to create lenet5 machine first with uninitialized parameter and then load it from file and it works)

parameter<fs(double)> theparam;
lenet5<fs(double)> l5(theparam, 32, 32, 5, 5, 2, 2, 5, 5, 2, 2, 120, 10);
theparam.resize(1);
theparam.load_x(class_l5_path.c_str());

cmog...@gmail.com

unread,
Mar 10, 2013, 12:44:24 PM3/10/13
to ebl...@googlegroups.com
I'm trying to do same thing. I trained MNIST as in http://eblearn.cs.nyu.edu:21991/doku.php?id=mnist

I modified code to use IMagick:

#include "eblearn/libidx.h"
#include "eblearn/libeblearn.h"
#include "eblearn/libeblearntools.h"
#include "eblearn/libeblearngui.h"
#include "eblearn/libidxgui.h"
#include "eblearn/ebl_states.h"
#include "eblearn/ebl_machines.h"
#include <iostream>
#include <Magick++.h>

INIT_DEBUGMEM()
INIT_DUMP()

using namespace std;
using namespace ebl;
using namespace Magick;

MAIN_QTHREAD(int, argc, char **, argv)
{
try
{
cout << "Start\n";

string class_l5_path("//home//cmogilko//eblearn//my//mnist_net00020.mat");
parameter<fs(double)> theparam;
lenet5<fs(double)> l5(theparam, 32, 32, 5, 5, 2, 2, 5, 5, 2, 2, 120, 10);
theparam.resize(1);
theparam.load_x(class_l5_path.c_str());

Image m;
m.read("3.jpg");
Geometry newSize = Geometry(32, 32);
newSize.aspect(true);
m.resize(newSize);
m.type(GrayscaleType);
m.write("gr3.jpg");

idx<ubyte> image_idx(32, 32);
for(int i = 0; i < 32; i++)
for (int j = 0; j < 32; j++)
{
ColorGray c(m.pixelColor(i, j));
image_idx.set(c.shade()*255, i, j);
}

fstate_idx<double> stin(1, 32, 32);
idx<double> inx = stin.x.select(0, 0);
idx_copy(image_idx, inx);
fstate_idx<double> stout(1,1,1);

l5.fprop(stin, stout);
for (int i = 0; i < stout.x.dim(0); ++i)
cout << i << " " << stout.x.get(i) << "\n";
}
eblcatch();
return 0;
}

I drew this image: http://4.firepic.org/4/images/2013-03/10/fko06k8rkgic.jpg

But results was strange:
0 1.71077
1 1.71549
2 0.66524
3 1.68648
4 1.68193
5 1.71569
6 0.268922
7 1.71229
8 -1.01364
9 1.71582

Where was I wrong? Wrong self-drawn image? Wrong usage IMagick? Wrong usage network configuration?

If it was wrong self-drawn image, how to extract images from mnist dataset? I can't find information about extracting.

пятница, 25 января 2013 г., 15:48:20 UTC+4 пользователь sergey....@gmail.com написал:
Reply all
Reply to author
Forward
0 new messages