前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Caffe中均值文件的问题

Caffe中均值文件的问题

作者头像
GavinZhou
发布2018-01-02 15:12:27
6120
发布2018-01-02 15:12:27
举报

关于均值文件

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

均值文件形式之间的转换

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

代码语言:javascript
复制
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(比如我)来说,还是要费一番功夫的,特此写出供遇到和我一样问题的人参考,大家共同努力吧!!!

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2015-12-20 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 关于均值文件
  • 均值文件形式之间的转换
  • 写在后面
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档