1

The title already contains the full question: How can I get the output shape of a given layer of a Caffe model using Pycaffe?

I have a caffe.Net() object and now I want the output shape of a specific layer in the model.

Shai
  • 102,241
  • 35
  • 217
  • 344
Alex
  • 3,026
  • 2
  • 22
  • 46

1 Answers1

2

Given the layer name, you can get its index via:

l_idx = list(net._layer_names).index(my_layer_name)

Once you have l_idx, you can get its outputs (aka "top"s):

tops = [(net._blob_names[bi], net.blobs[net._blob_names[bi]].data.shape) 
        for bi in list(net._top_ids(li))]

for each "top" you can get the informtation

for tn in tops:
  print "output name {} has shape {}".format(tn, net.blobs[tn].data.shape)

A more detailed example on how to access net's structure via pycaffe interface can be found here.

Shai
  • 102,241
  • 35
  • 217
  • 344