predict.py backup
2016-05-25 10:55
309 查看
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) ~
相关文章推荐
- MySQL数据库中的存储过程和函数的操作
- (4.6.12.3)Android属性allowBackup安全风险浅析
- Androin学习笔记四十七:简易文件管理器的用法
- JavaScript笔记
- Linux上用udev自动识别并挂载U盘
- 字符串判断
- 数据库ORACLE中函数decode的用法
- at java.util.concurrent.ConcurrentHashMap.hash(ConcurrentHashMap.java:333)
- swift UIView 扩展
- Lucene(未查找)
- 基于 JQUERY 网页 banner
- nginx模块
- linux__kickstart无人值守批量安装系统
- 关于Android Lollipop
- 343. Integer Break #Medium
- eclipse 指定文件上传到tomcat的路径
- 回归 ---- 线性回归,多元回归与逻辑回归的关系
- 287. Find the Duplicate Number
- SQL Server native client与sqlcmd单独安装
- android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open dat