Skip to content

Instantly share code, notes, and snippets.

@haoliplus
Created May 13, 2016 07:01
Show Gist options
  • Save haoliplus/14b919e744084f75f6f9b70debd4a5d8 to your computer and use it in GitHub Desktop.
Save haoliplus/14b919e744084f75f6f9b70debd4a5d8 to your computer and use it in GitHub Desktop.
Using Mxnet model to predict
#! /usr/bin/env python
#################################################################################
# File Name : test-one.py
# Created By : Hao Li
# Creation Date : [2016-04-08 13:44]
# Last Modified : [2016-04-26 13:49]
# Description :
#################################################################################
import os
import sys
import time
import numpy
import LabelIndex
from skimage import io,transform
import logging
import numpy as np
sys.path.insert(0, "/mnt/disk0/lihao/plate-test/libs")
import mxnet as mx
class MxnetModel():
def convert_mean_file(self, mean_filename):
pass
def get_mean(self, mean_filename):
return npy.mean(1).mean(1)
def __init__(self, data_name="current"):
mxnet_judge_rounds = 70
mx_net_judge_prefix = "/mnt/disk0/lihao/plate-test/data/mxnet-model/platenet-100-0"
epoch = 70
device_id = 0
self.model = mx.model.FeedForward.load(mx_net_judge_prefix, int(mxnet_judge_rounds),
ctx=mx.gpu(device_id), numpy_batch_size=1)
def predict(self, segments):
resized_imgs = [transform.resize(io.imread(path), (64,64)) for path in segments]
swapped_imgs = np.swapaxes(np.swapaxes(np.asarray(resized_imgs) * 256, 1, 3), 2, 3)
probs = self.model.predict(swapped_imgs)
return probs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment