测试时出现Caffe错误:检查失败:count_ == proto.data_size()(9408与0)

时间:2018-09-28 09:34:24

标签: conv-neural-network caffe pycaffe

我已经在Caffe上训练了一个googlenet,现在我想进行测试,因此我使用了deploy.prototxt和预先训练的权重并将其分配给Net。但是我收到此错误(有趣的是,在提示网络初始化的消息之后)

I0927 17:51:41.171922  5336 net.cpp:255] Network initialization done.
I0927 17:51:41.195708  5336 net.cpp:744] Ignoring source layer label_imgdata_1_split
F0927 17:51:41.195746  5336 blob.cpp:496] Check failed: count_ == proto.data_size() (9408 vs. 0) 

显然,由于此处的字符限制,我无法复制粘贴整个原型文件。我要添加的外观是没有相同或不相同的主体(阶段:TRAIN和阶段:TEST of c的部分除外)。正文与此处的示例相同:https://github.com/BVLC/caffe/tree/master/models/bvlc_googlenet

一个注意事项:我在训练过程中读入hdf5数据,而我在测试过程中只使用python脚本(我执行与创建hdf5数据时相同的预处理,所以我不使用caffe的io.transform,完全不减去均值(这样可以更好地工作))-尽管错误是在初始化过程中发生的,而未读入数据部分

我的部署如下:

name: "GoogleNet"
layer {
  name: "data"
  type: "Input"
  top: "data"
  input_param { shape: { dim: 10 dim: 3 dim: 224 dim: 224 } }
}

.....

  layer {
  name: "loss3/classifier"
  type: "InnerProduct"
  bottom: "pool5/7x7_s1"
  top: "loss3/classifier"
  param {
    lr_mult: 1
    decay_mult: 1
  }
  param {
    lr_mult: 2
    decay_mult: 0
  }
  inner_product_param {
    num_output: 7
    weight_filler {
      type: "xavier"
    }
    bias_filler {
      type: "constant"
      value: 0
    }
  }
}

layer {
  name: "prob"
  type: "Softmax"
  bottom: "loss3/classifier"
  top: "prob"
}

这是我的火车原型的样子:

name: "GoogleNet"

layer {
  name: "imgdata"
  type: "HDF5Data"
  top: "label"
   hdf5_data_param {
      source: "/media/DATA/DetDataWOMeanSubt/train_h5_list.txt"
      batch_size: 64
      shuffle: true
      }
  include {
    phase: TRAIN
  }

}

layer {
  name: "imgdata"
  type: "HDF5Data"
  top: "imgdata"
  top: "label"
   hdf5_data_param {
      source: "/media/DATA/DetDataWOMeanSubt/eval_h5_list.txt"
      batch_size: 128
      shuffle: true
      }
 include {
    phase: TEST
  }
}

....

layer {
  name: "loss3/classifier"
  type: "InnerProduct"
  bottom: "pool5/7x7_s1"
  top: "loss3/classifier"
  inner_product_param {
    num_output: 7
    weight_filler {
      type: "xavier"
    }
    bias_filler {
      type: "constant"
      value: 0
    }
  }
}
layer {
  name: "loss"
  type: "SoftmaxWithLoss"
  bottom: "loss3/classifier"
  bottom: "label"
  top: "loss"
  loss_weight: 1
}
layer {
  name: "accuracy/top-1"
  type: "Accuracy"
  include { phase: TEST }
  bottom: "loss3/classifier"
  bottom: "label"
  top: "accuracy/top-1"
  accuracy_param { top_k: 1 }
}

这是我初始化网络的方法:

net = caffe.Net(model_def,      # defines the structure of the model
                model_weights,  # contains the trained weights
                caffe.TEST)     # use test mode (e.g., don't perform dropout)

在网络初始化之前,我确实会收到此警告(无论如何,它似乎仍会继续初始化网络)

DEPRECATION WARNING - deprecated use of Python interface
W0927 17:51:40.486548  5336 _caffe.cpp:140] Use this instead (with the named "weights" parameter):
W0927 17:51:40.486551  5336 _caffe.cpp:142] Net('/home/x/Desktop/caffe-caffe-0.16/models/bvlc_googlenet/deploy.prototxt', 1, weights='/home/x/Desktop/caffe-caffe-0.16/models/bvlc_googlenet/logs_iter_60000.caffemodel')

(但是,当我按照建议进行操作时,则无效)

在使用Caffe之前,我已经进行了很多次测试,我不知道为什么它不起作用。

1 个答案:

答案 0 :(得分:0)

如果有人想知道的话,事实证明我已经用不同版本的caffe训练了该模型,并试图与另一个模型进行测试。我的计算机上安装了两个版本,看来我只是在测试中使用LD_LIBRARY_PATH中定义的python脚本(为了进行培训,我直接引用并使用了正在构建的caffe工具)导入较旧的版本。版本之间的差异不是很大,但是在读取prototoxt时似乎不匹配。