-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest.py
41 lines (31 loc) · 1.05 KB
/
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
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import os
import warnings
warnings.filterwarnings('ignore')
import tensorflow as tf
from PIL import Image
from helper_functions import run_odt_and_draw_results
import config
cwd = os.getcwd()
MODEL_PATH = config.MODEL_PATH
MODEL_NAME = config.MODEL_NAME
DETECTION_THRESHOLD = 0.3
# Change the test file path to your test image
INPUT_IMAGE_PATH = 'dataset/test/IMG_2347_jpeg_jpg.rf.7c71ac4b9301eb358cd4a832844dedcb.jpg'
im = Image.open(INPUT_IMAGE_PATH)
im.thumbnail((512, 512), Image.ANTIALIAS)
im.save(f'{cwd}/result/input.png', 'PNG')
# Load the TFLite model
model_path = f'{MODEL_PATH}/{MODEL_NAME}'
interpreter = tf.lite.Interpreter(model_path=model_path)
interpreter.allocate_tensors()
# Run inference and draw detection result on the local copy of the original file
detection_result_image = run_odt_and_draw_results(
f'{cwd}/result/input.png',
interpreter,
threshold=DETECTION_THRESHOLD
)
# Show the detection result
img = Image.fromarray(detection_result_image)
img.save(f'{cwd}/result/ouput.png')
print('-'*100)
print('See the result folder.')