BrainAI-1 commited on
Commit
3818b72
·
verified ·
1 Parent(s): 6d97312

Upload 10 files

Browse files
.gitattributes CHANGED
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ data/breakfast.mp4 filter=lfs diff=lfs merge=lfs -text
37
+ data/school.mp4 filter=lfs diff=lfs merge=lfs -text
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import cv2
3
+ from utils import object_detection_brainai as odb
4
+ object_detection = odb.ObjectDetectionModel()
5
+
6
+ def detect_image(img):
7
+ result_img = object_detection.process(img)
8
+
9
+ return result_img
10
+
11
+
12
+ def detect_video(video_path, ):
13
+ frames, fps, frame_width, frame_height = object_detection.detect_objects_in_video(video_path)
14
+ output_video_path = object_detection.create_video(frames, fps, frame_width, frame_height)
15
+
16
+ return output_video_path
17
+
18
+ image_interface = gr.Interface(
19
+ fn=detect_image,
20
+ inputs=gr.Image(label="Upload Image"),
21
+ outputs="image",
22
+ examples = ['data/desk.jpg', 'data/office.jpg'],
23
+ title="Image Object Detection"
24
+ )
25
+
26
+ video_interface = gr.Interface(
27
+ fn=detect_video,
28
+ inputs=gr.Video(label="Upload Video"),
29
+ examples = ['data/breakfast.mp4', 'data/school.mp4'],
30
+ outputs="video",
31
+ title="Video Object Detection"
32
+ )
33
+
34
+ demo = gr.TabbedInterface([image_interface, video_interface], ["Image", "Video"])
35
+
36
+ demo.launch()
data/breakfast.mp4 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c72555727af845f336b68f204186b8012781979dafa7e7abb3a4671590f4049c
3
+ size 1396102
data/desk.jpg ADDED
data/office.jpg ADDED
data/school.mp4 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:636ee794077188d85c717722e49024595a3381deac75acf1471410ab88028a8f
3
+ size 2837273
models/yolov8n.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f59b3d833e2ff32e194b5bb8e08d211dc7c5bdf144b90d2c8412c47ccfc83b36
3
+ size 6549796
models/yolov8n_openvino_model/metadata.yaml ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ description: Ultralytics YOLOv8n model trained on coco.yaml
2
+ author: Ultralytics
3
+ date: '2024-11-27T09:26:37.990600'
4
+ version: 8.3.34
5
+ license: AGPL-3.0 License (https://ultralytics.com/license)
6
+ docs: https://docs.ultralytics.com
7
+ stride: 32
8
+ task: detect
9
+ batch: 1
10
+ imgsz:
11
+ - 640
12
+ - 640
13
+ names:
14
+ 0: person
15
+ 1: bicycle
16
+ 2: car
17
+ 3: motorcycle
18
+ 4: airplane
19
+ 5: bus
20
+ 6: train
21
+ 7: truck
22
+ 8: boat
23
+ 9: traffic light
24
+ 10: fire hydrant
25
+ 11: stop sign
26
+ 12: parking meter
27
+ 13: bench
28
+ 14: bird
29
+ 15: cat
30
+ 16: dog
31
+ 17: horse
32
+ 18: sheep
33
+ 19: cow
34
+ 20: elephant
35
+ 21: bear
36
+ 22: zebra
37
+ 23: giraffe
38
+ 24: backpack
39
+ 25: umbrella
40
+ 26: handbag
41
+ 27: tie
42
+ 28: suitcase
43
+ 29: frisbee
44
+ 30: skis
45
+ 31: snowboard
46
+ 32: sports ball
47
+ 33: kite
48
+ 34: baseball bat
49
+ 35: baseball glove
50
+ 36: skateboard
51
+ 37: surfboard
52
+ 38: tennis racket
53
+ 39: bottle
54
+ 40: wine glass
55
+ 41: cup
56
+ 42: fork
57
+ 43: knife
58
+ 44: spoon
59
+ 45: bowl
60
+ 46: banana
61
+ 47: apple
62
+ 48: sandwich
63
+ 49: orange
64
+ 50: broccoli
65
+ 51: carrot
66
+ 52: hot dog
67
+ 53: pizza
68
+ 54: donut
69
+ 55: cake
70
+ 56: chair
71
+ 57: couch
72
+ 58: potted plant
73
+ 59: bed
74
+ 60: dining table
75
+ 61: toilet
76
+ 62: tv
77
+ 63: laptop
78
+ 64: mouse
79
+ 65: remote
80
+ 66: keyboard
81
+ 67: cell phone
82
+ 68: microwave
83
+ 69: oven
84
+ 70: toaster
85
+ 71: sink
86
+ 72: refrigerator
87
+ 73: book
88
+ 74: clock
89
+ 75: vase
90
+ 76: scissors
91
+ 77: teddy bear
92
+ 78: hair drier
93
+ 79: toothbrush
models/yolov8n_openvino_model/yolov8n.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:48b86fce278a5a6833dc015b7af8cbcb7174004a5f9b6ff7ec724f753f361681
3
+ size 12708656
models/yolov8n_openvino_model/yolov8n.xml ADDED
The diff for this file is too large to render. See raw diff
 
utils/object_detection_brainai.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from ultralytics import YOLO
2
+ import cv2
3
+
4
+ class ObjectDetectionModel():
5
+
6
+ def __init__(self):
7
+ self.model = YOLO("models/yolov8n_openvino_model", task = "detect")
8
+ self.class_names = self.model.names
9
+
10
+ def process(self, img):
11
+ result = self.model(img)
12
+ img_plot = result[0].plot()
13
+
14
+ return img_plot
15
+
16
+
17
+ def detect_objects_in_video(self, video_path, conf_thres=0.25, iou_thres=0.45):
18
+ cap = cv2.VideoCapture(video_path)
19
+ frame_width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
20
+ frame_height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
21
+ fps = cap.get(cv2.CAP_PROP_FPS)
22
+ frames = []
23
+
24
+ while cap.isOpened():
25
+ ret, frame = cap.read()
26
+ if not ret:
27
+ break
28
+
29
+ img_plot = self.process(frame)
30
+ frames.append(img_plot)
31
+ cap.release()
32
+ return frames, fps, frame_width, frame_height
33
+
34
+ def create_video(self, frames, fps, frame_width, frame_height):
35
+ fourcc = cv2.VideoWriter_fourcc(*'mp4v')
36
+ out_path = 'output_video.mp4'
37
+ out = cv2.VideoWriter(out_path, fourcc, fps, (frame_width, frame_height))
38
+
39
+ for frame in frames:
40
+ out.write(frame)
41
+
42
+ out.release()
43
+ return out_path
44
+
45
+