Skip to content

Instantly share code, notes, and snippets.

@haoliplus
Created May 13, 2016 07:02
Show Gist options
  • Save haoliplus/86c710db4d12c4d1f6cf4154f8d26a36 to your computer and use it in GitHub Desktop.
Save haoliplus/86c710db4d12c4d1f6cf4154f8d26a36 to your computer and use it in GitHub Desktop.
Using Purine model to predict
#! /usr/bin/env python
#################################################################################
# File Name : PlateModel.py
# Created By : Hao Li
# Creation Date : [2016-04-19 16:27]
# Last Modified : [2016-04-23 15:17]
# Description :
#################################################################################
from pymongo import MongoClient
import os
import sys
import numpy as np
import importlib
import ConfigParser
reload(sys) # 2
sys.setdefaultencoding('utf-8') # 3
class PurineModel:
def __init__(self):
sys.path.append('./libs')
self.net = importlib.import_module("purine.libautopurine")
self.cf = ConfigParser.ConfigParser()
self.cf.read('conf.ini')
self.gray_reg_net_idx = self.net.init_model(self.cf.get('plate_detection', 'purine_gray_reg_model'), 0)
def __del__(self):
self.net.delete_model(self.gray_reg_net_idx)
def getProb(self, imgpath):
jpeg_contents = [open(imgpath).read()]
prob = [[0 for i in range(73)]]
self.net.predict(self.gray_reg_net_idx, jpeg_contents, prob, {'data_type':1, 'multi_view':0})
return prob
def predict(self, segments):
probs = []
for s in segments:
probs.extend(self.getProb(s))
probs = np.array(probs)
return probs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment