大家好,放假在即,来整理一波在Linux上用caffe跑深度学习的流程,免得开学回来忘记。
以下地址均为我自己电脑上的地址,大家要照着跑请自行修改地址哦!
1.将训练和测试的图像放入examples-->images.训练图像放入train文件夹中,测试图像放入test文件夹中。
2.在自己创建的examples-->mytest中,创建creat_filelist.sh来生成对应标签train.txt和test.txt,具体代码如下:
#!/usr/bin/env sh DATA=examples/images/ MY=examples/mytest echo "Create train.txt..." rm -rf $MY/train.txt for i in 0 1 2 3 4 5 6 7 8 9 10 do find $DATA/train -name $i*.jpg|cut -d '/' -f4-5 | sed "s/$/ $i/">>$MY/train.txt done echo "Creat test.txt..." rm -rf $MY/test.txt for i in 0 1 2 3 4 5 6 7 8 9 10 do find $DATA/test -name $i*.jpg | cut -d '/' -f4-5 | sed "s/$/ $i/">>$MY/test.txt done echo "all done.."3. 在自己创建的examples-->mytest中,创建creat_mytest.sh来将train和test的图片转换成LMDB格式。具体代码如下:
#!/usr/bin/env sh MY=examples/mytest echo "Create train lmdb.." rm -rf $MY/img_train_lmdb build/tools/convert_imageset \ --shuffle \ --resize_height=224 \ --resize_width=224 \ /apps/jhinno/users/IMGLAB/2004/caffe-master/examples/images/ \ $MY/train.txt \ $MY/img_train_lmdb echo "Create test lmdb.." rm -rf $MY/img_test_lmdb build/tools/convert_imageset \ --shuffle \ --resize_height=224 \ --resize_width=224 \ /apps/jhinno/users/IMGLAB/2004/caffe-master/examples/images/ \ $MY/test.txt \ $MY/img_test_lmdb echo "ALL Done.."4.对图像取减去均值的操作,代码如下:
#!/usr/bin/env sh BUILD=build/tools EXAMPLE=examples/mytest echo "Creating arv.." rm -rf $EXAMPLE/mean.binaryproto #$BUILD/compute_image_mean.bin $EXAMPLE/img_train_lmdb \ #$EXAMPLE/mean.binaryproto build/tools/compute_image_mean.bin examples/mytest/img_train_lmdb examples/mytest/mean.binaryproto echo "Done.."5.修改slover和train_test_net参数后,运行train.sh进行训练
6.训练完得到相应的.caffemodel文件,可以通过运行test.sh调用deploy文件调用.caffemodel来进行测试
7.全部完成后查看loss和accuracy曲线的方法在我的另一篇博客中有详细介绍哟。-->caffe在linux下绘制训练时的loss曲线
我是深度学习新的不能再新的新手,希望和大家一起学习
我们下期见!