dwkurnie commited on
Commit
fa11d8c
·
1 Parent(s): 306aa59
Files changed (3) hide show
  1. .gitignore +7 -0
  2. app.py +76 -0
  3. requirements.txt +47 -0
.gitignore ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ flagged/
2
+ *.pt
3
+ *.png
4
+ *.jpg
5
+ *.mp4
6
+ *.mkv
7
+ gradio_cached_examples/
app.py ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import cv2
3
+ from ultralytics import YOLO
4
+
5
+ # Load YOLO model
6
+ model = YOLO('best.pt')
7
+
8
+ # Function to perform object detection on an image
9
+ def show_preds_image(image_path):
10
+ image = cv2.imread(image_path)
11
+ outputs = model.predict(source=image_path)
12
+ results = outputs[0].cpu().numpy()
13
+ for i, det in enumerate(results.boxes.xyxy):
14
+ cv2.rectangle(
15
+ image,
16
+ (int(det[0]), int(det[1])),
17
+ (int(det[2]), int(det[3])),
18
+ color=(0, 0, 255),
19
+ thickness=2,
20
+ lineType=cv2.LINE_AA
21
+ )
22
+ return cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
23
+
24
+ # Define inputs and outputs for image interface
25
+ inputs_image = [
26
+ gr.inputs.Image(type="filepath", label="Input Image"),
27
+ ]
28
+ outputs_image = [
29
+ gr.outputs.Image(type="numpy", label="Output Image"),
30
+ ]
31
+ interface_image = gr.Interface(
32
+ fn=show_preds_image,
33
+ inputs=inputs_image,
34
+ outputs=outputs_image,
35
+ title="Garbage Detector (Image Input)",
36
+ )
37
+
38
+ # Function to perform object detection on a video stream
39
+ def show_preds_video(video_stream):
40
+ cap = cv2.VideoCapture(video_stream.name)
41
+ while(cap.isOpened()):
42
+ ret, frame = cap.read()
43
+ if ret:
44
+ frame_copy = frame.copy()
45
+ outputs = model.predict(source=frame)
46
+ results = outputs[0].cpu().numpy()
47
+ for i, det in enumerate(results.boxes.xyxy):
48
+ cv2.rectangle(
49
+ frame_copy,
50
+ (int(det[0]), int(det[1])),
51
+ (int(det[2]), int(det[3])),
52
+ color=(0, 0, 255),
53
+ thickness=2,
54
+ lineType=cv2.LINE_AA
55
+ )
56
+ yield cv2.cvtColor(frame_copy, cv2.COLOR_BGR2RGB)
57
+
58
+ # Define inputs and outputs for video interface
59
+ inputs_video = [
60
+ gr.inputs.Video(type="webcam", label="Input Webcam"),
61
+ ]
62
+ outputs_video = [
63
+ gr.outputs.Image(type="numpy", label="Output Image"),
64
+ ]
65
+ interface_video = gr.Interface(
66
+ fn=show_preds_video,
67
+ inputs=inputs_video,
68
+ outputs=outputs_video,
69
+ title="Garbage Detector (Webcam Input)",
70
+ )
71
+
72
+ # Launch tabbed interface for both image and video inference
73
+ gr.TabbedInterface(
74
+ [interface_image, interface_video],
75
+ tab_names=['Image Inference', 'Video Inference']
76
+ ).launch()
requirements.txt ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Ultralytics requirements
2
+ # Usage: pip install -r requirements.txt
3
+
4
+ # Base ----------------------------------------
5
+ hydra-core>=1.2.0
6
+ matplotlib>=3.2.2
7
+ numpy>=1.18.5
8
+ opencv-python>=4.1.1
9
+ Pillow>=7.1.2
10
+ PyYAML>=5.3.1
11
+ requests>=2.23.0
12
+ scipy>=1.4.1
13
+ torch>=1.7.0
14
+ torchvision>=0.8.1
15
+ tqdm>=4.64.0
16
+ ultralytics
17
+
18
+ # Logging -------------------------------------
19
+ tensorboard>=2.4.1
20
+ # clearml
21
+ # comet
22
+
23
+ # Plotting ------------------------------------
24
+ pandas>=1.1.4
25
+ seaborn>=0.11.0
26
+
27
+ # Export --------------------------------------
28
+ # coremltools>=6.0 # CoreML export
29
+ # onnx>=1.12.0 # ONNX export
30
+ # onnx-simplifier>=0.4.1 # ONNX simplifier
31
+ # nvidia-pyindex # TensorRT export
32
+ # nvidia-tensorrt # TensorRT export
33
+ # scikit-learn==0.19.2 # CoreML quantization
34
+ # tensorflow>=2.4.1 # TF exports (-cpu, -aarch64, -macos)
35
+ # tensorflowjs>=3.9.0 # TF.js export
36
+ # openvino-dev # OpenVINO export
37
+
38
+ # Extras --------------------------------------
39
+ ipython # interactive notebook
40
+ psutil # system utilization
41
+ thop>=0.1.1 # FLOPs computation
42
+ # albumentations>=1.0.3
43
+ # pycocotools>=2.0.6 # COCO mAP
44
+ # roboflow
45
+
46
+ # HUB -----------------------------------------
47
+ GitPython>=3.1.24