I want to set up a caffe CNN with python, using caffe.NetSpec() interface. Although I saw we can put test net in solver.prototxt, I would like to w
Although several answers have been given, none covers a more real-world scenario where you don't even know (at the moment of writing code) the names of your layers. For example when you're assembling a network from smaller blocks, you can't write:
n.data = L.Data(#...
n.test_data = L.Data(#...
Because every next instantiation of the block would overwrite data and test_data (or batchnorm, which is more likely to be put in blocks).
Fortunately, you can assign to the NetSpec object via __getitem__, like so:
layer_name = 'norm{}'.format(i) #for example
n[layer_name + '_train'] = L.Data(#...
n[layer_name + '_test'] = L.Data(#...