简体   繁体   English

Caffe将AlexNet的预训练权重复制到具有两个AlexNet的自定义网络

[英]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.

相关问题 用Caffe训练暹罗网络 - Training a Siamese Network with Caffe 在Caffe中训练连体网络 - Training Siamese Network in Caffe 是否可以修改预训练卷积神经网络的层? - Is it possible to modify layers of a pretrained convolutional neural network? 仅使用预先训练的火炬网络的某些层 - Use only certain layers of pretrained torchvision network 使用预训练网络提取的图像特征负值的含义是什么 - What is meaning of negative value of features of images extracted using pretrained network LMDB文件以及它们如何用于caffe深度学习网络 - LMDB files and how they are used for caffe deep learning network 我应该如何使用预训练模型优化神经网络进行图像分类 - How should I optimize neural network for image classification using pretrained models 如何在一个通道上使用 AlexNet - How to use AlexNet with one channel 解析文本格式caffe.NetParameter时出错:54:17:消息类型“ caffe.ConvolutionParameter”没有名为“ sparse_ratio”的字段 - Error parsing text-format caffe.NetParameter: 54:17: Message type “caffe.ConvolutionParameter” has no field named “sparse_ratio” 我可以使用 Python 和 Pillow 将彩色图像转换为灰度,并使用自定义权重而不是内置的亮度变换权重吗? - Can I convert a color image into greyscale using Python and Pillow with custom weights instead of the built-in luma transform weights?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM