Spaces:
Paused
Paused
remove tomatoes video file
Browse files- .gitignore +2 -2
- app.py +73 -9
- best.pt +2 -2
- samples/tomatoes.mp4 +0 -3
.gitignore
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
flagged/
|
2 |
*.png
|
3 |
*.jpg
|
4 |
-
*.mp4
|
5 |
*.mkv
|
6 |
-
gradio_cached_examples/
|
|
|
|
1 |
flagged/
|
2 |
*.png
|
3 |
*.jpg
|
|
|
4 |
*.mkv
|
5 |
+
gradio_cached_examples/
|
6 |
+
venv/
|
app.py
CHANGED
@@ -33,20 +33,49 @@ model = YOLO('best.pt')
|
|
33 |
path = [['image_0.jpg'], ['image_1.jpg']]
|
34 |
video_path = [['video.mp4']]
|
35 |
|
|
|
|
|
|
|
36 |
def show_preds_image(image_path):
|
37 |
image = cv2.imread(image_path)
|
38 |
outputs = model.predict(source=image_path)
|
39 |
results = outputs[0].cpu().numpy()
|
40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
cv2.rectangle(
|
42 |
image,
|
43 |
-
(
|
44 |
-
(
|
45 |
-
color=
|
46 |
thickness=2,
|
47 |
lineType=cv2.LINE_AA
|
48 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
return cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
|
|
50 |
|
51 |
inputs_image = [
|
52 |
gr.components.Image(type="filepath", label="Input Image"),
|
@@ -71,19 +100,54 @@ def show_preds_video(video_path):
|
|
71 |
frame_copy = frame.copy()
|
72 |
outputs = model.predict(source=frame)
|
73 |
results = outputs[0].cpu().numpy()
|
74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
cv2.rectangle(
|
76 |
frame_copy,
|
77 |
-
(
|
78 |
-
(
|
79 |
-
color=
|
80 |
thickness=2,
|
81 |
lineType=cv2.LINE_AA
|
82 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
yield cv2.cvtColor(frame_copy, cv2.COLOR_BGR2RGB)
|
|
|
|
|
|
|
|
|
84 |
|
85 |
inputs_video = [
|
86 |
-
gr.components.Video(
|
87 |
|
88 |
]
|
89 |
outputs_video = [
|
|
|
33 |
path = [['image_0.jpg'], ['image_1.jpg']]
|
34 |
video_path = [['video.mp4']]
|
35 |
|
36 |
+
|
37 |
+
|
38 |
+
|
39 |
def show_preds_image(image_path):
|
40 |
image = cv2.imread(image_path)
|
41 |
outputs = model.predict(source=image_path)
|
42 |
results = outputs[0].cpu().numpy()
|
43 |
+
|
44 |
+
# Print the detected objects' information (class, coordinates, and probability)
|
45 |
+
box = results[0].boxes
|
46 |
+
names = model.model.names
|
47 |
+
boxes = results.boxes
|
48 |
+
|
49 |
+
for box, conf, cls in zip(boxes.xyxy, boxes.conf, boxes.cls):
|
50 |
+
|
51 |
+
x1, y1, x2, y2 = map(int, box)
|
52 |
+
|
53 |
+
class_name = names[int(cls)]
|
54 |
+
print(class_name, "class_name", class_name.lower() == 'ripe')
|
55 |
+
if class_name.lower() == 'ripe':
|
56 |
+
color = (0, 0, 255) # Red for ripe
|
57 |
+
else:
|
58 |
+
color = (0, 255, 0) # Green for unripe
|
59 |
+
|
60 |
+
# Draw rectangle around object
|
61 |
cv2.rectangle(
|
62 |
image,
|
63 |
+
(x1, y1),
|
64 |
+
(x2, y2),
|
65 |
+
color=color,
|
66 |
thickness=2,
|
67 |
lineType=cv2.LINE_AA
|
68 |
)
|
69 |
+
|
70 |
+
# Display class label on top of rectangle
|
71 |
+
label = f"{class_name.capitalize()}: {conf:.2f}"
|
72 |
+
cv2.putText(image, label, (x1, y1-10), cv2.FONT_HERSHEY_SIMPLEX, 0.9, color, # Use the same color as the rectangle
|
73 |
+
2,
|
74 |
+
cv2.LINE_AA)
|
75 |
+
|
76 |
+
# Convert image to RGB (Gradio expects RGB format)
|
77 |
return cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
78 |
+
|
79 |
|
80 |
inputs_image = [
|
81 |
gr.components.Image(type="filepath", label="Input Image"),
|
|
|
100 |
frame_copy = frame.copy()
|
101 |
outputs = model.predict(source=frame)
|
102 |
results = outputs[0].cpu().numpy()
|
103 |
+
|
104 |
+
boxes = results.boxes
|
105 |
+
confidences = boxes.conf
|
106 |
+
classes = boxes.cls
|
107 |
+
names = model.model.names
|
108 |
+
|
109 |
+
for box, conf, cls in zip(boxes.xyxy, confidences, classes):
|
110 |
+
x1, y1, x2, y2 = map(int, box)
|
111 |
+
|
112 |
+
# Determine color based on class
|
113 |
+
class_name = names[int(cls)]
|
114 |
+
if class_name.lower() == 'ripe':
|
115 |
+
color = (0, 0, 255) # Red for ripe
|
116 |
+
else:
|
117 |
+
color = (0, 255, 0) # Green for unripe
|
118 |
+
|
119 |
+
# Draw rectangle around object
|
120 |
cv2.rectangle(
|
121 |
frame_copy,
|
122 |
+
(x1, y1),
|
123 |
+
(x2, y2),
|
124 |
+
color=color,
|
125 |
thickness=2,
|
126 |
lineType=cv2.LINE_AA
|
127 |
)
|
128 |
+
|
129 |
+
# Display class label on top of rectangle with capitalized class name
|
130 |
+
label = f"{class_name.capitalize()}: {conf:.2f}"
|
131 |
+
cv2.putText(
|
132 |
+
frame_copy,
|
133 |
+
label,
|
134 |
+
(x1, y1 - 10), # Position slightly above the top of the rectangle
|
135 |
+
cv2.FONT_HERSHEY_SIMPLEX,
|
136 |
+
0.5,
|
137 |
+
color, # Use the same color as the rectangle
|
138 |
+
1,
|
139 |
+
cv2.LINE_AA
|
140 |
+
)
|
141 |
+
|
142 |
+
# Convert frame to RGB (Gradio expects RGB format)
|
143 |
yield cv2.cvtColor(frame_copy, cv2.COLOR_BGR2RGB)
|
144 |
+
else:
|
145 |
+
break
|
146 |
+
|
147 |
+
cap.release()
|
148 |
|
149 |
inputs_video = [
|
150 |
+
gr.components.Video(label="Input Video"),
|
151 |
|
152 |
]
|
153 |
outputs_video = [
|
best.pt
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:5327d18a7f7555da46b1200f7a0b6929bb5d2f91fddb02ac0c79e9c481c32e51
|
3 |
+
size 6247395
|
samples/tomatoes.mp4
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:605d5fb1a532865bd93c5cc08d92b9804d8987f6aedc66c88e9ca32ad9932fc1
|
3 |
-
size 2537426
|
|
|
|
|
|
|
|