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并测试数据的更多相关文章

  1. 深度学习—caffe框架训练文档

    转存:LMDB E:\机器学习2\caffe资料\caffe_root\caffe-master\Build\x64\Release>convert_imageset.exe E:/机器学习2/ ...

  2. 【机器学习PAI实践十】深度学习Caffe框架实现图像分类的模型训练

    背景 我们在之前的文章中介绍过如何通过PAI内置的TensorFlow框架实验基于Cifar10的图像分类,文章链接:https://yq.aliyun.com/articles/72841.使用Te ...

  3. caffe fine tune 复制预训练model的参数和freeze指定层参数

    复制预训练model的参数,只需要重新copy一个train_val.prototxt.然后把不需要复制的层的名字改一下,如(fc7 -> fc7_new),然后fine tune即可. fre ...

  4. Caffe使用step by step:caffe框架下的基本操作和分析

    caffe虽然已经安装了快一个月了,但是caffe使用进展比较缓慢,果然如刘老师说的那样,搭建起来caffe框架环境比较简单,但是完整的从数据准备->模型训练->调参数->合理结果需 ...

  5. 【神经网络与深度学习】Caffe使用step by step:caffe框架下的基本操作和分析

    caffe虽然已经安装了快一个月了,但是caffe使用进展比较缓慢,果然如刘老师说的那样,搭建起来caffe框架环境比较简单,但是完整的从数据准备->模型训练->调参数->合理结果需 ...

  6. Caffe框架下的图像回归测试

    Caffe框架下的图像回归测试 参考资料: 1. http://stackoverflow.com/questions/33766689/caffe-hdf5-pre-processing 2. ht ...

  7. 人工智能深度学习Caffe框架介绍,优秀的深度学习架构

    人工智能深度学习Caffe框架介绍,优秀的深度学习架构 在深度学习领域,Caffe框架是人们无法绕过的一座山.这不仅是因为它无论在结构.性能上,还是在代码质量上,都称得上一款十分出色的开源框架.更重要 ...

  8. caffe框架下目标检测——faster-rcnn实战篇操作

    原有模型 1.下载fasrer-rcnn源代码并安装 git clone --recursive https://github.com/rbgirshick/py-faster-rcnn.git 1) ...

  9. Caffe框架,了解三个文件

    不知道从什么时候开始,Deep Learning成为了各个领域研究的热点,也不知道从什么时候开始,2015CVPR的文章出现了很多Deep Learning的文章,更不知道从什么时候开始,三维重建各个 ...

随机推荐

  1. laravel实现支付宝支付功能

    起因 前段时间因为项目中需要实现支付宝手机网站支付功能,所以写下这篇文章以作记录,不足之处,欢迎指教. 后端框架:Laravel 5.5 业务功能 适用于商家在移动端网页应用中集成支付宝支付功能.商家 ...

  2. 干货满满,腾讯云+社区技术沙龙 Kafka Meetup 深圳站圆满结束

    欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 云+导语:4月22日,由腾讯云和 Kafka 社区主办.开源中国协办的腾讯云+社区技术沙龙 Kafka Meetup 深圳站在腾讯大厦举行, ...

  3. Jenkins持续集成环境, 如何自定义 maven 仓库

    最后的解决方法: job-->configure-->Build-->Goals and options: clean package -Dmaven.repo.local=D:\d ...

  4. 48. Rotate Image(中等)

    You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). ...

  5. JQ简单实现无缝滚动

    $(function(){ $("ul li:lt(5)").clone().appendTo("ul"); var $width = $("ul l ...

  6. CSS实现元素居中原理解析

    在 CSS 中要设置元素水平垂直居中是一个非常常见的需求了.但就是这样一个从理论上来看似乎实现起来极其简单的,在实践中,它往往难住了很多人. 让元素水平居中相对比较简单:如果它是一个行内元素,就对它的 ...

  7. CRM客户关系管理系统(三)

    第四章.kingadmin开发设计 4.1.kingadmin设计 自定义admin注册model的写法 crm/admin.py class CustomerAdmin(admin.ModelAdm ...

  8. python笔记十四(高阶函数——map/reduce、filter、sorted)

    一.map/reduce 1.map() map(f,iterable),将一个iterable对象一次作用于函数f,并返回一个迭代器. >>> def f(x): #定义一个函数 ...

  9. AWS EC2 CentOS release 6.5 部署redis

    AWS EC2 CentOS release 6.5 部署redis参考:http://blog.csdn.net/ludonqin/article/details/47211109一.安装redis ...

  10. Rails中rspec测试xxx_path调用失败的解决

    首先要想生成类似于home_path,about_path之类的方法,必须在路由文件中添加对应方法: match '/help',to:"static_pages#help",vi ...