Multiple pathways for data through a layer in Caffe

前提是你 提交于 2020-01-15 04:51:46

问题


I would like to construct a network in Caffe in which the incoming data is split up initially, passes separately through the same set of layers, and is finally recombined using an eltwise layer. After this, all the parts will move as a single blob.

The layer configuration of the part of the network for which the data moves parallely will be identical, except for the learned parameters.

Is there a way to define this network in Caffe without redefining the layers through which the different parts of the data go through multiple times? In other words, is it possible to define a layer once and have multiple pathways for input and output, something like having multiple top and bottom parameters with a mapping between them?


回答1:


I don't think raw caffe's prototxt format allows for what you are after. But you can get this using caffe.NetSpec() python interface. That is, using python interface to construct the net and write the prototxt file.

import caffe
from caffe import layers as L
ns = caffe.NetSpec()
ns.data, ns.label = L.Data(ntop=2, name='data', data_param={'source':'/path/to', 'batch_size': 32})
tops = []
for i in xrange(3):
    nm = 'path{}'.format(i)
    top = L.Convolution(ns.data, name=nm, convolution_params={'num_output':32})
    ns.__setattr__(nm, top)
    tops.append(top)
# concat
ns.concat = L.Concat(*tops, name='concat', concat_param={'axis':1})
print '{}'.format(ns.toProto())


来源:https://stackoverflow.com/questions/44366735/multiple-pathways-for-data-through-a-layer-in-caffe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!