【问题标题】:Image Channel Mismatch in CaffeCaffe 中的图像通道不匹配
【发布时间】:2017-01-05 09:27:55
【问题描述】:

我知道在 caffe 用户组中问这个问题可能会更好,但我无法访问用户组并且不知道在哪里提出问题,因为我不确定这是否需要在 git 中作为问题提出。无论如何,我正在做的是:

我有一组灰度图像,我想用它们来训练使用 caffe 的 CNN。我正在使用提供的 caffenet 模型定义的修改版本,稍作修改(即:通道 = 1 而不是 3,因为我有灰度图像)。到目前为止,我使用 imagenet 提供的平均图像来训练 CNN,它训练并生成了结果。现在我想计算我自己的训练/测试数据集的图像平均值并将其用作平均图像,因此我使用 build/tools/ 中的文件来执行此操作。它需要图像在 lmdb 中,所以我首先使用 convert_imageset 将图像转换为 lmdb,然后使用 compute_mean 计算平均值。我确保在使用 convert_imageset 时使用 --gray 标志,因为我的图像是灰度的。当我重新运行 caffe 时,出现以下错误。据我了解,这是一个渠道不匹配,但我不知道如何解决这个问题。非常感谢您对此的任何帮助。

I0829 20:41:50.429733 17065 layer_factory.hpp:77] Creating layer data
I0829 20:41:50.429764 17065 net.cpp:100] Creating Layer data
I0829 20:41:50.429769 17065 net.cpp:408] data -> data
I0829 20:41:50.429790 17065 net.cpp:408] data -> label
I0829 20:41:50.429805 17065 data_transformer.cpp:25] Loading mean file from: data/flickr_style/train_mean.binaryproto
I0829 20:41:50.438251 17065 image_data_layer.cpp:38] Opening file data/flickr_style/train.txt
I0829 20:41:50.446666 17065 image_data_layer.cpp:58] A total of 31740 images.
I0829 20:41:50.451941 17065 image_data_layer.cpp:85] output data size: 10,3,227,227
I0829 20:41:50.459661 17065 net.cpp:150] Setting up data
I0829 20:41:50.459692 17065 net.cpp:157] Top shape: 10 3 227 227 (1545870)
I0829 20:41:50.459697 17065 net.cpp:157] Top shape: 10 (10)
I0829 20:41:50.459699 17065 net.cpp:165] Memory required for data: 6183520
I0829 20:41:50.459707 17065 layer_factory.hpp:77] Creating layer conv1
I0829 20:41:50.459728 17065 net.cpp:100] Creating Layer conv1
I0829 20:41:50.459733 17065 net.cpp:434] conv1 <- data
I0829 20:41:50.459744 17065 net.cpp:408] conv1 -> conv1
F0829 20:41:50.463794 17106 data_transformer.cpp:257] Check failed: img_channels == data_mean_.channels() (3 vs. 1) 
*** Check failure stack trace: ***
    @     0x7f0712106daa  (unknown)
    @     0x7f0712106ce4  (unknown)
    @     0x7f07121066e6  (unknown)
    @     0x7f0712109687  (unknown)
    @     0x7f071287d6cd  caffe::DataTransformer<>::Transform()
    @     0x7f07127fde60  caffe::ImageDataLayer<>::load_batch()
    @     0x7f0712839539  caffe::BasePrefetchingDataLayer<>::InternalThreadEntry()
    @     0x7f0712886020  caffe::InternalThread::entry()
    @     0x7f070a762a4a  (unknown)
    @     0x7f070603e184  start_thread
    @     0x7f07111eb37d  (unknown)
    @              (nil)  (unknown)

我在 train_val.prototxt 中有以下内容

name: "FlickrStyleCaffeNet"
layer {
  name: "data"
  type: "ImageData"
  top: "data"
  top: "label"
  include {
    phase: TRAIN
  }
  transform_param {
    mirror: true
    crop_size: 227
    mean_file: "data/ilsvrc12/imagenet_mean.binaryproto"
  }
  image_data_param {
    source: "data/flickr_style/mri_train.txt"
    batch_size: 10
    new_height: 256
    new_width: 256
  }
}

这在 deploy.prototxt 中

name: "FlickrStyleCaffeNet"
layer {
  name: "data"
  type: "Input"
  top: "data"
  input_param { shape: { dim: 10 dim: 3 dim: 227 dim: 227 } }
}

【问题讨论】:

  • 如果你有灰度图像,为什么数据层的输出形状是10 x 3 x 227 x 227
  • 我不确定,我在哪里编辑它以使其成为 10 x 1?

标签: caffe conv-neural-network pycaffe matcaffe


【解决方案1】:

您(或界面)未能调整灰度输入。 Gray只有1个输入通道(值);该模型需要 3 个通道 (RGB)。图层 top 形状中的 3 应该是 1


在您的 *.prototxt 文件中查看靠近顶部(输入层)的类似内容:

shape {
  dim: 10
  dim: 3
  dim: 227 
  dim: 227
}

这些维度是 batch_size、channels、rows 和 columns。无论您在此订单上的任何位置(应该只有一个,并且仅在输入文件中),将 3 更改为 1。

【讨论】:

  • 我已经确保在 deploy.prototxt 中使通道维度=1,我在 transform_param 中尝试了 force_gray,但没有成功。你知道如何将图层顶部形状中的 3 更改为 1 吗?
  • 我在 deploy.prototxt 中有 input_param { shape: { dim: 10 dim: 1 dim: 227 dim: 227 } } 并在我的 train_val.prototxt 上有以下内容(修改为问题以将其作为代码)
  • 您的代码仍然将第 2 维显示为 3,而不是 1。我是不是看错了 deploy.prototxt
  • 应该是 1,我对其进行了编辑,以便网络可以使用我计算的平均图像运行。
【解决方案2】:

我想出了如何做到这一点。在 train_val.prototxt 中,数据层下有一个image_data_param 部分。我必须在其中添加 is_color: false 并解决了问题。

感谢大家的cmets和回复,不胜感激。

【讨论】:

    猜你喜欢
    • 2016-01-23
    • 2016-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-29
    • 2018-10-22
    • 1970-01-01
    • 2012-02-02
    相关资源
    最近更新 更多