-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
33 lines (24 loc) · 1.14 KB
/
test.py
File metadata and controls
33 lines (24 loc) · 1.14 KB
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
# Tutorials/01_image_to_word/inferenceModel.py
if __name__ == "__main__":
import pandas as pd
from tqdm import tqdm
from mltu.configs import BaseModelConfigs
configs = BaseModelConfigs.load("Models/1_image_to_word/202211270035/configs.yaml")
model = ImageToWordModel(model_path=configs.model_path, char_list=configs.vocab)
df = pd.read_csv("Models/1_image_to_word/202211270035/val.csv").dropna().values.tolist()
accum_cer = []
for image_path, label in tqdm(df):
image = cv2.imread(image_path)
try:
prediction_text = model.predict(image)
cer = get_cer(prediction_text, label)
print(f"Image: {image_path}, Label: {label}, Prediction: {prediction_text}, CER: {cer}")
# resize image by 3 times for visualization
# image = cv2.resize(image, (image.shape[1] * 3, image.shape[0] * 3))
# cv2.imshow(prediction_text, image)
# cv2.waitKey(0)
# cv2.destroyAllWindows()
except:
continue
accum_cer.append(cer)
print(f"Average CER: {np.average(accum_cer)}")