Isaacgonzales
commited on
Commit
•
5a7c59c
1
Parent(s):
d78a11f
add time result
Browse files
app.py
CHANGED
@@ -23,9 +23,9 @@ from model import prediction
|
|
23 |
|
24 |
def predict(img):
|
25 |
|
26 |
-
prediction_img, text = prediction(img)
|
27 |
|
28 |
-
return str(text), prediction_img,
|
29 |
|
30 |
|
31 |
sample_images = ["dataset/" + name for name in os.listdir("dataset")]
|
@@ -33,6 +33,6 @@ sample_images = ["dataset/" + name for name in os.listdir("dataset")]
|
|
33 |
|
34 |
gr.Interface(fn=predict,
|
35 |
inputs=[gr.Image(label="image à tester" ,type="filepath")],
|
36 |
-
outputs=[gr.Textbox(label="analyse"), gr.Image(label ="résultat") ],
|
37 |
css="footer {visibility: hidden} body}, .gradio-container {background-color: white}",
|
38 |
examples=sample_images).launch(server_name="0.0.0.0", share=False)
|
|
|
23 |
|
24 |
def predict(img):
|
25 |
|
26 |
+
prediction_img, text, t_process = prediction(img)
|
27 |
|
28 |
+
return t_process, str(text), prediction_img,
|
29 |
|
30 |
|
31 |
sample_images = ["dataset/" + name for name in os.listdir("dataset")]
|
|
|
33 |
|
34 |
gr.Interface(fn=predict,
|
35 |
inputs=[gr.Image(label="image à tester" ,type="filepath")],
|
36 |
+
outputs=[gr.Textbox(label="temps"), gr.Textbox(label="analyse"), gr.Image(label ="résultat") ],
|
37 |
css="footer {visibility: hidden} body}, .gradio-container {background-color: white}",
|
38 |
examples=sample_images).launch(server_name="0.0.0.0", share=False)
|
model.py
CHANGED
@@ -8,6 +8,7 @@ from torchvision import transforms
|
|
8 |
from PIL import Image
|
9 |
import torch
|
10 |
import cv2
|
|
|
11 |
|
12 |
model_recog = load_from_checkpoint("weights/parseq/last.ckpt").eval().to("cpu")
|
13 |
img_transform = SceneTextDataModule.get_transform(model_recog.hparams.img_size)
|
@@ -21,6 +22,7 @@ SHAPE_Y = 384
|
|
21 |
|
22 |
|
23 |
def prediction(image_path):
|
|
|
24 |
image = cv2.imread(image_path)
|
25 |
image_original = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
26 |
preprocessing_fn = smp.encoders.get_preprocessing_fn('resnet50')
|
@@ -42,11 +44,11 @@ def prediction(image_path):
|
|
42 |
|
43 |
p = model_recog(image).softmax(-1)
|
44 |
pred, p = model_recog.tokenizer.decode(p)
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
return img_vis, pred[0]
|
49 |
|
|
|
50 |
|
51 |
|
52 |
|
|
|
8 |
from PIL import Image
|
9 |
import torch
|
10 |
import cv2
|
11 |
+
from time import process_time
|
12 |
|
13 |
model_recog = load_from_checkpoint("weights/parseq/last.ckpt").eval().to("cpu")
|
14 |
img_transform = SceneTextDataModule.get_transform(model_recog.hparams.img_size)
|
|
|
22 |
|
23 |
|
24 |
def prediction(image_path):
|
25 |
+
t_start = process_time()
|
26 |
image = cv2.imread(image_path)
|
27 |
image_original = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
28 |
preprocessing_fn = smp.encoders.get_preprocessing_fn('resnet50')
|
|
|
44 |
|
45 |
p = model_recog(image).softmax(-1)
|
46 |
pred, p = model_recog.tokenizer.decode(p)
|
47 |
+
t_stop = process_time()
|
48 |
+
t_process = t_stop - t_start
|
49 |
+
print(f'{image_path}: {pred[0]}, {t_process} seconds')
|
|
|
50 |
|
51 |
+
return img_vis, pred[0], t_process
|
52 |
|
53 |
|
54 |
|