【问题标题】:guide to use caffe convert_imageset.cpp and making lmdb [duplicate]使用 caffe convert_imageset.cpp 和制作 lmdb 的指南 [重复]
【发布时间】:2016-11-01 00:02:22
【问题描述】:

我是 Caffe 的新手,如果有人指导我,我将不胜感激。我将使用 convert_imagenet.cpp 从 jpg 制作 lmdb,但无法成功。 create.sh的内容如下:

#!/usr/bin/env sh
# Create the caltech101 lmdb inputs
# N.B. set the path to the caltech101 train + val data dirs

EXAMPLE=examples/caltech101
DATA=data/caltech101
TOOLS=build/tools

TRAIN_DATA_ROOT=examples/caltech101/caltech101_train/
VAL_DATA_ROOT=examples/caltech101/caltech101_train/

# Set RESIZE=true to resize the images to 256x256. Leave as false if images have
# already been resized using another tool.
RESIZE=true
if $RESIZE; then
  RESIZE_HEIGHT=256
  RESIZE_WIDTH=256
else
  RESIZE_HEIGHT=0
  RESIZE_WIDTH=0
fi

if [ ! -d "$TRAIN_DATA_ROOT" ]; then
  echo "Error: TRAIN_DATA_ROOT is not a path to a directory: $TRAIN_DATA_ROOT"
  echo "Set the TRAIN_DATA_ROOT variable in create_caltech101.sh to the path" \
       "where the caltech101 training data is stored."
  exit 1
fi

if [ ! -d "$VAL_DATA_ROOT" ]; then
  echo "Error: VAL_DATA_ROOT is not a path to a directory: $VAL_DATA_ROOT"
  echo "Set the VAL_DATA_ROOT variable in create_caltech101.sh to the path" \
       "where the caltech101 validation data is stored."
  exit 1
fi

echo "Creating train lmdb..."

GLOG_logtostderr=1 $CAFFE_ROOT/build/tools/convert_imageset \
    --resize_height=256 \
    --resize_width=256 \
    --shuffle \
    $CAFFE_ROOT/examples/caltech101/caltech101_train/ \
    $CAFFE_ROOT/data/caltech101/caltech101_train.txt \
    $CAFFE_ROOT/examples/caltech101/caltech101_train_lmdb

echo "Creating val lmdb..."

GLOG_logtostderr=1 $TOOLS/convert_imageset \
    --resize_height=256 \
    --resize_width=256 \
    --shuffle \
    $CAFFE_ROOT/examples/caltech101/caltech101_train/ \
    $CAFFE_ROOT/data/caltech101/caltech101_test.txt \
    $CAFFE_ROOT/examples/caltech101/caltech101_test_lmdb

echo "Done."

另外,执行create.sh后,输出为:

root@samar-Dell-Precision-M3800:~/caffe# ./examples/caltech101/create_caltech101.sh
Creating train lmdb...
I0701 20:17:34.589217  3256 convert_imageset.cpp:86] Shuffling data
I0701 20:17:34.589913  3256 convert_imageset.cpp:89] A total of 84 images.
I0701 20:17:34.590143  3256 db_lmdb.cpp:35] Opened lmdb /home/samar/caffe/examples/caltech101/caltech101_train_lmdb
E0701 20:17:34.645048  3256 io.cpp:80] Could not open or find file /home/samar/caffe/examples/caltech101/caltech101_train/
I0701 20:17:34.768301  3256 convert_imageset.cpp:153] Processed 83 files.
Creating val lmdb...
I0701 20:17:34.787917  3258 convert_imageset.cpp:86] Shuffling data
I0701 20:17:34.788311  3258 convert_imageset.cpp:89] A total of 40 images.
I0701 20:17:34.788477  3258 db_lmdb.cpp:35] Opened lmdb /home/samar/caffe/examples/caltech101/caltech101_test_lmdb
I0701 20:17:34.872882  3258 convert_imageset.cpp:153] Processed 40 files.
Done.

创建了 caltech101_train_lmdb 和 caltech101_test_lmdb 两个文件,但大小未知。

感谢您的大力帮助。

【问题讨论】:

    标签: caffe


    【解决方案1】:

    首先,对所有变量使用绝对路径:

    EXAMPLE
    DATA
    TOOLS
    
    TRAIN_DATA_ROOT
    VAL_DATA_ROOT
    

    接下来,您似乎只有 84 张图片。如果是这种情况,您的数据库将非常小。仔细检查您是否正确提供了训练和验证图像。您需要有两个文本文件 - 一个用于训练,另一个用于验证。在每个文件中,您将有两列。在每一行中,第一列包含图像的路径,第二列具有相应的标签。标签始终是一个数字。两列用空格隔开。

    【讨论】:

    • 谢谢您的回复,我按照您说的更新了上面的参数并重新运行,但是出现了如下错误。我粘贴了 train.txt 和 test.txt 的一部分,并创建了.sh 文件
    • EXAMPLE=/home/samar/caffe/examples/caltech101 DATA=/home/samar/caffe/data/caltech101/images TOOLS=/home/samar/caffe/build/tools TRAIN_DATA_ROOT=/home /samar/caffe/data/caltech101/images/VAL_DATA_ROOT=/home/samar/caffe/data/caltech101/images/
    • GLOG_logtostderr=1 $CAFFE_ROOT/build/tools/convert_imageset \ --resize_height=256 \ --resize_width=256 \ --shuffle \ $CAFFE_ROOT/data/caltech101/images/ \ $CAFFE_ROOT/data /caltech101/caltech101_train.txt \ $CAFFE_ROOT/data/caltech101/caltech101_train_lmdb #caltech101_train_lmdb 不存在。我认为它将在这一步中创建 echo "Creating val lmdb..."
    • GLOG_logtostderr=1 $TOOLS/convert_imageset \ --resize_height=256 \ --resize_width=256 \ --shuffle \ $CAFFE_ROOT/data/caltech101/images/ \ $CAFFE_ROOT/data/caltech101/caltech101_test .txt \ $CAFFE_ROOT/data/caltech101/caltech101_test_lmdb #caltech101_test_lmdb 不存在。我认为它会在这一步创建
    • cimage_0034.jpg 0 cimage_0035.jpg 0 cimage_0036.jpg 0 cimage_0037.jpg 0 image_0001.jpg 1 image_0002.jpg 1 image_0003.jpg 1 image_0004.jpg 1 image_0005.jpg 1
    【解决方案2】:

    在 lmbd 中创建数据库:

    创建火车数据文件夹 创建包含文件名标签的 train.txt 文件 创建验证数据文件夹 创建包含文件名和标签的 val.txt 文件

    *** 编辑这个文件examples/imagenet/create_imagenet.sh *************** :-)

    EXAMPLE= path to where *.lmbd folder wil be stored
    DATA= path where val.txt and train.txt is present
    TOOLS=build/tools
    
    TRAIN_DATA_ROOT=test/make_caffe_data/train/ # path to trainfiles
    VAL_DATA_ROOT=test/make_caffe_data/val/ # path to test_files
    

    设置 RESIZE=true 将图像大小调整为 256x256。如果图像有则保留为 false

    已使用其他工具调整大小。

    RESIZE=true  
    
    
    ./examples/imagenet/create_imagenet.sh 
    

    【讨论】:

      猜你喜欢
      • 2015-10-04
      • 1970-01-01
      • 2016-01-15
      • 2016-02-11
      • 2016-01-12
      • 1970-01-01
      • 2018-01-07
      • 2011-12-29
      相关资源
      最近更新 更多