如何在pycaffe中获取图层类型?

How can I get layer type in pycaffe?

是否可以在 pycaffe 中获取每一层的类型(例如:卷积、数据等)? 我搜索了提供的示例,但找不到任何内容。目前我正在使用图层名称来完成我的工作,这是非常糟糕和有限的。

很简单!

import caffe
net = caffe.Net('/path/to/net.prototxt', '/path/to/weights.caffemodel', caffe.TEST)

# get type of 5-th layer
print "type of 5-th layer is ", net.layers[5].type

要在图层名称和索引之间进行映射,您可以使用这个简单的技巧:

idx = list(net._layer_names).index('my_layer')
print "The index of \'my_layer\' is ", idx, " and the type is ", net.layers[idx].type