【问题标题】:issues when using caffe (create_imagenet.sh) to convert my jpg to lmdb使用 caffe (create_imagenet.sh) 将我的 jpg 转换为 lmdb 时出现问题
【发布时间】:2018-06-06 18:13:01
【问题描述】:

我想做微调来训练我的 jpg。在很多文档的指导下,我主要修改了create_imagenet.sh中data、txt和tool的路径,如下:

#!/usr/bin/env sh
# This script converts the mnist data into lmdb/leveldb format,
# depending on the value assigned to $BACKEND.
set -e

EXAMPLE=/home/sun/Documents/python/fine-tuning/Oxford102/data/test
DATA_TEST=/home/sun/Documents/python/fine-tuning/Oxford102/data/test/test/
DATA_TRAIN=/home/sun/Documents/python/fine-tuning/Oxford102/data/test/train/
NOTI=/home/sun/Documents/python/fine-tuning/Oxford102/data/test
BUILD=/home/sun/Documents/caffe/build/tools

#BACKEND="lmdb"

# 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 "$DATA_TRAIN" ]; then  
  echo "Error: TRAIN_DATA_ROOT is not a path to a directory: $DATA_TRAIN"  
  echo "Set the TRAIN_DATA_ROOT variable in create_imagenet.sh to the path" \  
       "where the ImageNet training data is stored."  
  exit 1  
fi  

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

echo "Creating train lmdb..."
GLOG_logtostderr=1 $BUILD/convert_imageset \
    --resize_height=$RESIZE_HEIGHT \ 
    --resize_width=$RESIZE_WIDTH \
    --shuffle \
    $DATA_TRAIN \  
    $NOTI/info_train.txt \  
    $EXAMPLE/img_train_lmdb  

echo "Creating test lmdb..."
GLOG_logtostderr=1 $BUILD/convert_imageset \
    --resize_height=$RESIZE_HEIGHT \ 
    --resize_width=$RESIZE_WIDTH \
    --shuffle \
    $DATA_TEST \  
    $NOTI/info_test.txt \  
    $EXAMPLE/img_test_lmdb

echo "Done."

然后我在终端中运行“sudo sh create_oxford.sh”,但一无所获。

running result in shell

另外,我的文档结构如下:

在 /home/sun/Documents/python/fine-tuning/Oxford102/data/test 中,我放置了 info_test.txt、info_train.txt、test(jpg 用于测试)和 train(jpg 用于火车)。在txt中,信息类似于'image_0001.jpg 0'。

【问题讨论】:

    标签: linux machine-learning caffe lmdb


    【解决方案1】:

    1)我成功运行了代码。

    2) 当命令行参数未正确传递时,我得到了用法但什么也没有。

    3) 您可以使用以下命令调试您的 shell 脚本:set -vx 它将显示实际的争论如下:

    +/home/u5652/.conda/envs/riCffAlex3.6/bin/convert_imageset --resize_height=256 --resize_width=256

    convert_imageset:将一组图像转换为leveldb/lmdb 用作 Caffe 输入的格式。 用法: convert_imageset [FLAGS] ROOTFOLDER/ LISTFILE DB_NAME .....................

    根据 caffe/tools/convert_imageset.cpp:

    if (argc < 4) {
        gflags::ShowUsageWithFlagsRestrict(argv[0], "tools/convert_imageset");
        return 1;
      }
    

    最小争论应该是 4,否则它会显示用法。 你一定是因为不正确的论据而得到了使用。

    4) 我运行了以下代码并成功创建了 lmdb:

    #!/usr/bin/env sh
    set -vx
    EXAMPLE=examples/imagenet/test
    DATA=data/ilsvrc12/test
    TOOLS=~/.conda/envs/riCffAlex3.6/bin
    TRAIN_DATA_ROOT=~/caffe/data/ilsvrc12/test/train/
    VAL_DATA_ROOT=~/caffe/data/ilsvrc12/test/test/
    
    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_imagenet.sh to the path" \
           "where the ImageNet 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_imagenet.sh to the path" \
           "where the ImageNet validation data is stored."
      exit 1
    fi
    
    echo "Creating train lmdb..."
    
    GLOG_logtostderr=1 $TOOLS/convert_imageset \
        --resize_height=$RESIZE_HEIGHT \
        --resize_width=$RESIZE_WIDTH \
        --shuffle \
        $TRAIN_DATA_ROOT \
        $DATA/train.txt \
        $EXAMPLE/train_lmdb
    
    echo "Creating test lmdb..."
    
    GLOG_logtostderr=1 $TOOLS/convert_imageset \
        --resize_height=$RESIZE_HEIGHT \
        --resize_width=$RESIZE_WIDTH \
        --shuffle \
        $VAL_DATA_ROOT \
        $DATA/val.txt \
        $EXAMPLE/test_lmdb
    
    echo "Done."
    

    5) 我将详细信息的格式与您在 .txt 文件中的格式相同。我把:TestJpg.jpg 0

    注意:图片的名称和扩展名应与您输入的 .txt 相同

    试试方法。您的错误应该得到解决。

    谢谢

    【讨论】:

    • 非常感谢!我通过取消“\”并将所有参数放在一行中解决了这个问题。似乎 \ 在我的机器上没有充当连接命令。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-24
    • 2020-04-16
    • 2016-02-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多