caffe使用之——将自己的数据生成lmdb

来源:互联网 发布:php可以编译吗 编辑:程序博客网 时间:2024/05/19 16:50

1,准备文件目录

在caffe/examples/下新建my_image文件夹

下面在新建data文件夹以存放数据,建lmdbtest文件夹存放lmdb文件

2,数据准备

data文件夹下新建train,val文件夹分别存放用于训练和验证的数据

建立train.txt文件,生成图片的目录+标签,最好打乱一下

home/alice/caffe/examples/my_image/data/train/n02121620_3678.JPEG 0home/alice/caffe/examples/my_image/data/train/n02084071_13.JPEG 1home/alice/caffe/examples/my_image/data/train/n02084071_15328.JPEG 1home/alice/caffe/examples/my_image/data/train/n02084071_23907.JPEG 1home/alice/caffe/examples/my_image/data/train/n02121620_25290.JPEG 0home/alice/caffe/examples/my_image/data/train/n02121620_3420.JPEG 0home/alice/caffe/examples/my_image/data/train/n02084071_7987.JPEG 1home/alice/caffe/examples/my_image/data/train/n02121620_4769.JPEG 0home/alice/caffe/examples/my_image/data/train/n02084071_5399.JPEG 1home/alice/caffe/examples/my_image/data/train/n02121620_4568.JPEG 0home/alice/caffe/examples/my_image/data/train/n02121620_30404.JPEG 0home/alice/caffe/examples/my_image/data/train/n02121620_25411.JPEG 0

建立val.txt文件,同上

home/alice/caffe/examples/my_image/data/val/n02121620_293.JPEG 0home/alice/caffe/examples/my_image/data/val/n02084071_32440.JPEG 1home/alice/caffe/examples/my_image/data/val/n02121620_1028.JPEG 0home/alice/caffe/examples/my_image/data/val/n02121620_1395.JPEG 0home/alice/caffe/examples/my_image/data/val/n02084071_29164.JPEG 1home/alice/caffe/examples/my_image/data/val/n02512053_929.JPEG 2home/alice/caffe/examples/my_image/data/val/n02084071_32981.JPEG 1home/alice/caffe/examples/my_image/data/val/n02512053_2034.JPEG 2home/alice/caffe/examples/my_image/data/val/n02512053_815.JPEG 2home/alice/caffe/examples/my_image/data/val/n02121620_1208.JPEG 0home/alice/caffe/examples/my_image/data/val/n02084071_30600.JPEG 1home/alice/caffe/examples/my_image/data/val/n02512053_1829.JPEG 2home/alice/caffe/examples/my_image/data/val/n02084071_35839.JPEG 1home/alice/caffe/examples/my_image/data/val/n02121620_68.JPEG 0home/alice/caffe/examples/my_image/data/val/n02512053_38.JPEG 2
建立words。txt文件

0 cat1 dog2 fish

3,复制creat_imagenet.sh到my_image目录下

修改参数

#!/usr/bin/env sh# Create the imagenet lmdb inputs# N.B. set the path to the imagenet train + val data dirsset -eEXAMPLE=examples/my_image/lmdbtest    #存放lmdb的文件夹目录DATA=examples/my_image/data  #tain.txt 等文件所在目录TOOLS=build/tools #调用caffe工具TRAIN_DATA_ROOT=/  #此类目录与train.txt val.txt文件下的目录结合为每个图片的完整目录VAL_DATA_ROOT=/# 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=256else  RESIZE_HEIGHT=0  RESIZE_WIDTH=0fiif [ ! -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 1fiif [ ! -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 1fiecho "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 val lmdb..."GLOG_logtostderr=1 $TOOLS/convert_imageset \    --resize_height=$RESIZE_HEIGHT \    --resize_width=$RESIZE_WIDTH \    --shuffle \    $VAL_DATA_ROOT \    $DATA/val.txt \    $EXAMPLE/val_lmdbecho "Done."
运行
 ./examples/my_image/create_myimagenet.sh

成功则






阅读全文
0 0
原创粉丝点击