Lately I've been attempting to classify images using C++. A few references have pointed to #499, however I have only been able to reproduce some of the results within that issue.
As it stands I am able to classify images with predict.cpp which uses image_data_param and a source list of images. Nonetheless, I am interested in classifying images using memory_data_param and thus not needing to rely on a saved image on disk. While this is certainly possible with Python, is this possible in C++?
You can try https://github.com/BVLC/caffe/pull/1416
@Zackory I had my own share of brewing code snippets from the bag of messy Caffe tickets, so here is my currently grinded final solution, if it can help:
float loss = 0.0;
std::vector<cv::Mat> dv = {image}; // image is a cv::Mat, as I'm using #1416
std::vector<int> dvl = {0};
boost::dynamic_pointer_cast<caffe::MemoryDataLayer<float>>(_net->layers()[0])->AddMatVector(dv,dvl);
std::vector<Blob<float>*> results = _net->ForwardPrefilled(&loss); // depending on your net's architecture, the blobs will hold accuracy and / or labels, etc...
From the top of one of my deploy.prototxt files:
layers {
name: "data"
type: MEMORY_DATA
top: "data"
top: "label"
memory_data_param {
batch_size: 1
channels: 3
height: 227
width: 227
}
transform_param {
crop_size: 227
mirror: true
mean_file: "mean.binaryproto"
}
On my spare-time I am working on a little higher level machinery that helps running ML algorithms, including Caffe and possibly other ML libs.
@beniz
hello beniz,
Can you give me a complete example of #1416 , my English is poor, do not know whether you can understand my meaning.
@githubtest20141111 just look at the example above, AddMatVector applies to the bottom layer.
@beniz I may be an old version, I do not have the following file ,how should I do????
include/caffe/data_layers.hpp
include/caffe/data_transformer.hpp
src/caffe/data_transformer.cpp
@githubtest20141111 I am using the 'dev' branch if this can help.
@beniz @bhack If I was using the old version, how should I do, can you give me an example
@kloudkl can you give me an example about memory data layer,i use c++
@pleasurelong can you give me an example about memory data layer,i use c++
@shelhamer @longjon Can you close this ticket? @beniz if you are interested you can add an example in the wiki. For other user side question please use the mailinglist
Please ask usage questions on the caffe-users mailing list. Thanks!
@Zackory
Have you got the answer for how to use memory data layer for testing the model in real time with camera frames. I am unable to use memory data layer for image inputs. Please help me
I'm use opencv load a caffe module :(http://docs.opencv.org/trunk/d5/de7/tutorial_dnn_googlenet.html)
is there anyone know how to deal with this problem?
main.cpp:13:23: error: variable or field ‘getMaxClass’ declared void
void getMaxClass(dnn::Blob &probBlob, int *classId, double *classProb)
^
main.cpp:13:18: error: ‘Blob’ is not a member of ‘cv::dnn’
void getMaxClass(dnn::Blob &probBlob, int *classId, double *classProb)
Most helpful comment
@Zackory I had my own share of brewing code snippets from the bag of messy Caffe tickets, so here is my currently grinded final solution, if it can help:
From the top of one of my deploy.prototxt files:
On my spare-time I am working on a little higher level machinery that helps running ML algorithms, including Caffe and possibly other ML libs.