himisir commited on
Commit
fd10dcd
1 Parent(s): 6b3b667
Files changed (3) hide show
  1. .gitignore +7 -0
  2. app.py +68 -0
  3. requirments.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,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import time
2
+ import gradio as gr
3
+ import cv2 as cv
4
+ from ultralytics import YOLO
5
+
6
+
7
+ def load_yolo_model():
8
+ return YOLO()
9
+
10
+
11
+ def process_video(model, cap):
12
+ while cap.isOpened():
13
+ ret, image = cap.read()
14
+ if not ret:
15
+ break
16
+ start = time.perf_counter()
17
+ results = model(image)
18
+ end = time.perf_counter()
19
+ segments = results[0].plot()
20
+ cv.putText(segments, f'FPS: {int(1 // (end - start))}', (10, 30),
21
+ cv.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2)
22
+ cv.imshow('Image Segmentation', segments)
23
+ key = cv.waitKey(1)
24
+ if key & 0xFF == ord('q'):
25
+ break
26
+ cap.release()
27
+ cv.destroyAllWindows()
28
+
29
+
30
+ def segment_video(uploaded_video):
31
+ model = load_yolo_model()
32
+ cap = cv.VideoCapture(uploaded_video.name)
33
+ process_video(model, cap)
34
+
35
+
36
+ def segment_webcam():
37
+ model = load_yolo_model()
38
+ cap = cv.VideoCapture(0)
39
+ process_video(model, cap)
40
+
41
+
42
+ def wrapper_for_segment_video(uploaded_video):
43
+ segment_video(uploaded_video)
44
+
45
+
46
+ iface = gr.Interface(
47
+ fn=None,
48
+ inputs=[gr.inputs.Checkbox(label="Segment Video"),
49
+ gr.inputs.Checkbox(label="Segment Webcam"),
50
+ gr.inputs.File(label="Upload Video")],
51
+ outputs=None,
52
+ live=True
53
+ )
54
+
55
+
56
+ def update_fn(segment_video_checkbox, segment_webcam_checkbox, uploaded_video):
57
+ if segment_video_checkbox and uploaded_video:
58
+ iface.fn = wrapper_for_segment_video
59
+ iface.args = [uploaded_video]
60
+ elif segment_webcam_checkbox:
61
+ iface.fn = segment_webcam
62
+ iface.args = []
63
+ else:
64
+ iface.fn = None
65
+
66
+
67
+ iface.update(update_fn)
68
+ iface.launch()
requirments.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