Guided backpropagation for Caffe

290 visualizzazioni
Passa al primo messaggio da leggere

volo...@missinglink.ai

da leggere,
16 mag 2017, 11:46:5916/05/17
a Caffe Users
Hello everyone. 
I'm trying to implement guided backprop for caffe and i have some difficulties.
I am using ResNet-152 as a starting point.
1. Why some layer names from net._layer_names are not present in net.blobs.keys() ?
2. How do i implement my custom layer for ReLU? I would like to override only backward() method but it seems like i need to implement setup() and forward() as well?
3. What is the best way to substitute "on the fly" all relu layers of a net with my custom layers? 

Any help would be highly appreciated.
Thanks in advance
Volodymyr

Przemek D

da leggere,
17 mag 2017, 04:31:2517/05/17
a Caffe Users
1. Because net._layer_names is a vector of layer names while net.blobs.keys() is a list of blob names. Some layers don't produce new blobs (often dropout, ReLU, which are in-place operations), so for their entries in _layer_names you will not find any corresponding ones in blobs. Also, you should not assume that a layer will produce a blob of exactly the same name as the layer - in this case you should look at net.top_names and net.bottom_names which are OrderedDicts binding blobs to layers by name.
2. I'm not a C++ magician but looking at ReLU code, it doesn't look too difficult to derive your custom layer from ReLU. I see no reason why you should implement setup(), since ReLU itself does not (inheriting it from the abstract Layer, see layer.hpp). Might indeed have to implement forward() but again, my understanding of caffe C++ code is limited, so take my words on that point with even a few grains of salt.
3. Once your model is loaded, there's nothing that can be done (to my knowledge), so you need to modify your network at the prototxt level. I suppose you could get away with simple text substitution there, but a more elegant (and less error-prone) solution would be to use NetParameter, kind of like so:
from google.protobuf import text_format
model = caffe.io.caffe_pb2.NetParameter()
text_format
.Merge(open('path_to_my_model.prototxt').read(), model)
for x in model.layer:
   
if x.type == u'ReLU':
        x
.type = u'myReLU'
open
('output.prototxt', 'w').write(str(model))
Rispondi a tutti
Rispondi all'autore
Inoltra
0 nuovi messaggi