简体   繁体   中英

Caffe Copy PreTrained Weights of AlexNet to custom network that has Two AlexNets

I am trying to build a network that contains two image inputs. Each image will go through a network simultaneous with late fusion that will merge and give one outputs. I use a diagram below to show what I need (ps: sorry my english is not so good)

在此处输入图片说明

My network defined in caffe prototxt model definition file which contains exact AlexNet defined twice upto the Pool 5. For first network the layers has same name as in AlexNet while for the second net I added a "_1" suffix to each layer name. My question is how can i copy the pretained weight?

For Eg: my convolution layer 1 of each network is as follows. Note that for conv1 the pretrained weights can easily be copied since the layer name is same as one in pretrained model. However of conv1_1 the same is different so I am afraid I cannot copy the pretrained weights? Or is there a way to do this even is the layer names are different?

layer {
  name: "conv1"
  type: "Convolution"
  bottom: "data1"
  top: "conv1"
  param {
    lr_mult: 0
    decay_mult: 1
  }
  param {
    lr_mult: 0
    decay_mult: 0
  }
  convolution_param {
    num_output: 96
    kernel_size: 11
    stride: 4
    weight_filler {
      type: "gaussian"
      std: 0.01
    }
    bias_filler {
      type: "constant"
      value: 0
    }
  }
}


layer {
  name: "conv1_1"
  type: "Convolution"
  bottom: "data2"
  top: "conv1_1"
  param {
    lr_mult: 0
    decay_mult: 1
  }
  param {
    lr_mult: 0
    decay_mult: 0
  }
  convolution_param {
    num_output: 96
    kernel_size: 11
    stride: 4
    weight_filler {
      type: "gaussian"
      std: 0.01
    }
    bias_filler {
      type: "constant"
      value: 0
    }
  }
}

I presume that you are trying to finetune the whole network after initialization, otherwise you could simply use features extracted from AlexNet and start your training at the FC layer. For finetuning, you will need to copy the weights on the first network (one with the same names), and have second network share the weights with the first one. Take a look at this thread. Or rather this reply from Evan Shelmar.

I did something similar, here you can see the Siamese Network with Identical AlexNet. Identical AlexNet for Siamese Network . Here is prototxt file

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM