如何通过 Pycaffe 获取图层的输出形状

How to get the output shape of a layer via Pycaffe

标题已包含完整问题:如何使用 Pycaffe 获取 Caffe 模型给定层的输出形状?

我有一个 caffe.Net() object,现在我想要模型中特定层的输出形状。

给定图层名称,您可以通过以下方式获取其索引:

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

一旦你有了 l_idx,你就可以得到它的输出(又名 "top"s):

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

每个"top"你可以获得信息

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

可以找到有关如何通过 pycaffe 接口访问 net 结构的更详细示例