I have a trained convolutional net, created from
this and
this examples, and I'm trying to test it on an image.
Mat dst; ///there is an image
resize(src, dst, Size(227,227) );
///load trained convolutional net
std::shared_ptr<Net<float> > net_conv( new Net<float>( "/.../bvlc_caffenet_full_conv.prototxt", caffe::TEST ) );
net_conv->CopyTrainedLayersFrom("/.../out_conv.caffemodel");
TransformationParameter input_xform_param;
input_xform_param.set_scale( 1.0/255 );
DataTransformer<float> input_xformer( input_xform_param, TEST );
TransformationParameter output_xform_param;
output_xform_param.set_scale(255.0);
DataTransformer<float> output_xformer( output_xform_param, TEST );
Blob<float> input_blob;
input_blob.Reshape(1, dst.channels(), dst.rows, dst.cols );
//mete la imagen en el input blob
input_xformer.Transform( dst, &input_blob );
std::vector<Blob<float>*> input;
input.push_back( &input_blob );
std::vector<caffe::Blob<float>*> output = net_conv->Forward( input );
Blob<float> output_blob;
// Scale the output blob back to the original image scaling
output_blob.Reshape( raw_blob_ptr->shape() );
//medio trivial pero por ahi lo usamos
output_xformer.Transform( raw_blob_ptr, &output_blob );
// Shape the blob to match the input blob
vector<int> theShape = {raw_blob_ptr->shape(0), input_blob.shape(1),
input_blob.shape(2),input_blob.shape(3) };
output_blob.Reshape( theShape );
// Convert the output blob back to an image.
Datum datum;
datum.set_height( output_blob.height() );
datum.set_width( output_blob.width() );
datum.set_channels( output_blob.channels() );
datum.clear_data();
datum.clear_float_data();
const float* blob_data = output_blob.cpu_data();
blob_data += output_blob.offset(0);
for( int i = 0; i < output_blob.count(); ++i )
{
datum.add_float_data( blob_data[i] );
}
cv::Mat mat = DatumToCvMat(datum);
show_image(mat, "output");
The returned image is completly black. We checked this line
for the return value and the returned pointer is 0, which obviously can't be since cpu_ptr_ (which is the pointer that should be returned) isn't null.
I tried debugging further but I couldn't get inside cpu_data(), it looks like it skips over it and just returns 0.
Maybe I'm messing this up, could the training be wrong? or is it something I'm messing up to retrieve the output image?
Thank you for any help you can provide