-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheval.py
28 lines (21 loc) · 810 Bytes
/
eval.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import tensorflow as tf
from config import *
from PIL import Image
import numpy as np
from util import *
ix2char = loadindex2char()
tf.train.import_meta_graph(model_dir+'.meta')
saver = tf.train.Saver()
sess = tf.Session()
saver.restore(sess,model_dir)
imarr = []
im = Image.open(r'C:\迅雷下载\Synthetic Chinese String Dataset\images\20436312_1683447152.jpg')
ima = np.array(im.convert('L'))
imarr.append(np.expand_dims(ima,axis=-1))
image_holder = tf.get_default_graph().get_tensor_by_name("image_holder:0")
best_path = tf.get_default_graph().get_tensor_by_name("ctc_best_path:0")
_preds = sess.run(best_path, feed_dict={image_holder: np.array(imarr)})
strarr = []
for line in _preds:
strarr.append(''.join([ix2char[char_index] if char_index!=-1 else '' for char_index in line]))
print(strarr)