Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from detecto import core, utils, visualize
|
2 |
+
from detecto.visualize import show_labeled_image, plot_prediction_grid
|
3 |
+
from torchvision import transforms
|
4 |
+
import matplotlib.pyplot as plt
|
5 |
+
from tensorflow.keras.utils import img_to_array
|
6 |
+
import numpy as np
|
7 |
+
import warnings
|
8 |
+
import streamlit as st
|
9 |
+
warnings.filterwarnings("ignore", category=UserWarning)
|
10 |
+
|
11 |
+
|
12 |
+
|
13 |
+
|
14 |
+
MODEL_PATH = "SD_model_weights.pth"
|
15 |
+
IMAGE_PATH = "img1.jpeg"
|
16 |
+
model = core.Model.load(MODEL_PATH, ['cross_arm','pole','tag'])
|
17 |
+
#warnings.warn(msg)
|
18 |
+
|
19 |
+
st.title("Object Detection")
|
20 |
+
|
21 |
+
|
22 |
+
def detect_object(IMAGE_PATH)
|
23 |
+
image = utils.read_image(IMAGE_PATH)
|
24 |
+
predictions = model.predict(image)
|
25 |
+
labels, boxes, scores = predictions
|
26 |
+
|
27 |
+
|
28 |
+
thresh=0.2
|
29 |
+
filtered_indices=np.where(scores>thresh)
|
30 |
+
filtered_scores=scores[filtered_indices]
|
31 |
+
filtered_boxes=boxes[filtered_indices]
|
32 |
+
num_list = filtered_indices[0].tolist()
|
33 |
+
filtered_labels = [labels[i] for i in num_list]
|
34 |
+
visualize.show_labeled_image(image, filtered_boxes, filtered_labels)
|
35 |
+
#img_array = img_to_array(img)
|
36 |
+
|
37 |
+
|
38 |
+
|
39 |
+
|
40 |
+
|
41 |
+
|
42 |
+
|
43 |
+
|