Update app.py
Browse files
app.py
CHANGED
@@ -4,8 +4,8 @@ import numpy as np
|
|
4 |
import torch
|
5 |
from ultralytics import YOLO
|
6 |
|
7 |
-
# Load
|
8 |
-
model = YOLO("yolov12x.pt") #
|
9 |
|
10 |
# Class label for trucks (COCO dataset)
|
11 |
TRUCK_CLASS_ID = 7 # "truck" in COCO dataset
|
@@ -28,7 +28,7 @@ def count_trucks(video_path):
|
|
28 |
if frame_count % frame_skip != 0:
|
29 |
continue # Skip frames to improve efficiency
|
30 |
|
31 |
-
# Run
|
32 |
results = model(frame, verbose=False)
|
33 |
|
34 |
truck_count = 0
|
@@ -45,8 +45,7 @@ def count_trucks(video_path):
|
|
45 |
cap.release()
|
46 |
|
47 |
return {
|
48 |
-
"Total Trucks in Video": int(np.max(truck_count_per_frame)) if truck_count_per_frame else 0
|
49 |
-
#"Avg Trucks Per Frame": round(np.mean(truck_count_per_frame), 2) if truck_count_per_frame else 0
|
50 |
}
|
51 |
|
52 |
# Gradio UI function
|
@@ -59,9 +58,9 @@ interface = gr.Interface(
|
|
59 |
fn=analyze_video,
|
60 |
inputs=gr.Video(label="Upload Video"),
|
61 |
outputs=gr.Textbox(label="Truck Counting Results"),
|
62 |
-
title="
|
63 |
-
description="Upload a video to detect and count trucks using
|
64 |
)
|
65 |
|
66 |
# Launch app
|
67 |
-
interface.launch()
|
|
|
4 |
import torch
|
5 |
from ultralytics import YOLO
|
6 |
|
7 |
+
# Load YOLOv12x model (pre-trained on COCO dataset)
|
8 |
+
model = YOLO("yolov12x.pt") # Update to YOLOv12x
|
9 |
|
10 |
# Class label for trucks (COCO dataset)
|
11 |
TRUCK_CLASS_ID = 7 # "truck" in COCO dataset
|
|
|
28 |
if frame_count % frame_skip != 0:
|
29 |
continue # Skip frames to improve efficiency
|
30 |
|
31 |
+
# Run YOLOv12x inference
|
32 |
results = model(frame, verbose=False)
|
33 |
|
34 |
truck_count = 0
|
|
|
45 |
cap.release()
|
46 |
|
47 |
return {
|
48 |
+
"Total Trucks in Video": int(np.max(truck_count_per_frame)) if truck_count_per_frame else 0
|
|
|
49 |
}
|
50 |
|
51 |
# Gradio UI function
|
|
|
58 |
fn=analyze_video,
|
59 |
inputs=gr.Video(label="Upload Video"),
|
60 |
outputs=gr.Textbox(label="Truck Counting Results"),
|
61 |
+
title="YOLOv12x-based Truck Counter",
|
62 |
+
description="Upload a video to detect and count trucks using YOLOv12x."
|
63 |
)
|
64 |
|
65 |
# Launch app
|
66 |
+
interface.launch()
|