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的文章,更不知道从什么时候开始,三维重建各个 ...
随机推荐
- Jenkins持续集成环境, 如何自定义 maven 仓库
最后的解决方法: job-->configure-->Build-->Goals and options: clean package -Dmaven.repo.local=D:\d ...
- vscode 搭建go开发环境的13个插件的安装
由于网的问题 大家都不能直接go get 这里从易到难按难度给大家推荐几种方法 最简单的FQ 但是能FQ你还不能装 请问是假的FQ吗? 第一 用git 直接git反而能从那边趴下代码 但是要自己go ...
- Python小代码_12_生成前 n 行杨辉三角
def demo(t): print([1]) print([1, 1]) line = [1, 1] for i in range(2, t): r = [] for j in range(0, l ...
- java 需要准备的知识(转摘)
需要准备的知识 以下为在近期面试中比较有印象的问题,也就不分公司了,因为没什么意义,大致分类记录一下,目前只想起这么多,不过一定要知道这些问题只是冰山一角,就算都会了也不能怎么样,最最重要的,还是坚实 ...
- 通过AIDL在两个APP之间Service通信
一.项目介绍 [知识准备] ①Android Interface definition language(aidl,android接口定义语言),其目的实现跨进程的调用.进程是程序在os中执行的载体, ...
- c++ Struct和Class的区别
C++中的struct对C中的struct进行了扩充,它已经不再只是一个包含不同数据类型的数据结构了,它已经获取了太多的功能.struct能包含成员函数吗? 能!struct能继承吗? 能!!stru ...
- Oracle中打印99乘法表的13种方法
--实现1: select r1 || '*' || r1 || '=' || r1 * r1 A, decode(r2, '', '', r2 || '*' || r1 || '=' || r2 * ...
- EntityFramework Core 自动绑定模型映射
笔者最近在和同事共同开发项目时,需要从他们提供的包含数据库实体类型的类库中读取实体信息绑定到自己的项目中(但是都在同一个解决方案里),所以很直接的一种方式就是把项目中所有的实体都以 public Db ...
- Java 8新特性:新语法方法引用和Lambda表达式及全新的Stream API
新语法 方法引用Method references Lambda语法 Lambda语法在AndroidStudio中报错 Stream API 我正参加2016CSDN博客之星的比赛 希望您能投下宝贵 ...
- TCP发送源码学习(1)--tcp_sendmsg
一.tcp_sendmsg()函数分析: int tcp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg, size_t ...