forked from breadbread1984/OCR-tf2
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.py
24 lines (18 loc) · 812 Bytes
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/python3
import cv2;
import tensorflow as tf;
from create_dataset import ocr_parse_function, SampleGenerator;
from TextRecognizer import TextRecognizer;
def main():
generator = SampleGenerator(10);
text_recognizer = TextRecognizer();
testset = tf.data.Dataset.from_generator(generator.gen, (tf.float32, tf.int64), (tf.TensorShape([32, None, 3]), tf.TensorShape([None,]))).repeat(-1).map(ocr_parse_function).batch(1).prefetch(tf.data.experimental.AUTOTUNE);
# restore from existing checkpoint
for image, label in testset:
text = text_recognizer.recognize(image, preprocess = False);
print(text);
cv2.imshow("image", ((image[0,...] / 2 + 0.5) * 255.).numpy().astype('uint8'));
cv2.waitKey();
if __name__ == "__main__":
assert True == tf.executing_eagerly();
main();