Reputation: 71
I was trying to implement the siamese network described in "Seeing the Forest from the Trees: A Holistic Approach to Near-infrared Heterogeneous Face Recognition, CVPRW 2016". The approach involves initialising the two channels of siamese network with the same pretrained weights of a single channel model. This is pretty straigtforward in caffe when the weights are shared. But I'm looking to implement it in such a way that the weights are not shared (has to learn together without the same weights by employing the contrastive loss as mentioned in the above paper, but the initializations on both channels has to be the same). I couldn't find a way to implement it in caffe. Any of you have any suggestions for neat approaches or hacks to do this in caffe? Thanks.
Upvotes: 3
Views: 586
Reputation: 1483
You can load source and siamese destination model in python using caffe :
netSrc = caffe.Net('deploySrc.prototxt',
'src.caffemodel',
caffe.TEST)
netDst = caffe.Net('deployDst.prototxt',
'dst.caffemodel',
caffe.TEST)
Then you can assign per layer weights from source to destination. Say you want to copy layer conv from source to convA and convB copies in siamese network:
netDst.params['convA'] = netSrc.params['conv']
netDst.params['convB'] = netSrc.params['conv']
Then save results to new caffemodel :
netDst.save('dstInitialized.caffemodel')
Upvotes: 1