Caffe中均值文件的问题

关于均值文件

(1) 在Caffe中作classification时经常需要使用均值文件,但是caffe自己提供的脚本只能将图像数据转换为
binaryproto类似的形式
(2) 我们在使用python接口时需要将npy形式的均值文件导入进来,而非binaryproto这样的均值文件

均值文件形式之间的转换

google类以下发现可以使用如下的代码进行转换:
代码是我自己实际使用的,有注释

import PIL
import Image
import sys
import time
import os
import numpy as np
from matplotlib import pyplot as plt 

start = time.time()

# Make sure that caffe is on the python path
caffe_root = '/home/gavinzhou/caffe-master/'  
sys.path.insert(0, caffe_root + 'python')

import caffe
# "source" is the binary file converted by the command shell 
# "des" is the binary file with python format converted from "source"
source = caffe_root + 'gavinzhou_LAB/alexnet/GF18_mean.binaryproto'
des = caffe_root + 'gavinzhou_LAB/alexnet/GF18_mean.npy'

# BlobProto object
blob = caffe.proto.caffe_pb2.BlobProto()
data = open( source , 'rb' ).read()
# parsing source data
blob.ParseFromString(data)
# convert to npy format
arr = np.array( caffe.io.blobproto_to_array(blob) )
out = arr[0]
# save the converted result
np.save( des , out )

实际测试时,验证数据集使用binaryproto形式的均值文件和测试数据集使用npy形式的均值文件时,正确率基本一样(差异很小但是还是验证集合稍高)

写在后面

从零开始玩deep learning确实很不容易,不过坚持下来就有收获,类似于这种问题虽然很小可是对于入门的learner(比如我)来说,还是要费一番功夫的,特此写出供遇到和我一样问题的人参考,大家共同努力吧!!!

评论 11
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值