Setting input layer in CAFFE with C++ -


i'm writing c++ code using caffe predict single (for now) image. image has been preprocessed , in .png format. have created net object , read in trained model. now, need use .png image input layer , call net.forward() - can me figure out how set input layer?

i found few examples on web, none of them work, , of them use deprecated functionality. according to: berkeley's net api, using "forwardprefilled" deprecated, , using "forward(vector, float*)" deprecated. api indicates 1 should "set input blobs, use forward() instead". makes sense, "set input blobs" part not expanded on, , can't find c++ example on how that.

i'm not sure if using caffe::datum right way go or not, i've been playing this:

float lossval = 0.0; caffe::datum datum; caffe::readimagetodatum("myimg.png", 1, imgdims[0], imgdims[1], &datum); caffe::blob< float > *imgblob = new caffe::blob< float >(1, datum.channels(), datum.height(), datum.width()); //how image data blob, , blob net input layer??? const vector< caffe::blob< float >* > &result = caffenet.forward(&lossval); 

again, i'd follow api's direction of setting input blobs , using (non-deprecated) caffenet.forward(&lossval) result opposed making use of deprecated stuff.

edit:

based on answer below, updated include this:

caffe::memorydatalayer<unsigned char> *memory_data_layer = (caffe::memorydatalayer<unsigned char> *)caffenet.layer_by_name("input").get(); vector< caffe::datum > datumvec; datumvec.push_back(datum); memory_data_layer->adddatumvector(datumvec); 

but call adddatumvector seg faulting.. wonder if related prototxt format? here's top of prototxt:

name: "deploy"    input: "data" input_shape { dim: 1 dim: 3 dim: 100 dim: 100 }  layer {   name: "conv1"   type: "convolution"   bottom: "data"   top: "conv1" 

i base part of question on this discussion "source" field being important in prototxt...

caffe::datum datum; caffe::readimagetodatum("myimg.png", 1, imgdims[0], imgdims[1], &datum); memorydatalayer<float> *memory_data_layer = (memorydatalayer<float> *)caffenet->layer_by_name("data").get(); memory_data_layer->adddatumvector(datum); const vector< caffe::blob< float >* > &result = caffenet.forward(&lossval); 

something useful. here have use memorydata layer input layer. expecting layer name named data.

the way of using datum variable may not correct. if memory correct, guess, have use vector of datum data.

i think should started.

happy brewing. :d


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -