How to change the Imagenet Caffe model?

I would like to modify the caffe ImageNet model as described below:

Since the input channel number for temporary networks is different from that of spatial networks (20 vs. 3), we average the filters of the ImageNet model first layer over the channel, and then copy the average results of 20 as initialization of temporary networks.

My question is: how can I achieve the above results? How can I open the caffe model to be able to make these changes?

I read a tutorial on clean surgery, but does not cover the necessary procedure.

Thanks for the help!

Amayer

+4
source share
1 answer

Net Surgery , . , :

  • .prototxt: : ImageNet .prototxt . , , , . , ImageNet .caffemodel .

    conv- , .prototxt, ImageNet. Caffe , , . ( , .) , . conv1b .

  • ImageNet , :

    net = caffe.Net('imagenet.prototxt', 'imagenet.caffemodel', caffe.TEST)
    
  • .

    conv_1_weights = old_net.params['conv1'][0].data
    conv_1_biases = old_net.params['conv1'][1].data
    
  • :

    conv_av_weights = np.mean(conv_1_weights, axis=1, keepdims=True)
    
  • .caffemodel , , , ImageNet:

    new_net = caffe.Net('new_network.prototxt', 'imagenet.caffemodel', caffe.TEST)
    
  • new_net.params['conv1b'][0].data[...] = conv_av_weights
    new_net.params['conv1b'][1].data[...] = conv_1_biases
    
  • .caffemodel :

    new_net.save('new_weights.caffemodel')
    
+3

Source: https://habr.com/ru/post/1663259/


All Articles