导航:首页 > 程序命令 > 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命令相关的资料

热点内容
伪军pdf 浏览:418
如何判断基本命令 浏览:972
pdf批量删除 浏览:943
广播android静态动态区别 浏览:390
centos7设置为命令行启动 浏览:570
程序员资质资格证 浏览:217
常见编码加密 浏览:236
阿狸免费云服务器 浏览:764
快速配置服务器bmc地址 浏览:968
机械手臂编程自动化 浏览:501
怎么看银行app的银行卡号 浏览:84
pdf文件改ppt 浏览:196
ecs对比云服务器 浏览:852
必剪app怎么没有美颜 浏览:176
唯库的视频怎么下载app 浏览:465
面度云服务器 浏览:353
加密狗华为 浏览:6
光遇安卓版和ios怎么一起玩 浏览:52
飞机空气动力学pdf 浏览:25
AndroidBinder设计与 浏览:278