caffe: model definition: write same layer with different phase using caffe.NetSpec()

前端 未结 5 712
野性不改
野性不改 2020-12-03 23:00

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

5条回答
  •  隐瞒了意图╮
    2020-12-03 23:37

    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(#...
    

提交回复
热议问题