import caffe
# caffemodel文件
MODEL_FILE = 'model/_iter_10000.caffemodel'
# deploy文件,参考/caffe/models/bvlc_alexnet/deploy.prototxt
DEPLOY_FILE = 'deploy.prototxt'
# 测试图片存放文件夹
TEST_ROOT = 'datas/'
caffe.set_mode_gpu()
net = caffe.Classifier(MODEL_FILE, PRETRAIN_FILE,
raw_scale=255, channel_swap=(2, 1, 0))
# 详见/caffe/python/caffe/io.py
img = caffe.io.load_image('temp.jpg')
# 读取的图片文件格式为H×W×K,需转化
# 需注意第一个参数为数组
# 默认采用过采样(详见**/caffe/python/caffe/io.py**),这里取消
out = net.predict([img], oversample=False)
# 输出结果为各个可能分类的概率分布
pridect = out.argmax()