caffe学习笔记12-建立自己的数据集与均值计算

来源:互联网 发布:欧洲旅游价格知乎 编辑:程序博客网 时间:2024/05/29 12:46

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=/home/nielsen/caffe-master/examples/image_test        #设置生成的lmdb数据存放路径

DATA=/home/nielsen/caffe-master/data/image1000test200         #设置数据来源

TOOLS=/home/nielsen/caffe-master/build/tools                  #设置lmdb工具存放路径

TRAIN_DATA_ROOT=/home/nielsen/caffe-master/data/image1000test200/train/   #设置需要转换的训练集数据来源

VAL_DATA_ROOT=/home/nielsen/caffe-master/data/image1000test200/val/       #设置需要转换的验证集数据来源

# Set RESIZE=true to resize the images to 256x256. Leave as false if images have

# already been resized using another tool.

RESIZE=true             #这是设置RESIZE = true,caffe就可以帮我们修改好图片的尺寸,这里imagenet网络必须是227×227的大小输入

if $RESIZE; then

  RESIZE_HEIGHT=227

  RESIZE_WIDTH=227

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..."

#这里会调用作者已经写好的 convert_imageset 函数,通过该函数可以产生lmdb的数据,后面生成的训练集和验证集的lmdb名字需要更改

#--shuffle默认为true,表示做乱序

#--encoded可以对图像做编码压缩

GLOG_logtostderr=1 $TOOLS/convert_imageset \

    --resize_height=$RESIZE_HEIGHT \

    --resize_width=$RESIZE_WIDTH \

    --shuffle \ 

    $TRAIN_DATA_ROOT \

    $DATA/train.txt \

    $EXAMPLE/image_test_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/image_test_val_lmdb

echo "Done."


make_imagenet_mean.sh:

#!/usr/bin/env sh

# Compute the mean image from the imagenet training lmdb 只需要training的lmdb数据即可,不需要原数据

# N.B. this is available in data/ilsvrc12

#不要在路径前面多加空格

EXAMPLE=/home/nielsen/caffe-master/examples/image_test     #设置lmdb数据来源

DATA=/home/nielsen/caffe-master/data/image1000test200      #设置生成的mean存放的路径

TOOLS=/home/nielsen/caffe-master/build/tools               #设置mean工具存放路径

$TOOLS/compute_image_mean $EXAMPLE/image_test_val_lmdb \

  $DATA/image_test_val_mean.binaryproto

echo "Done."

0 0
原创粉丝点击