From 78f486f2d99a14f36ee16c9f20639e435be5405e Mon Sep 17 00:00:00 2001 From: NASEEM A P Date: Sun, 22 Sep 2024 09:06:10 +0530 Subject: [PATCH 1/6] updated get_yolo fn, added tracker to yolov8 model, added bytetrack, botsort --- model_utils.py | 47 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/model_utils.py b/model_utils.py index 53396de..a9324c1 100644 --- a/model_utils.py +++ b/model_utils.py @@ -21,10 +21,10 @@ def color_picker_fn(classname, key): return color -def get_yolo(img, model_type, model, confidence, color_pick_list, class_list, draw_thick): +def get_yolo(img, model_type, model, confidence, color_pick_list, class_list, draw_thick, Tracker): current_no_class = [] - results = model(img) if model_type == 'YOLOv7': + results = model(img) box = results.pandas().xyxy[0] for i in box.index: @@ -35,18 +35,37 @@ def get_yolo(img, model_type, model, confidence, color_pick_list, class_list, dr color=color_pick_list[id], line_thickness=draw_thick) current_no_class.append([class_name]) - if model_type == 'YOLOv8': - for result in results: - bboxs = result.boxes.xyxy - conf = result.boxes.conf - cls = result.boxes.cls - for bbox, cnf, cs in zip(bboxs, conf, cls): - xmin = int(bbox[0]) - ymin = int(bbox[1]) - xmax = int(bbox[2]) - ymax = int(bbox[3]) - if cnf > confidence: - plot_one_box([xmin, ymin, xmax, ymax], img, label=class_list[int(cs)], + elif model_type == 'YOLOv8': + if Tracker == "Tracker": + results = model.predict(img, conf=confidence) + for result in results: + bboxs = result.boxes.xyxy + conf = result.boxes.conf + cls = result.boxes.cls + for bbox, cnf, cs in zip(bboxs, conf, cls): + xmin = int(bbox[0]) + ymin = int(bbox[1]) + xmax = int(bbox[2]) + ymax = int(bbox[3]) + # if cnf > confidence: + plot_one_box([xmin, ymin, xmax, ymax], img, label=f"{class_list[int(cs)]} {cnf:.3}", + color=color_pick_list[int(cs)], line_thickness=draw_thick) + current_no_class.append([class_list[int(cs)]]) + + elif Tracker != "Tracker": + results = model.track(img, tracker=f"tracker/{Tracker}.yaml") + for result in results: + bboxs = result.boxes.xyxy + conf = result.boxes.conf + cls = result.boxes.cls + track_id = result.boxes.id.int().cpu().tolist() + for bbox, cnf, cs, id in zip(bboxs, conf, cls, track_id): + xmin = int(bbox[0]) + ymin = int(bbox[1]) + xmax = int(bbox[2]) + ymax = int(bbox[3]) + # if cnf > confidence: + plot_one_box([xmin, ymin, xmax, ymax], img, label=f"ID: {id} {class_list[int(cs)]} {cnf:.3}", color=color_pick_list[int(cs)], line_thickness=draw_thick) current_no_class.append([class_list[int(cs)]]) return img, current_no_class From 14b22136ed173714e88440af9aa5bff9048c2e90 Mon Sep 17 00:00:00 2001 From: NASEEM A P Date: Sun, 22 Sep 2024 09:06:39 +0530 Subject: [PATCH 2/6] added bytetrack, botsort config --- tracker/botsort.yaml | 18 ++++++++++++++++++ tracker/bytetrack.yaml | 11 +++++++++++ 2 files changed, 29 insertions(+) create mode 100644 tracker/botsort.yaml create mode 100644 tracker/bytetrack.yaml diff --git a/tracker/botsort.yaml b/tracker/botsort.yaml new file mode 100644 index 0000000..3683044 --- /dev/null +++ b/tracker/botsort.yaml @@ -0,0 +1,18 @@ +# Ultralytics YOLO 🚀, AGPL-3.0 license +# Default YOLO tracker settings for BoT-SORT tracker https://github.com/NirAharon/BoT-SORT + +tracker_type: botsort # tracker type, ['botsort', 'bytetrack'] +track_high_thresh: 0.5 # threshold for the first association +track_low_thresh: 0.1 # threshold for the second association +new_track_thresh: 0.6 # threshold for init new track if the detection does not match any tracks +track_buffer: 30 # buffer to calculate the time when to remove tracks +match_thresh: 0.8 # threshold for matching tracks +fuse_score: True # Whether to fuse confidence scores with the iou distances before matching +# min_box_area: 10 # threshold for min box areas(for tracker evaluation, not used for now) + +# BoT-SORT settings +gmc_method: sparseOptFlow # method of global motion compensation +# ReID model related thresh (not supported yet) +proximity_thresh: 0.5 +appearance_thresh: 0.25 +with_reid: False \ No newline at end of file diff --git a/tracker/bytetrack.yaml b/tracker/bytetrack.yaml new file mode 100644 index 0000000..3465b2e --- /dev/null +++ b/tracker/bytetrack.yaml @@ -0,0 +1,11 @@ +# Ultralytics YOLO 🚀, AGPL-3.0 license +# Default YOLO tracker settings for ByteTrack tracker https://github.com/ifzhang/ByteTrack + +tracker_type: bytetrack # tracker type, ['botsort', 'bytetrack'] +track_high_thresh: 0.5 # threshold for the first association +track_low_thresh: 0.1 # threshold for the second association +new_track_thresh: 0.6 # threshold for init new track if the detection does not match any tracks +track_buffer: 30 # buffer to calculate the time when to remove tracks +match_thresh: 0.8 # threshold for matching tracks +fuse_score: True # Whether to fuse confidence scores with the iou distances before matching +# min_box_area: 10 # threshold for min box areas(for tracker evaluation, not used for now) \ No newline at end of file From b0cfa06b48712fb32362dfd27d2600e82bf9b4d5 Mon Sep 17 00:00:00 2001 From: NASEEM A P Date: Sun, 22 Sep 2024 09:07:16 +0530 Subject: [PATCH 3/6] added tracker option, added bytetrack, botsort, only for yolov8 model --- app.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/app.py b/app.py index aa4c3f2..643dc66 100644 --- a/app.py +++ b/app.py @@ -9,7 +9,6 @@ import json import pandas as pd from model_utils import get_yolo, color_picker_fn, get_system_stat -# from ultralytics import YOLO p_time = 0 @@ -52,7 +51,7 @@ model = custom(path_or_model=path_model_file, gpu=True) # YOLOv8 Model - if model_type == 'YOLOv8': + elif model_type == 'YOLOv8': from ultralytics import YOLO model = YOLO(path_model_file) @@ -62,6 +61,8 @@ # Inference Mode options = st.sidebar.radio( 'Options:', ('Webcam', 'Image', 'Video', 'RTSP'), index=1) + + tracker = st.sidebar.selectbox("Choose Tracker", ("Tracker", "bytetrack", "botsort")) # Confidence confidence = st.sidebar.slider( @@ -91,7 +92,11 @@ FRAME_WINDOW.image(img, channels='BGR') if pred: - img, current_no_class = get_yolo(img, model_type, model, confidence, color_pick_list, class_labels, draw_thick) + img, current_no_class = get_yolo( + img, model_type, model, confidence, + color_pick_list, class_labels, draw_thick, + Tracker=tracker + ) FRAME_WINDOW.image(img, channels='BGR') # Current number of classes @@ -107,7 +112,7 @@ st.dataframe(df_fq, use_container_width=True) # Video - if options == 'Video': + elif options == 'Video': upload_video_file = st.sidebar.file_uploader( 'Upload Video', type=['mp4', 'avi', 'mkv']) if upload_video_file is not None: @@ -120,7 +125,7 @@ # Web-cam - if options == 'Webcam': + elif options == 'Webcam': cam_options = st.sidebar.selectbox('Webcam Channel', ('Select Channel', '0', '1', '2', '3')) @@ -130,7 +135,7 @@ # RTSP - if options == 'RTSP': + elif options == 'RTSP': rtsp_url = st.sidebar.text_input( 'RTSP URL:', 'eg: rtsp://admin:name6666@198.162.1.58/cam/realmonitor?channel=0&subtype=0' @@ -152,7 +157,11 @@ ) break - img, current_no_class = get_yolo(img, model_type, model, confidence, color_pick_list, class_labels, draw_thick) + img, current_no_class = get_yolo( + img, model_type, model, confidence, + color_pick_list, class_labels, draw_thick, + Tracker=tracker + ) FRAME_WINDOW.image(img, channels='BGR') # FPS From 6737897b35e37170864d55677aa62edda35ffd29 Mon Sep 17 00:00:00 2001 From: NASEEM A P Date: Sun, 22 Sep 2024 09:13:59 +0530 Subject: [PATCH 4/6] updated clone repo to copy --- Dockerfile | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 854c80e..fc41397 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,15 @@ FROM ubuntu:20.04 ARG DEBIAN_FRONTEND=noninteractive +COPY . /App RUN apt-get update && \ - apt-get install -y \ - python3 \ - python3-pip \ - ffmpeg \ - libsm6 \ - libxext6 \ - git -RUN git clone https://github.com/naseemap47/streamlit-yolo.git App +apt-get install -y \ +python3 \ +python3-pip \ +ffmpeg \ +libsm6 \ +libxext6 \ +git WORKDIR /App +RUN cd streamlit-yolo RUN pip install -r requirements.txt CMD [ "streamlit", "run", "app.py" ] \ No newline at end of file From 0e94aba78fc09d62c5555e4ed15cdbaa21f6dabb Mon Sep 17 00:00:00 2001 From: NASEEM A P Date: Sun, 22 Sep 2024 09:17:42 +0530 Subject: [PATCH 5/6] fixed issue with work_dir --- Dockerfile | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index fc41397..174f3db 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM ubuntu:20.04 ARG DEBIAN_FRONTEND=noninteractive -COPY . /App +COPY . /home RUN apt-get update && \ apt-get install -y \ python3 \ @@ -9,7 +9,6 @@ ffmpeg \ libsm6 \ libxext6 \ git -WORKDIR /App -RUN cd streamlit-yolo +WORKDIR /home/streamlit-yolo RUN pip install -r requirements.txt CMD [ "streamlit", "run", "app.py" ] \ No newline at end of file From 12f14536962de4d0c5de41539b1952cec0b8c968 Mon Sep 17 00:00:00 2001 From: NASEEM A P Date: Sun, 22 Sep 2024 09:25:45 +0530 Subject: [PATCH 6/6] revert back - Dockerfile --- Dockerfile | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index 174f3db..854c80e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,14 @@ FROM ubuntu:20.04 ARG DEBIAN_FRONTEND=noninteractive -COPY . /home RUN apt-get update && \ -apt-get install -y \ -python3 \ -python3-pip \ -ffmpeg \ -libsm6 \ -libxext6 \ -git -WORKDIR /home/streamlit-yolo + apt-get install -y \ + python3 \ + python3-pip \ + ffmpeg \ + libsm6 \ + libxext6 \ + git +RUN git clone https://github.com/naseemap47/streamlit-yolo.git App +WORKDIR /App RUN pip install -r requirements.txt CMD [ "streamlit", "run", "app.py" ] \ No newline at end of file