【问题标题】:Reading encoded image data from lmdb database in caffe从 caffe 的 lmdb 数据库中读取编码的图像数据
【发布时间】:2016-12-18 04:58:29
【问题描述】:

我对使用 caffe 比较陌生,并且正在尝试创建可以(稍后)调整的最小工作示例。我可以毫无困难地将 caffe 的示例与 MNIST 数据一起使用。我下载了 image-net 数据 (ILSVRC12) 并使用 caffe 的工具将其转换为 lmdb 数据库:

$CAFFE_ROOT/build/install/bin/convert_imageset -shuffle -encoded=true top_level_data_dir/ fileNames.txt lmdb_name

创建一个包含编码 (jpeg) 图像数据的 lmdb。原因是编码后的 lmdb 约为 64GB,而未编码约为 240GB。

我描述网络的 .prototxt 文件是最小的(一对内积层,主要是从 MNIST 示例中借来的——这里不求准确,我只是想要一些工作)。

name: "example"
layer {
  name: "imagenet"
  type: "Data"
  top: "data"
  top: "label"
  include {
    phase: TRAIN
  }
  transform_param {
    scale: 0.00390625
  }
  data_param {
    source: "train-lmdb"
    batch_size: 100
    backend: LMDB
  }
}
layer {
  name: "imagenet"
  type: "Data"
  top: "data"
  top: "label"
  include {
    phase: TEST
  }
  transform_param {
    scale: 0.00390625
  }
  data_param {
    source: "test-lmdb"
    batch_size: 100
    backend: LMDB
  }
}
layer {
  name: "ip1"
  type: "InnerProduct"
  bottom: "data"
  top: "ip1"
  param {
    lr_mult: 1
  }
  param {
    lr_mult: 2
  }
  inner_product_param {
    num_output: 1000
    weight_filler {
      type: "xavier"
    }
    bias_filler {
      type: "constant"
    }
  }
}
layer {
  name: "relu1"
  type: "ReLU"
  bottom: "ip1"
  top: "ip1"
}
layer {
  name: "ip2"
  type: "InnerProduct"
  bottom: "ip1"
  top: "ip2"
  param {
    lr_mult: 1
  }
  param {
    lr_mult: 2
  }
  inner_product_param {
    num_output: 1000
    weight_filler {
      type: "xavier"
    }
    bias_filler {
      type: "constant"
    }
  }
}
layer {
  name: "accuracy"
  type: "Accuracy"
  bottom: "ip2"
  bottom: "label"
  top: "accuracy"
  include {
    phase: TEST
  }
}
layer {
  name: "loss"
  type: "SoftmaxWithLoss"
  bottom: "ip2"
  bottom: "label"
  top: "loss"
}

当 train-lmdb 未编码时,此 .prototxt 文件可以正常工作(准确性极差,但 caffe 不会崩溃)。但是,如果 train-lmdb 已编码,则会出现以下错误:

data_transformer.cpp:239] Check failed: channels == img_channels (3 vs. 1)

问题:我必须在 .prototxt 文件中设置一些“标志”来表明 train-lmdb 是编码图像吗? (可能必须为测试数据层 test-lmdb 提供相同的标志。)

一点研究:

用谷歌搜索,我发现了一个看起来很有希望的resolved issue。但是,将 'force_encoded_color' 设置为 true 并没有解决我的问题。

我还发现this 的答案对创建 lmdb 非常有帮助(特别是启用编码的说明),但是,没有提到应该做什么,以便 caffe 知道图像已编码。

【问题讨论】:

    标签: neural-network deep-learning caffe lmdb


    【解决方案1】:

    你得到的错误信息:

    data_transformer.cpp:239] Check failed: channels == img_channels (3 vs. 1)
    

    表示 caffe 数据转换器期望输入 3 个channels(即彩色图像),但得到的图像只有 1 个img_channels(即灰度图像)。

    看着 ar caffe.proto 似乎你应该在transformation_param 处设置参数:

    layer {
      name: "imagenet"
      type: "Data"
      top: "data"
      top: "label"
      include {
        phase: TRAIN
      }
      transform_param {
        scale: 0.00390625
        force_color: true  ##  try this
      }
      data_param {
        source: "train-lmdb"
        batch_size: 100
        backend: LMDB
        force_encoded_color: true  ## cannot hurt...
      }
    }
    

    【讨论】:

    • 这似乎有效!这是否意味着数据中混入了一些灰度图像?我认为/假设它们都是彩色的(我看到的少数肯定是彩色的)。如果我在创建 lmdb 时使用了 --check_size 选项,也许我会发现这一点?我之前已将所有图像的大小调整为 256x256,因此我没有费心检查。
    • @TravisJ 我不确定--check_size 检查通道数,AFAIK 它只检查宽度和高度,但我可能错了。
    • 我假设尺寸是宽 x 高 x 深(即通道数)......但我可能错了......对 caffe 很陌生。
    猜你喜欢
    • 2016-01-12
    • 2020-04-16
    • 1970-01-01
    • 2016-09-23
    • 2020-01-12
    • 2012-07-16
    • 2019-03-21
    • 2015-06-14
    • 2015-08-26
    相关资源
    最近更新 更多