1.获取训练数据
cd caffe
./data/cifar10/get_cifar10.sh
./examples/cifar10/create_cifar10.sh
2.开始训练
./examples/cifar10/train_quick.sh
3.训练结束后得到模型
cifar10_quick_iter_4000.caffemodel.h5
cifar10_quick_iter_4000.solverstate.h5
4.使用模型进行数据分类
先直接用一下别人的模型分类试一下:(默认用的ImageNet的模型)
python python/classify.py examples/images/cat.jpg foo
报错:
Traceback (most recent call last):
File "python/classify.py", line 138, in <module>
main(sys.argv)
File "python/classify.py", line 110, in main
channel_swap=channel_swap)
File "/home/hxy/caffe/python/caffe/classifier.py", line 26, in __init__
caffe.Net.__init__(self, model_file, caffe.TEST, weights=pretrained_file)
RuntimeError: Could not open file python/../models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel
原因是caffemodel那个文件需要自己下载
cd scripts
python download_model_binary.py /root/caffe/models/bvlc_reference_caffenet
继续报错
ERROR: [Errno 13] Permission denied: '/root/caffe/models/bvlc_reference_caffenet/readme.md'
愿意是没有权限 在前面加上sudo
sudo python scripts/download_model_binary.py models/bvlc_reference_caffenet
下载成功,继续进行分类,结果存放在foo文件内
python python/classify.py examples/images/cat.jpg foo
比较奇怪的是从readme.md那个文件所给的官网上下载model之后的后缀尾.caffemodel.part
查找资料后.part是只下载了部分文件不完整。
http://www.zou114.com/wenjian/show.asp?mc=part
5.用自己训练出的模型进行分类
python python/classify.py --model_def examples/cifar10/cifar10_quick.prototxt --pretrained_model examples/cifar10/cifar10_quick_iter_4000.caffemodel.h5 --center_only examples/images/cat.jpg foo
意思是使用cifar10_quick.prototxt网络和事先训练好的模型cifar10_quick_iter_5000.caffemodel.h5,对examples、images/cat.jpg进行分类。
http://www.cnblogs.com/alexcai/p/5468164.html
http://blog.youkuaiyun.com/dcxhun3/article/details/52021296
,使用cifar10_quick.prototxt网络 + cifar10_quick_iter_4000.caffemodel.h5模型,对examples/images/cat.jpg图片进行分类。