how to do the prediction iteratively using C++ interface?

27 views
Skip to first unread message

jeremy chang

unread,
Oct 31, 2016, 10:44:10 AM10/31/16
to Caffe Users
Hi, i am the beginner of caffe
Recently i have been learning how to use a pretrained caffe model to do some prediction in my own  project
and now i am trying to do a iteratively prediction while each loop there will be a new data(input) to be predicted
i use memory data layer as my data input layer

before entering the loop, i make some declaration 
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
               caffe::Datum datum;
datum.set_channels(1);
datum.set_height(1);
datum.set_width(30);
vector<caffe::Datum> dvector;
boost::shared_ptr<MemoryDataLayer<float> > memory_data_layer;
memory_data_layer = boost::static_pointer_cast<MemoryDataLayer<float>>(net.layer_by_name("datas"));
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

and in each loop, assume there is a new input data "vector<float> mydata" to be predicted
Here is what i do in each loop
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
              1.  copy data from "mydata" to "datum"
              2.   dvector.clear();
    dvector.push_back(datum);
              3.   memory_data_layer->AddDatumVector(dvector);
              4.   const vector<Blob<float>*> & results = net.Forward();
    float *output = results[0]->mutable_cpu_data();
              5.   get output result from "output[1]"
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

but the output result will turn out to be the same every loop even though the input data is different
am I skip any necessary steps?
thanks!
Reply all
Reply to author
Forward
0 new messages