python caffe 训练自己的模型_使用训练好的caffe模型分类图片(python版)

英文官方文档:http://nbviewer.jupyter.org/github/BVLC/caffe/blob/master/examples/00-classification.ipynb

导入python caffe包

import numpy as np

import matplotlib.pyplot as plt

# display plots in this notebook

%matplotlib inline

# set display defaults

plt.rcParams['figure.figsize'] = (10, 10) # large images

plt.rcParams['image.interpolation'] = 'nearest' # don't interpolate: show square pixels

plt.rcParams['image.cmap'] = 'gray' # use grayscale output rather than a (potentially misleading) color heatmap

import sys

import os

caffe_root = './' #指定caffe的根目录

sys.path.insert(0, caffe_root + 'python') #将caffe python接口文件路径添加到python path中

import caffe

# 判断model文件是否存在

if os.path.isfile(caffe_root + 'models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel'):

print 'CaffeNet found.'

else:

print 'Downloading pre-trained CaffeNet model...'

加载网络,创建输入处理

使用python  caffe.io.loadImage接口读取图片,返回的是[0-1]返回的np.float32数组

def load_image(filename, color=True):

"""

Load an image converting from grayscale or alpha as needed.

Parameters

----------

filename : string

color : boolean

flag for color format. True (default) loads as RGB while False

loads as

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值