使用caffe模型预测

#-*- coding:utf-8 -*-
import numpy as np
import sys
import cv2
caffe_root = '/home/ubuntu/caffe/'  #修改成你的Caffe项目路径
sys.path.insert(0,caffe_root+'python')

import caffe
imgs = np.zeros([1,3,200,200])
caffe.set_mode_gpu()




model_def = '/home/ubuntu/caffe/examples/danhdf5/test_deploy.prototxt'
model_weights = '/home/ubuntu/caffe/examples/danhdf5/model/solver_iter_2000.caffemodel'  # 修改成你的caffemodel文件的路径

net = caffe.Net(model_def,   # defines the structure of the model
                model_weights,  # contains the trained weights
                caffe.TEST)   # use test mode (e.g., don't perform dropout)



net.blobs['data'].reshape(1, 3, 200, 200) #修改输入格式
net.blobs['label_x'].reshape(1, 1, 1)
net.blobs['label_y'].reshape(1, 1, 1)
image = cv2.imread('/home/ubuntu/caffe_case/HDF5/image1/2.jpg')  #输入读取图片
image = image.transpose(2,0,1)
#imgsmean = cv2.imread('imgsmean.jpg')
#imgsmean = imgsmean.transpose(2,0,1)
image = (image)/255
imgs[0,:,:,:] = image
label_x = [[2.4]]
label_y = [[8.34]]

net.blobs['data'].data[...] = imgs
net.blobs['label_x'].data[...] = label_x
net.blobs['label_y'].data[...] = label_y


output = net.forward()   #前向传播



#output_prob = output['ip2_x']
output_loss_x = output['loss_x']  #输入前向传播后的loss_x层
output_loss_y = output['loss_y']
#print 'predicted is :',output_prob
print 'loss_x:',output_loss_x
print 'loss_y:',output_loss_y
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值