从caffe中的lmdb数据库中读取编码图像数据

问题描述 投票:3回答:1

我对使用caffe相对较新,并且正在尝试创建我可以(稍后)调整的最小工作示例。使用带有MNIST数据的caffe示例没有任何困难。我下载了图像网数据(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个回答
2
投票

您收到的错误消息:

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

意味着caffe数据变换器期望具有3个channels(即彩色图像)的输入,但是获得仅具有1个img_channels的图像(即,灰度图像)。

看看qazxsw poi看起来你应该在qazxsw poi设置参数:

caffe.proto
© www.soinside.com 2019 - 2024. All rights reserved.