Caffe框架,训练model并测试数据
1. 训练model
#!/usr/bin/env sh ./build/tools/caffe train --solver=examples/focal_length/focal_solver.prototxt
2. 测试数据
import caffe
from caffe.proto import caffe_pb2
import numpy as np
import cv2
run_mode = 'gpu'
deploy_file = 'focal_deploy.prototxt'
weight_file = 'focal_iter_5000.caffemodel'
data_path = '/home/lei/project/caffe/caffe-master/data/focal_length/test/'
list_file = 'list.txt'
# init the caffenet
if run_mode == 'gpu':
caffe.set_device(0)
caffe.set_mode_gpu()
elif run_mode == 'cpu':
caffe.set_mode_cpu()
net = caffe.Net(deploy_file, weight_file, caffe.TEST)
# mean array
mean_file = '/home/lei/project/caffe/caffe-master/data/ilsvrc12/imagenet_mean.binaryproto'
mean_blobproto = caffe_pb2.BlobProto()
fid = open(mean_file, 'rb')
mean_blobproto.ParseFromString( fid.read() )
mean_array = caffe.io.blobproto_to_array( mean_blobproto )
mean_array = mean_array.astype( np.float32 )
mean_array = np.zeros(mean_array.shape, mean_array.dtype)
with open(data_path + list_file) as fid:
for key in fid.readlines():
filename = ( data_path + key ).strip()
img = cv2.imread(filename)
cv2.imshow('name', img)
cv2.waitKey(500)
img = img.astype( np.float32 )
data_in = img.reshape( (1,256,256,3) )
data_in = data_in.transpose((0,3,1,2))
data_in = data_in - mean_array
data_in = data_in * 0.00390625
netout = net.forward_all(data=data_in)
guess = netout['prob'].argmax(axis=1) # the type is np.int64
prob = netout['prob'].max(axis=1)
print '{}: guess: {}, prob: {}'.format(key, guess[0], prob[0])
# /home/lei/project/caffe/caffe-master/examples/focal_length
Caffe框架,训练model并测试数据的更多相关文章
- 深度学习—caffe框架训练文档
转存:LMDB E:\机器学习2\caffe资料\caffe_root\caffe-master\Build\x64\Release>convert_imageset.exe E:/机器学习2/ ...
- 【机器学习PAI实践十】深度学习Caffe框架实现图像分类的模型训练
背景 我们在之前的文章中介绍过如何通过PAI内置的TensorFlow框架实验基于Cifar10的图像分类,文章链接:https://yq.aliyun.com/articles/72841.使用Te ...
- caffe fine tune 复制预训练model的参数和freeze指定层参数
复制预训练model的参数,只需要重新copy一个train_val.prototxt.然后把不需要复制的层的名字改一下,如(fc7 -> fc7_new),然后fine tune即可. fre ...
- Caffe使用step by step:caffe框架下的基本操作和分析
caffe虽然已经安装了快一个月了,但是caffe使用进展比较缓慢,果然如刘老师说的那样,搭建起来caffe框架环境比较简单,但是完整的从数据准备->模型训练->调参数->合理结果需 ...
- 【神经网络与深度学习】Caffe使用step by step:caffe框架下的基本操作和分析
caffe虽然已经安装了快一个月了,但是caffe使用进展比较缓慢,果然如刘老师说的那样,搭建起来caffe框架环境比较简单,但是完整的从数据准备->模型训练->调参数->合理结果需 ...
- Caffe框架下的图像回归测试
Caffe框架下的图像回归测试 参考资料: 1. http://stackoverflow.com/questions/33766689/caffe-hdf5-pre-processing 2. ht ...
- 人工智能深度学习Caffe框架介绍,优秀的深度学习架构
人工智能深度学习Caffe框架介绍,优秀的深度学习架构 在深度学习领域,Caffe框架是人们无法绕过的一座山.这不仅是因为它无论在结构.性能上,还是在代码质量上,都称得上一款十分出色的开源框架.更重要 ...
- caffe框架下目标检测——faster-rcnn实战篇操作
原有模型 1.下载fasrer-rcnn源代码并安装 git clone --recursive https://github.com/rbgirshick/py-faster-rcnn.git 1) ...
- Caffe框架,了解三个文件
不知道从什么时候开始,Deep Learning成为了各个领域研究的热点,也不知道从什么时候开始,2015CVPR的文章出现了很多Deep Learning的文章,更不知道从什么时候开始,三维重建各个 ...
随机推荐
- Golang学习笔记:channel
channel channel是goroutine之间的通信机制,它可以让一个goroutine通过它给另一个goroutine发送数据,每个channel在创建的时候必须指定一个类型,指定的类型是任 ...
- Linux系统中安装Oracle过程记录
第一章 安装数据库软件 1.1 修改密码及创建目录和权限 创建oracle用户和组 创建相关目录并赋权 1.2 设置oracle用户环境变量 ORACLE_BASE:产品基目录 ORACLE_HOME ...
- RandomAccessFile&IO流&排序&方法论
RandomAccessFile&IO流&排序&方法论 我们总觉得历史是极其遥远的东西,与我们并无关联,又觉得历史隐藏在图书馆的旧书之中. 然而,我们每个人都有真真切切的历史. ...
- REACT相关资料合集
===实例=== https://github.com/jesseskinner/react-webpack-demo ===UI组件库=== https://github.com/amazeui/a ...
- 06 Nexus仓储/基础设施 - DevOps之路
06 Nexus仓储/基础设施 - DevOps之路 文章Github地址,欢迎start:https://github.com/li-keli/DevOps-WiKi Nexus仓储官网简介: Th ...
- 如何搭建apache服务?
为了日后便于查询,本文所涉及到的所有命令集合如下: chkconfig iptables off #关闭防火墙命令 在Centos7中使用的是chkconfig firewalld off vi /e ...
- Protobuf3语法详解
定义一个消息类型 先来看一个非常简单的例子.假设你想定义一个"搜索请求"的消息格式,每一个请求含有一个查询字符串.你感兴趣的查询结果所在的页数,以及每一页多少条查询结果.可以采用如 ...
- Numpy函数学习--genfromtxt函数
genfromtxt函数 今天学习时遇到了genfromtxt函数 world_alcohol = numpy.genfromtxt("world_alcohol.txt",del ...
- 短文本分析----基于python的TF-IDF特征词标签自动化提取
绪论 最近做课题,需要分析短文本的标签,在短时间内学习了自然语言处理,社会标签推荐等非常时髦的技术.我们的需求非常类似于从大量短文本中获取关键词(融合社会标签和时间属性)进行用户画像.这一切的基础就是 ...
- hexo常用命令
Hexo 约有二十个命令,但普通用户经常使用的只有下列几个: hexo s hexo s是hexo server的缩写,命令效果一致:启动本地服务器,用于预览主题.默认地址: http://local ...