如何确定caffe blob的输入尺寸

时间:2018-05-29 22:14:37

标签: machine-learning neural-network deep-learning caffe pycaffe

我正在尝试为caffe网打印出一些诊断信息,但是虽然我可以通过blob找到数据输出的形状,但我无法直接找到预期输入数据的形状。例如:

nb = self.net.blobs # nb is an OrderedDict of the blob objects 
                      that make up a VGG16 net
for ctr, name in enumerate(nb):
   print ctr, name, nb[name].data.shape

0 data (10, 3, 224, 224)
1 conv1_1 (10, 64, 224, 224)
2 conv1_2 (10, 64, 224, 224)
3 pool1 (10, 64, 112, 112)
4 conv2_1 (10, 128, 112, 112)
5 conv2_2 (10, 128, 112, 112)
6 pool2 (10, 128, 56, 56)
7 conv3_1 (10, 256, 56, 56)
8 conv3_2 (10, 256, 56, 56)
9 conv3_3 (10, 256, 56, 56)
10 pool3 (10, 256, 28, 28)
11 conv4_1 (10, 512, 28, 28)
12 conv4_2 (10, 512, 28, 28)
13 conv4_3 (10, 512, 28, 28)
14 pool4 (10, 512, 14, 14)
15 conv5_1 (10, 512, 14, 14)
16 conv5_2 (10, 512, 14, 14)
17 conv5_3 (10, 512, 14, 14)
18 pool5 (10, 512, 7, 7)
19 fc6 (10, 4096)
20 fc7 (10, 4096)
21 fc8a (10, 365)
22 prob (10, 365)

如何更改此代码以使输出格式为:

 layer_number  layer_name  input_shape   output_shape  

没有直接查询父图层以查看它给出的输出?

1 个答案:

答案 0 :(得分:1)

您可以修改this answer中的代码,逐层迭代网络:

def dont_forget_to_thank_me_later(net):
  for li in xrange(len(net.layers)):  # for each layer in the net
  print "{}\t{}\t".format(li, net._layer_names[li]),      
  # for each input to the layer (aka "bottom") print its name and shape
  for bi in list(net._bottom_ids(li)):
    print "{} ({}) ".format(net._blob_names[bi], net.blobs[net._blob_names[bi]].data.shape),
  print "\t"
  # for each output of the layer (aka "top") print its name and shape
  for bi in list(net._top_ids(li)):
    print "{} ({}) ".format(net._blob_names[bi], net.blobs[net._blob_names[bi]].data.shape) 
  print ""  # end of line

请注意,图层可能包含多个输入或多个输出...