Is it possible at all to get each layer's type (e.g: Convolution, Data, etc) in pycaffe? I searched the examples provided, but I couldn't find anything. currently I'm using layers name to do my job which is extremely bad and limiting .
Asked
Active
Viewed 1,884 times
1 Answers
3
It's easy!
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
To map between layer names and indices you can use this simple trick:
idx = list(net._layer_names).index('my_layer')
print "The index of \'my_layer\' is ", idx, " and the type is ", net.layers[idx].type

Shai
- 111,146
- 38
- 238
- 371
-
I'm getting 'ValueError: 'data' is not in list' when I want to use your second snippet of code for mapping layer names and their indexes. whats wrong? – Hossein Sep 26 '17 at 11:44
-
@Coderx7 is it possible you do not have a layer named `"data"` in your net? – Shai Sep 26 '17 at 12:29
-
I used it inside a for loop which reads layer names directly from net : https://paste.ee/p/Z1RZg I'm currently doing this: https://paste.ee/p/g4Llm – Hossein Sep 26 '17 at 12:41
-
1@Coderx7 you are confusing `blob` names and `layer` names: `blob` names are the arguments of `"top"`/`"bottom"`s while layer names are the arguments of `"name"`. For instance, you may have a `"Data"` **layer** named `"data"` producing **blobs** `"data"` and `"label"`. So you have a **blob** named `"label"` but no layer with that name. – Shai Sep 26 '17 at 12:51
-
1@Coderx7 you might find the python function in [this answer](https://stackoverflow.com/a/45208380/1714410) helpful to understand the difference between blobs and layers and how to access them correctly. – Shai Sep 26 '17 at 12:53
-
Oh, Thank you very much for the clarification. :) – Hossein Sep 26 '17 at 12:56