Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,14 +3,15 @@ import numpy as np
|
|
3 |
from six import BytesIO
|
4 |
from PIL import Image
|
5 |
import tensorflow as tf
|
6 |
-
from object_detection.utils import label_map_util
|
7 |
-
from object_detection.utils import visualization_utils as viz_utils
|
8 |
-
from object_detection.utils import ops as utils_op
|
9 |
import tarfile
|
10 |
import wget
|
11 |
import gradio as gr
|
12 |
from huggingface_hub import snapshot_download
|
13 |
import os
|
|
|
|
|
|
|
|
|
14 |
|
15 |
PATH_TO_LABELS = 'label_map.pbtxt'
|
16 |
category_index = label_map_util.create_category_index_from_labelmap(PATH_TO_LABELS, use_display_name=True)
|
@@ -43,9 +44,7 @@ def load_model2():
|
|
43 |
detection_model = tf.saved_model.load(str(model_dir))
|
44 |
return detection_model
|
45 |
|
46 |
-
|
47 |
-
# image_path = 'test_samples/sample_balloon.jpeg
|
48 |
-
#
|
49 |
|
50 |
def predict(pilimg):
|
51 |
|
@@ -55,10 +54,8 @@ def predict(pilimg):
|
|
55 |
def predict2(image_np):
|
56 |
|
57 |
results = detection_model(image_np)
|
58 |
-
|
59 |
# different object detection models have additional results
|
60 |
result = {key:value.numpy() for key,value in results.items()}
|
61 |
-
|
62 |
label_id_offset = 0
|
63 |
image_np_with_detections = image_np.copy()
|
64 |
|
@@ -75,7 +72,6 @@ def predict2(image_np):
|
|
75 |
line_thickness=3)
|
76 |
|
77 |
result_pil_img = tf.keras.utils.array_to_img(image_np_with_detections[0])
|
78 |
-
|
79 |
return result_pil_img
|
80 |
|
81 |
|
@@ -95,6 +91,6 @@ gr.Interface(fn=predict,
|
|
95 |
title = title,
|
96 |
description = description,
|
97 |
css=css_code,
|
98 |
-
inputs=gr.Image(type="pil", height=
|
99 |
-
outputs=gr.Image(type="pil", height=
|
100 |
).launch(share=True)
|
|
|
3 |
from six import BytesIO
|
4 |
from PIL import Image
|
5 |
import tensorflow as tf
|
|
|
|
|
|
|
6 |
import tarfile
|
7 |
import wget
|
8 |
import gradio as gr
|
9 |
from huggingface_hub import snapshot_download
|
10 |
import os
|
11 |
+
from object_detection.utils import label_map_util
|
12 |
+
from object_detection.utils import visualization_utils as viz_utils
|
13 |
+
from object_detection.utils import ops as utils_op
|
14 |
+
|
15 |
|
16 |
PATH_TO_LABELS = 'label_map.pbtxt'
|
17 |
category_index = label_map_util.create_category_index_from_labelmap(PATH_TO_LABELS, use_display_name=True)
|
|
|
44 |
detection_model = tf.saved_model.load(str(model_dir))
|
45 |
return detection_model
|
46 |
|
47 |
+
|
|
|
|
|
48 |
|
49 |
def predict(pilimg):
|
50 |
|
|
|
54 |
def predict2(image_np):
|
55 |
|
56 |
results = detection_model(image_np)
|
|
|
57 |
# different object detection models have additional results
|
58 |
result = {key:value.numpy() for key,value in results.items()}
|
|
|
59 |
label_id_offset = 0
|
60 |
image_np_with_detections = image_np.copy()
|
61 |
|
|
|
72 |
line_thickness=3)
|
73 |
|
74 |
result_pil_img = tf.keras.utils.array_to_img(image_np_with_detections[0])
|
|
|
75 |
return result_pil_img
|
76 |
|
77 |
|
|
|
91 |
title = title,
|
92 |
description = description,
|
93 |
css=css_code,
|
94 |
+
inputs=gr.Image(type="pil", height=250),
|
95 |
+
outputs=gr.Image(type="pil", height=250)
|
96 |
).launch(share=True)
|