1. 程式人生 > >Caffe:製作與訓練自己的圖片資料

Caffe:製作與訓練自己的圖片資料

一、製作資料

根據上篇內容來製作資料。
我用的是中草藥的資料,包括三種藥材;
cheqianzi:700張
JianLianHua:1000張
pugongying:500張
其中的百分之二十用於test,百分之八十用於train。
test:140+200+100=440張
train:560+800+400=1760張
檔案存放如下:
這裡寫圖片描述

在data/herbal_demo/下建立兩個資料夾:
這裡寫圖片描述
分別存放test和train圖片。

二、製作資料

在examples/herbal_demo/下建立create_filelist.sh檔案
內容如下:

#!/usr/bin/env sh
DATA=data/herbal/
MY=examples/herbal_demo

echo "Create train.txt..."
rm -rf $MY/train.txt
find $DATA/train -name cq2015*.jpg | cut -d '/' -f4-5 | sed "s/$/ 1/">>$MY/train.txt
find $DATA/train -name JLHZZ*.JPG | cut -d '/' -f4-5 | sed "s/$/ 2/"
>>$MY/train.txt find $DATA/train -name py201512*.jpg | cut -d '/' -f4-5 | sed "s/$/ 3/">>$MY/train.txt echo "Create test.txt..." rm -rf $MY/test.txt find $DATA/train -name cq2015*.jpg | cut -d '/' -f4-5 | sed "s/$/ 1/">>$MY/test.txt find $DATA/train -name JLHZZ*.JPG | cut -d '/' -f4-5 | sed "s/$/ 2/"
>>$MY/test.txt find $DATA/train -name py201512*.jpg | cut -d '/' -f4-5 | sed "s/$/ 3/">>$MY/test.txt echo "All done"

$ ./examples/herbal_demo/create_filelist.sh
執行後:
生成test.txt和train.txt檔案。
這裡寫圖片描述
待續。。