Spaces:
Build error
Build error
adding label_maps
Browse files
app.py
CHANGED
|
@@ -76,6 +76,44 @@ def predict2(image_np):
|
|
| 76 |
|
| 77 |
return result_pil_img
|
| 78 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
|
| 80 |
REPO_ID = "apailang/mytfodmodel"
|
| 81 |
detection_model = load_model()
|
|
@@ -89,3 +127,12 @@ gr.Interface(fn=predict,
|
|
| 89 |
inputs=gr.Image(type="pil"),
|
| 90 |
outputs=gr.Image(type="pil")
|
| 91 |
).launch(share=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
|
| 77 |
return result_pil_img
|
| 78 |
|
| 79 |
+
def detect_video(video):
|
| 80 |
+
# Create a video capture object
|
| 81 |
+
cap = cv2.VideoCapture(video)
|
| 82 |
+
|
| 83 |
+
# Process frames in a loop
|
| 84 |
+
while cap.isOpened():
|
| 85 |
+
ret, frame = cap.read()
|
| 86 |
+
if not ret:
|
| 87 |
+
break
|
| 88 |
+
|
| 89 |
+
# Expand dimensions since model expects images to have shape: [1, None, None, 3]
|
| 90 |
+
image_np_expanded = np.expand_dims(frame, axis=0)
|
| 91 |
+
|
| 92 |
+
# Run inference
|
| 93 |
+
output_dict = detection_model(image_np_expanded)
|
| 94 |
+
|
| 95 |
+
# Extract detections
|
| 96 |
+
boxes = output_dict['detection_boxes'][0].numpy()
|
| 97 |
+
scores = output_dict['detection_scores'][0].numpy()
|
| 98 |
+
classes = output_dict['detection_classes'][0].numpy().astype(np.int64)
|
| 99 |
+
|
| 100 |
+
# Draw bounding boxes and labels
|
| 101 |
+
image_np_with_detections = viz_utils.visualize_boxes_and_labels_on_image_array(
|
| 102 |
+
frame,
|
| 103 |
+
boxes,
|
| 104 |
+
classes,
|
| 105 |
+
scores,
|
| 106 |
+
category_index,
|
| 107 |
+
use_normalized_coordinates=True,
|
| 108 |
+
max_boxes_to_draw=20,
|
| 109 |
+
min_score_thresh=.5,
|
| 110 |
+
agnostic_mode=False)
|
| 111 |
+
|
| 112 |
+
# Yield the processed frame
|
| 113 |
+
yield image_np_with_detections
|
| 114 |
+
|
| 115 |
+
# Release resources
|
| 116 |
+
cap.release()
|
| 117 |
|
| 118 |
REPO_ID = "apailang/mytfodmodel"
|
| 119 |
detection_model = load_model()
|
|
|
|
| 127 |
inputs=gr.Image(type="pil"),
|
| 128 |
outputs=gr.Image(type="pil")
|
| 129 |
).launch(share=True)
|
| 130 |
+
|
| 131 |
+
# iface = gr.Blocks()
|
| 132 |
+
|
| 133 |
+
# iface.Image(fn=predict, inputs=gr.Image(type="pil"), label="Image Detection",outputs=gr.Image(type="pil"))
|
| 134 |
+
# iface.Video(fn=detect_video, inputs=gr.Video(type="mp4", live=True, label="Input Video"),outputs=gr.Video(type="mp4", label="Detected Video", live=True), label="Video Detection", interpretation="default")
|
| 135 |
+
|
| 136 |
+
# iface.launch(share=True)
|
| 137 |
+
|
| 138 |
+
|