在生成train.txt后,需要再生成lmdb格式的数据。操作如下:
在自己的数据准备方面,我只准备了train 和test。没有验证集。。。。。
在caffe根目录下新建一个myself文件夹,里面包含两个文件夹:Build_lmdb和Data_train,其中,Build_lmdb中包含了
create_imagenet.sh文件,其内容如下:
#!/usr/bin/env sh
# Create the imagenet lmdb inputs
# N.B. set the path to the imagenet train + val data dirs
set -e
EXAMPLE=myself/Build_lmdb #生成模型训练数据文件夹,即create_imagenet.sh所在文件夹
DATA=myself/Data_train #python脚本处理数据路径,即生成的文件列表.txt文件所在文件夹
TOOLS=build/tools #caffe的工具库,不用更改
TRAIN_DATA_ROOT=/home/aa/qxq/project/fruits/ncnn-master/data/train #待处理的训练数据,即 train 训练图像库所在位置
# VAL_DATA_ROOT=/path/to/imagenet/val/
# 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_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..."
rm -rf $EXAMPLE/train_lmdb #删除已存在的lmdb格式文件,若在已存在lmdb格式的文件夹下再添加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 val lmdb..."
#GLOG_logtostderr=1 $TOOLS/convert_imageset \
# --resize_height=$RESIZE_HEIGHT \
# --resize_width=$RESIZE_WIDTH \
# --shuffle \
# $VAL_DATA_ROOT \
# $DATA/val.txt \
# $EXAMPLE/ilsvrc12_val_lmdb
echo "Done."
然后在caffe目录下运行root@aa-pc:/home/caffe# sh ./myself/Build_lmdb/create_imagenet.sh
成功!就得到了:
文件