1. 程式人生 > >深度學習—caffe製作lmdb資料來源

深度學習—caffe製作lmdb資料來源

前提: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裡面找到資料來源

在這裡插入圖片描述