Cannot copy param 0 weights from layer 'conv6'; shape mismatch. Source param shape is 21 512 1 1

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/w_q_q2017/article/details/83023738

今天在使用别人的模型训练自己的数据时候,遇到了如下错误:

Cannot copy param 0 weights from layer 'conv6'; shape mismatch.  Source param shape is 21 512 1 1 (10752); target param shape is 5 512 1 1 (2560). To learn this layer's parameters from scratch rather than copying from a saved net, rename the layer.
*** Check failure stack trace: ***
    @     0x7fd7a4235dbd  google::LogMessage::Fail()
    @     0x7fd7a4237c5d  google::LogMessage::SendToLog()
    @     0x7fd7a42359ac  google::LogMessage::Flush()
    @     0x7fd7a423857e  google::LogMessageFatal::~LogMessageFatal()
    @     0x7fd7a48db897  caffe::Net<>::CopyTrainedLayersFrom()
    @     0x7fd7a48e3c62  caffe::Net<>::CopyTrainedLayersFromBinaryProto()
    @     0x7fd7a48e3cc6  caffe::Net<>::CopyTrainedLayersFrom()
    @           0x406764  CopyLayers()
    @           0x408315  train()
    @           0x405c4c  main
    @     0x7fd7a2d93f45  (unknown)
    @           0x40641d  (unknown)
Aborted (core dumped)

原因:在conv6层预训练的模型输出类别数目是21,而我的数目是5,所以出现了错误。所以要从零开始学习这个层的参数,而不是从保存的网络中复制,重命名该层。

解决方法:将conv6改为conv6_6

原来的层:

layer {
  name: "conv6"
  type: "Convolution"
  bottom: "conv5_4"
  top: "conv6"
  param {
    lr_mult: 10
    decay_mult: 1
  }
  param {
    lr_mult: 20
    decay_mult: 1
  }
  convolution_param {
    num_output: 5
    kernel_size: 1
    stride: 1
    weight_filler {
      type: "msra"
    }
    bias_filler {
      type: "constant"
      value: 0
    }
  }
}

修改后的层:

layer {
  name: "conv6_6"
  type: "Convolution"
  bottom: "conv5_4"
  top: "conv6_6"
  param {
    lr_mult: 10
    decay_mult: 1
  }
  param {
    lr_mult: 20
    decay_mult: 1
  }
  convolution_param {
    num_output: 5
    kernel_size: 1
    stride: 1
    weight_filler {
      type: "msra"
    }
    bias_filler {
      type: "constant"
      value: 0
    }
  }
}

猜你喜欢

转载自blog.csdn.net/w_q_q2017/article/details/83023738