python生成caffe binary proto文件
来源:互联网 发布:淘宝运营 策划能力 编辑:程序博客网 时间:2024/05/24 01:15
使用python 生成 caffe .binaryproto文件,使用起来比caffe提供的二进制工具灵活一些,可以在生成的时候自由添加一些对数据的处理。
python 代码:
def ComputeMean(img_file_list,mean_file_write_to): #resize 尺寸 protosize=(224,224) #可以限定生成均值图像使用的图像数量 mean_count=20000 images=open(img_file_list.decode('utf-8')).read().strip().split('\n') totalMean=np.zeros(protosize[0],protosize[1],3) accedImage=np.zeros(protosize[0],protosize[1],3) for index,img in enumerate(images): img_path=img.decode('gbk').split(' ')[0].replace('G:/','/Volumes/xxx/') print img_path img_data=cv2.imread(img_path.encode('gbk')) img_resized=cv2.resize(img_data,protosize,interpolation=cv2.INTER_LINEAR) cv2.accumulate(img_resized,accedImage) #累计1000次计算一次均值速度会快一些,如果图像太多汇总起来再计算可能会溢出。 if(index%1000 ==0 and index>0): accedImage=accedImage/float(mean_count) cv2.accumulate(accedImage,totalMean) accedImage=np.zeros(protosize[0],protosize[1],3) print "processed: "+str(index) if index==mean_count: break accedImage=accedImage/float(mean_count) cv2.accumulate(accedImage,totalMean) #均值文件保存成图像便于查看 cv2.imwrite(mean_to_file+"proto.jpg",totalMean) cv2.imshow("test",totalMean) cv2.waitKey(1000) #for RGB image # totalMean=totalMean.transpose((2, 0, 1)) # 存储为binaryproto blob = caffe.BlobProto() blob.channels=3 blob.height = protosize[0] blob.width = protosize[1] blob.num=1 blob.data.extend(totalMean.astype(float).flat) binaryproto_file = open(mean_file_write_to, 'wb' ) binaryproto_file.write(blob.SerializeToString()) binaryproto_file.close()
对于单通道图像生成的方式大同小异,channel改为1即可。
阅读全文
0 0
- python生成caffe binary proto文件
- caffe proto.exe生成caffe.pb.h和caffe.pb.cc文件
- caffe proto.exe生成caffe.pb.h和caffe.pb.cc文件
- 利用caffe.proto生成caffe.pb.h
- caffe proto文件,和配置文件
- caffe proto文件,和配置文件
- Caffe源码中caffe.proto文件分析
- 如何用proto生成文件
- 【Python】【Caffe】一、生成prototxt文件《python调用caffe模块》
- caffe的caffe.proto
- caffe的caffe.proto
- caffe的caffe.proto
- caffe的caffe.proto
- 【caffe】caffe的python接口学习:生成solver文件
- 用proto命令生成java文件
- ProtoBuffer由.proto文件生成.cc/.h
- 用proto命令生成java文件
- 用proto命令生成java文件
- Hibernate做好这几步,轻松完成一对多关系映射配置(实例)
- nodejs -- mysql模块占位符 ? ??
- java集合详解锦集
- Rhyme/ Linux 文件系统常用命令—mount挂载命令以及-o特殊选项查询表
- 二层交换机实现vlan 功能 (Cisco Packer Tracer 模拟器)
- python生成caffe binary proto文件
- 第七周项目一
- myeclipse 2014,eclipse 安装阿里巴巴Java开发规约插件
- 微信商户中查看 appid
- SQL Server 2008编程入门经典笔记:脚本
- 文章标题
- 费用分摊分配用法(KSU5/KSV5/KB21N/KB11N)
- 字符串输出对齐问题
- java.lang.NullPointerException at javax.servlet.GenericServlet.getServletContext