predict.py backup

import mxnet as mx
import numpy as np
from skimage import io, transform

prefix="model/mnist-0"
num_round=2
model = mx.model.FeedForward.load(prefix, num_round, ctx=mx.cpu(), numpy_batch_size=1)

#mean_img=mx.nd.load("Inception/mean_224.nd")["mean_img"]
mean_img = np.load("mean_img.npy")
mean_img = np.swapaxes(mean_img, 0, 2)
mean_img = np.swapaxes(mean_img, 1, 2)
#print mean_img

#synset=[l.strip() for l in open("Inception/synset-2w.txt").readlines()]

def PreprocessImage(path):
    img=io.imread(path)
    short_egde = min(img.shape[:2])
    yy = int((img.shape[0] - short_egde)/2)
    xx = int((img.shape[1] - short_egde)/2)
    crop_img = img[yy: yy+short_egde, xx:xx+short_egde]
    resized_img = transform.resize(crop_img, (224, 224))
    sample = np.asarray(resized_img)*256
    #sample = np.asarray(resized_img)
    sample = np.swapaxes(sample, 0, 2)
    sample = np.swapaxes(sample, 1, 2)
    normed_img = sample - mean_img
    print normed_img
    print normed_img.shape
    normed_img = normed_img.reshape(1, 3, 224, 224)
    return normed_img

batch = PreprocessImage("1999.jpg")
prob = model.predict(batch)[0]
print prob
#pred = np.argsort(prob)[::-1]
#top1=synset[pred[0]]
#print("Top1: ", top1)
~                       
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值