ocrModel = ocrModelTorchDense else: ocrModel = ocrModelTorchEng alphabet = alphabetEnglish LSTMFLAG = True elif ocrFlag == 'opencv': from crnn.network_dnn import CRNN ocrModel = ocrModelOpencv alphabet = alphabetChinese else: print("err,ocr engine in keras\opencv\darknet") nclass = len(alphabet) + 1 if ocrFlag == 'opencv': crnn = CRNN(alphabet=alphabet) else: crnn = CRNN(32, 1, nclass, 256, leakyRelu=False, lstmFlag=LSTMFLAG, GPU=GPU, alphabet=alphabet) if os.path.exists(ocrModel): crnn.load_weights(ocrModel) else: print("download model or tranform model with tools!") ocr = crnn.predict_job
def crnnSource(): alphabet = keys.alphabetChinese##中英文模型 converter = strLabelConverter(alphabet) model = CRNN(32, 1, len(alphabet)+1, 256, 1,lstmFlag=LSTMFLAG) model.load_weights(ocrModelKeras) return model,converter
# coding:utf-8 from crnn.utils import strLabelConverter, resizeNormalize from crnn.network_keras import keras_crnn as CRNN import tensorflow as tf from crnn import keys from config import ocrModelKeras import numpy as np graph = tf.get_default_graph() alphabet = keys.alphabetChinese model = CRNN(32, 1, len(alphabet) + 1, 256, 1, lstmFlag=False) model.load_weights(ocrModelKeras) export_path = "models/crnn/1" with tf.keras.backend.get_session() as sess: out = model.output keys = [0] values = [" "] for idx, char in enumerate(alphabet): keys.append(idx + 1) values.append(char) table = tf.contrib.lookup.HashTable( tf.contrib.lookup.KeyValueTensorInitializer(keys, values), "ç")