导航:首页 > 程序命令 > caffe命令

caffe命令

发布时间:2023-07-14 23:40:33

Ⅰ Caffe训练自己的imagenet,ubuntu提示killed

1、准备数据。
假设已经下载好数据集和验证集,存储路径为:
/path/to/imagenet/train/n01440764/n01440764_10026.JPEG
/path/to/imagenet/val/ILSVRC2012_val_00000001.JPEG
首选需要创建一个txt文件,列举出所有图像以及对应的lable,caffe包“python/caffe/imagenet/ilsvrc_2012_train.txt”和“ilsvrc_2012_val.txt”两个文件分别是标好的训练集和验证集的文件,共分为1000类。
还需要注意的是,所有的图像都需要归一到同样的尺寸。

2、转化生成训练集。
运行下面的命令
GLOG_logtostderr=1 examples/convert_imageset.bin /path/to/imagenet/train/ python/caffe/imagenet/ilsvrc_2012_train.txt /path/to/imagenet-train-leveldb
生成文件存储在“/path/to/imagenet-train_leveldb”路径下。

3、计算图像均值。
执行命令:
examples/demo_compute_image_mean.bin /path/to/imagenet-train-leveldb /path/to/mean.binaryproto
第一个参数是执行脚本代码,第二个参数是上一步生成的数据集,第三个参数是存储图像均值的目录路径。

4、定义网络。
ImageNet的网络定义在“examples/imagenet.prototxt”文件中,使用时需要修改里面source和meanfile变量的值,指向自己文件的路径。
仔细观察imagenet.prototxt和imagenet_val.prototxt文件可以发现,训练和验证的参数大部分都相同,不同之处在于初始层和最后一层。训练时,使用softmax_loss层来计算损失函数和初始化后向传播,验证时,使用accuracy层来预测精确度。
在文件“examples/imagenet_solver.prototxt”中定义solver协议,同样需要修改train_net和test_net的路径。

5、训练网络。
执行命令:
GLOG_logtostderr=1 examples/train_net.bin examples/imagenet_solver.prototxt

6、在python中使用已经训练好的模型。
Caffe只提供封装好的imagenet模型,给定一副图像,直接计算出图像的特征和进行预测。首先需要下载模型文件。
Python代码如下:

[python] view plain print?
from caffe import imagenet
from matplotlib import pyplot
# Set the right path to your model file, pretrained model
# and the image you would like to classify.
MODEL_FILE = 'examples/imagenet_deploy.prototxt'
PRETRAINED = '/home/jiayq/Downloads/caffe_reference_imagenet_model’
IMAGE_FILE = '/home/jiayq/lena.png'

net = imagenet.ImageNetClassifier(MODEL_FILE, PRETRAINED)
#预测
prediction = net.predict(IMAGE_FILE)
#绘制预测图像
print 'prediction shape:', prediction.shape
pyplot.plot(prediction)
prediction shape: (1000,)
[<matplotlib.lines.Line2D at 0x8faf4d0>] #结果如图所示

图上的横轴表示的label,纵轴表示在该类别上的概率,有图我们看到,lena.jpg被分到了”sombrero”这组,结果还算准确。

阅读全文

与caffe命令相关的资料

热点内容
怎么删除一个app下载任务 浏览:713
python执行bat命令 浏览:471
什么吉他调音器app最好 浏览:33
php程序员招聘试题 浏览:14
程序员升职记第九关最优解 浏览:317
三星安卓11怎么访问data文件夹 浏览:817
华三服务器怎么设置开机自启 浏览:711
钉邮登录服务器地址 浏览:644
起源编译器适配第二款应用 浏览:433
cad弄断线条命令 浏览:463
怎么恢复手机app的安装包 浏览:300
idea重启项目不编译 浏览:495
程序员那么可爱演员表陆漓妈妈 浏览:127
linuxgadget驱动 浏览:594
华三调用acl的命令 浏览:9
资金流pdf 浏览:931
金融结算法补充条款 浏览:291
什么叫服务器怎么连接 浏览:521
空调压缩机有制冷但室内不是很冷 浏览:839
如何查解压成功 浏览:652