0
我用caffe为我的机器学习C++
。如何在caffe中提取图层的blob信息?
作为net_->Forward();
通过网络后,我喜欢提取单个图层的信息。
我所做的是
net_->Forward();
//Extract layer information
cout << "Num layers:" << "'" << net_->layer_names().size() << "'"<< endl;
for (int layer_index = 0; layer_index < net_->layer_names().size(); ++layer_index)
{
// get that layer blob and its dimension
const boost::shared_ptr<Blob<float> > blob = net_->blob_by_name(net_->blob_names()[layer_index]);
int batch_size = blob->num();
int dim_features = blob->count()/batch_size;
std::cout << "Layer name:" << "'" << net_->layer_names()[layer_index] << "'" << " Blob name:" << "'" <<net_->blob_names()[layer_index] << "'" << " batch size " << "'" << batch_size << "'" << " dim_features:" << "'" << dim_features << "'" << std::endl;
}
我可以看到所有的图层名称和尺寸。
Layer name'image' Blob name'image' batch_size'1' dim_features'921600'
Layer name'conv1/7x7_s2' Blob name'conv1/7x7_s2' batch_size'1' dim_features'4915200'
Layer name'conv1/relu_7x7' Blob name'pool1/3x3_s2' batch_size'1' dim_features'1228800'
Layer name'pool1/3x3_s2' Blob name'pool1/norm1' batch_size'1' dim_features'1228800'
Layer name'pool1/norm1' Blob name'conv2/3x3_reduce' batch_size'1' dim_features'1228800'
Layer name'conv2/3x3_reduce' Blob name'conv2/3x3' batch_size'1' dim_features'3686400'
Layer name'conv2/relu_3x3_reduce' Blob name'conv2/norm2' batch_size'1' dim_features'3686400'
但是在这里我仍然需要更深入的信息。
当前尺寸是921600,即组成批量大小x通道×高度×宽度=的921600.
(1)因此,我的第一查询是如何分割的信息?
(2)说我有此信息的批量大小x通道×高度×宽度= 1×3×480×640然后
如何在像1×1×480×640的blob提取每个层,这样我可以打印或者我可以绘图。
这种事情,我可以在Python做这样
for layer_name, blob in net.blobs.iteritems():
print layer_name + '\t' + str(blob.data.shape)
mydata = net.blobs[layer_name].data[0,0,:,:]
#cv2.imshow("mydata",mydata);
#cv2.waitKey(1)
layer_name = layer_name.replace('/', '_')
np.savetxt("printdata/"+layer_name+".csv", mydata, delimiter=",")
但现在,我想在C++
做。
我做了同样的事情。但我得到黑色的图像,因为我做了cv :: Mat a(blob-> height(),blob-> width(),CV_32FC1,blob-> data_at(0,1,0,0));有问题? – batuman
我不明白这里的问题。我以为你只想要blob的尺寸信息。你想显示blob的图像吗? – lnman
Y在我的第二个问题中 – batuman