caffe Python API 之Inference
#以SSD的检测测试为例
def detetion(image_dir,weight,deploy,resolution=300):
caffe.set_mode_gpu()
net = caffe.Net(weight,deploy,caffe.TEST)
transformer = caffe.io.Transformer({'data': net.blobs['data'].data.shape})
transformer.set_transpose('data',(2,0,1))
transformer.set_mean('data', np.array([104, 117, 123])) # mean pixel images = os.listdir(image_dir)
target_dir = "det_results"
if not os.path.exists(target_dir):
os.mkdir(target_dir)
for image in images:
image_path = os.path.join(image_dir,image)
target_path = os.path.join(target_dir,image)
croped = cut(image_path,resolution)
net.blobs['data'].reshape(1, 3, resolution, resolution)
transformed_image = transformer.preprocess('data',croped)
net.blobs['data'].data[...]=transformed_image
start = time.time()
net.forward()
end = time.time()
print "Forward time is {} s.".format(int(end-start))
out_put = net.blobs["detection_out"].data out_put = np.squeeze(out_put)
# label,conf,xmin,ymin,xmax,ymax
for box in out_put:
conf = box[2]
# if conf < 0.1:
# continue
xmin = int(box[3]*resolution) if box[3] > 0 else 0
ymin = int(box[4]*resolution) if box[4] > 0 else 0
xmax = int(box[5]*resolution) if box[5] > 0 else 0
ymax = int(box[6]*resolution) if box[6] > 0 else 0
cv2.rectangle(croped,(xmin,ymin),(xmax,ymax),(0,255,0),1)
cv2.imwrite(target_path,croped)
print target_path
caffe Python API 之Inference的更多相关文章
- caffe Python API 之中值转换
# 编写一个函数,将二进制的均值转换为python的均值 def convert_mean(binMean,npyMean): blob = caffe.proto.caffe_pb2.BlobPro ...
- caffe Python API 之激活函数ReLU
import sys import os sys.path.append("/projects/caffe-ssd/python") import caffe net = caff ...
- caffe Python API 之 数据输入层(Data,ImageData,HDF5Data)
import sys sys.path.append('/projects/caffe-ssd/python') import caffe4 net = caffe.NetSpec() 一.Image ...
- caffe Python API 之BatchNormal
net.bn = caffe.layers.BatchNorm( net.conv1, batch_norm_param=dict( moving_average_fraction=0.90, #滑动 ...
- caffe Python API 之上卷积层(Deconvolution)
对于convolution: output = (input + 2 * p - k) / s + 1; 对于deconvolution: output = (input - 1) * s + k ...
- caffe Python API 之可视化
一.显示各层 # params显示:layer名,w,b for layer_name, param in net.params.items(): print layer_name + '\t' + ...
- caffe Python API 之图片预处理
# 设定图片的shape格式为网络data层格式 transformer = caffe.io.Transformer({'data': net.blobs['data'].data.shape}) ...
- caffe Python API 之Model训练
# 训练设置 # 使用GPU caffe.set_device(gpu_id) # 若不设置,默认为0 caffe.set_mode_gpu() # 使用CPU caffe.set_mode_cpu( ...
- caffe Python API 之Solver定义
from caffe.proto import caffe_pb2 s = caffe_pb2.SolverParameter() path='/home/xxx/data/' solver_file ...
随机推荐
- javascript如何封装函数
通常写js组件开发的,都会用到匿名函数的写法去封装一个对象,与外界形成一个闭包的作用域.封装,全天下漫天遍野的封装,JQuery,EXT和Prototype.js封装的是javascript,jQue ...
- A Magic Lamp HDU - 3183(RMQ返回下标)
原文地址:https://blog.csdn.net/acdreamers/article/details/8692384 题意: 对于一个序列A[1...N],一共N个数,除去M个数使剩下的数组成的 ...
- Crossing Rivers HDU - 3232 (均匀分布)
题目大意:A,B相距D,A,B间有n条河,河宽Li,每条河上有一个速度为vi的船,在河山来回行驶,每条河离A的距离为pi,现在求从A到B时间的期望,步行速度始终为1 题目分析:首先如果全部步行则期望为 ...
- Cells UVALive - 3486(dfs序+手动开栈)
给一棵树,每次每次询问一个点是否是另一个点的祖先? 输入时是每个下标对应节点的儿子的数量 用dfs序 时间戳.. 如果一个点是另一个点的祖先,那么它的两个标记一定在祖先的范围之内 #include & ...
- Debug快捷键
Debug快捷键 1. F5单步调试进入函数内部2. F6单步调试不进入函数内部3. F7由函数内部返回到调用处4. F8一直执行到下一个断点5. F11 重新运行debug
- castle activerecord 学习过程出现的问题
优点: 1.CRUD:代码简洁 2.不用配置map 3.自带事务方便 4.自带IOC 5.自带 数据有效性验证 缺点: 1.自增长(Oracle 一直提示序号不存在,有空继续尝试) 2.多条件,直接用 ...
- 【NuGet】使用NuGet打包并发布至ProGet过程 (打包再次详解)【下篇】
一.前言 上篇[1]主要介绍了利用csproj文件使用NuGet打包至ProGet的过程,并附上了用于在Jenkins上运行的python脚本.本篇的主要内容分为以下几点: 1. Nuspec与Nup ...
- redis分布式(主从复制)
Redis主从复制配置和使用都非常简单.通过主从复制可以允许多个slave server拥有和master server相同的数据库副本. Redis的复制原理:本身就是Master发送数据给s ...
- lightoj 1215
lightoj 1215 Finding LCM 链接:http://www.lightoj.com/volume_showproblem.php?problem=1215 题意:已知 a, b, l ...
- linux 查看登录日志
原文:http://www.cnblogs.com/wangkangluo1/archive/2011/09/23/2185976.html linux查看日志: # cd /var/log # le ...