user1245262
user1245262

Reputation: 7505

How can I determine the input dimensions for a caffe blob

I'm trying to print out some diagnostics for a caffe net, but although I can find the shape of the data output by a blob, I cannot directly find the shape of the expected input data. For example:

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)

How can I change this code so that the output is of the form:

 layer_number  layer_name  input_shape   output_shape  

without directly querying the parent layer to see what output it gives?

Upvotes: 1

Views: 1290

Answers (1)

Shai
Shai

Reputation: 114866

You can modify the code in this answer to iterate the net layer by layer:

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

Note that a layer may have more than one input, or more than one output...

Upvotes: 1

Related Questions