0

I am new to caffe and thus was trying to play around with the MNIST dataset . I ran the following commands

./data/mnist/get_mnist.sh
./examples/mnist/create_mnist.sh
./examples/mnist/train_lenet.sh

I haven't changed any of the files in caffe and has executed just the above 3 lines.

My example/mnist folder structure is as follows:

examples/mnist/
|-- convert_mnist_data.cpp
|-- create_mnist.sh
|-- lenet_adadelta_solver.prototxt
|-- lenet_auto_solver.prototxt
|-- lenet_consolidated_solver.prototxt
|-- lenet_iter_10000.caffemodel
|-- lenet_iter_10000.solverstate
|-- lenet_iter_5000.caffemodel
|-- lenet_iter_5000.solverstate
|-- lenet_multistep_solver.prototxt
|-- lenet.prototxt
|-- lenet_solver_adam.prototxt
|-- lenet_solver.prototxt
|-- lenet_solver_rmsprop.prototxt
|-- lenet_train_test.prototxt
|-- mnist_autoencoder.prototxt
|-- mnist_autoencoder_solver_adadelta.prototxt
|-- mnist_autoencoder_solver_adagrad.prototxt
|-- mnist_autoencoder_solver_nesterov.prototxt
|-- mnist_autoencoder_solver.prototxt
|-- mnist_test_lmdb
|   |-- data.mdb
|   `-- lock.mdb
|-- mnist_train_lmdb
|   |-- data.mdb
|   `-- lock.mdb
|-- readme.md
|-- train_lenet_adam.sh
|-- train_lenet_consolidated.sh
|-- train_lenet_docker.sh
|-- train_lenet_rmsprop.sh
|-- train_lenet.sh
|-- train_mnist_autoencoder_adadelta.sh
|-- train_mnist_autoencoder_adagrad.sh
|-- train_mnist_autoencoder_nesterov.sh
`-- train_mnist_autoencoder.sh

I want to test the model created by passing an image that is of size 256*256 but don't know how to do it, and want to do it using python . Any help would be appreciated .

kkk
  • 1,850
  • 1
  • 25
  • 45

1 Answers1

1
  1. You will need to downscale your image to the desired size 28x28.

  2. You have already created a dataset in LMDB format:

    • ./data/mnist/get_mnist.sh
    • ./examples/mnist/create_mnist.sh

And have already trained the model:

  • ./examples/mnist/lenet_train_test.prototxt

whose weights are stored as:

  • ./examples/mnist/lenet_iter_10000.caffemodel

You now want to deploy your classifier. lenet.prototxt is the same model at the core, except it's input and outputs have changed. When you deploy, you want to have as input a regular image in practice.

  • ./examples/mnist/lenet.prototxt : deployment model
  • ./examples/mnist/lenet_iter_10000.caffemodel : learned weights

.

I am not aware if you can simply use the caffe tool and run the test command on an image.

The easiest ways to classify seem to be using matlab or python.

Here is a matlab example:

model = 'lenet.prototxt';
weights = 'lenet_iter_10000.caffemodel';
%caffe.set_mode_gpu();
%caffe.set_device(0);
net = caffe.Net(model, weights, 'test');
image = imread('example.png');
res = net.forward({image});
prob = res{1}

Here is a classification tutorial using python (./examples/00-classification.ipynb). However, it's designed for ilsvrc12 type datasets. If you simply ignore subtracting the mean image, it might just work.

There is also a CPP example (./examples/cpp_classification), but again I'm not sure about the mean image.

Eduard Feicho
  • 568
  • 4
  • 8