[英]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) 我使用下面的图表显示我的需要(ps:对不起,我的英语不太好)
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. 我的网络在caffe prototxt模型定义文件中定义,该文件包含到池5定义两次的精确AlexNet。对于第一个网络,各层的名称与AlexNet中的名称相同,而对于第二个网络,我为每个层名称添加了“ _1”后缀。 My question is how can i copy the pretained weight? 我的问题是我该如何复制保留的重量?
For Eg: my convolution layer 1 of each network is as follows. 例如:每个网络的卷积层1如下。 Note that for conv1
the pretrained weights can easily be copied since the layer name is same as one in pretrained model. 请注意,对于conv1
,可以轻松复制预训练的权重,因为图层名称与预训练模型中的图层名称相同。 However of conv1_1
the same is different so I am afraid I cannot copy the pretrained weights? 但是conv1_1
不同,所以我担心无法复制预训练的权重? 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. 我假设您正在尝试在初始化后微调整个网络,否则您可以简单地使用从AlexNet提取的功能并在FC层开始培训。 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. 或者说这个埃文Shelmar答复。
I did something similar, here you can see the Siamese Network with Identical AlexNet. 我做了类似的事情,在这里您可以看到带有相同AlexNet的暹罗网络。 Identical AlexNet for Siamese Network . 与Siamese网络相同的AlexNet 。 Here is prototxt file 这是prototxt文件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.