前提:ubuntu系统,安装了caffe,python。
Caffe深度学习训练网络模型需要的数据的格式分三种,数据直接来源于图片,使用lmdb数据源,使用hdf5数据源。
本文档把图片制作成lmdb数据源
首先任何位置新建文件夹:比如我新建了xytest文件夹
在文件夹xytest下新建train 再新建分类的文件夹比如0和1
用来分别存放红绿灯图片。
在文件夹下新建val文件夹用来存放测试源的数据就是测试的图片。
在xytest文件夹下新建train.txt和val.txt
比如train.txt文件内容 1/red_0223.jpg 1
1/red_0223.jpg 就是train文件夹下的图片的路径 后面的1 就是类别
Val.txt就是文件名空格加类别
在xytest下新建.sh文件命名随便比如我新建为make_image_lmdb.sh
文件内容如下:(caffe提供本脚本)
reate the imagenet lmdb inputs
#N.B. set the path to the imagenet train + val data dirs
set -e
EXAMPLE=lmdb #xytest文件夹的路径
DATA=~/xytest/ #xytest文件夹的路径
TOOLS=~/caffe/build/tools #caffe安装路径+build/tools
TRAIN_DATA_ROOT=~/xytest/train/ #训练数据的路径
VAL_DATA_ROOT=~/xytest/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…”
GLOG_logtostderr=1 KaTeX parse error: Expected 'EOF', got '\
' at position 24: …nvert_imageset \̲
̲ --resize_he…RESIZE_HEIGHT
–resize_width=$RESIZE_WIDTH
–shuffle
$TRAIN_DATA_ROOT
$DATA/train.txt
$EXAMPLE/xytest_train_lmdb #制作的数据源名称
echo “Creating val lmdb…”
GLOG_logtostderr=1 KaTeX parse error: Expected 'EOF', got '\
' at position 24: …nvert_imageset \̲
̲ --resize_he…RESIZE_HEIGHT
–resize_width=$RESIZE_WIDTH
–shuffle
$VAL_DATA_ROOT
$DATA/val.txt
$EXAMPLE/xytest_val_lmdb #制作的测试源名称
echo “Done.”
新建lmdb文件夹用来存放数据源
然后运行脚本make_image_lmdb.sh开始制作
制作完成后可在lmdb里面找到数据源