from utils.plots import plot_one_box from PIL import ImageColor import subprocess import streamlit as st import psutil def get_gpu_memory(): result = subprocess.check_output( [ 'nvidia-smi', '--query-gpu=memory.used', '--format=csv,nounits,noheader' ], encoding='utf-8') gpu_memory = [int(x) for x in result.strip().split('\n')] return gpu_memory[0] def get_yolo(img, model_type, model, confidence, class_list, draw_thick): current_no_class = [] results = model(img) # if model_type == 'YOLOv8': # box = results.pandas().xyxy[0] # for i in box.index: # xmin, ymin, xmax, ymax, conf, id, class_name = int(box['xmin'][i]), int(box['ymin'][i]), int(box['xmax'][i]), \ # int(box['ymax'][i]), box['confidence'][i], box['class'][i], box['name'][i] # if conf > confidence: # plot_one_box([xmin, ymin, xmax, ymax], img, label=class_name, # 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)], line_thickness=draw_thick) current_no_class.append([class_list[int(cs)]]) return img, current_no_class def get_system_stat(stframe1, stframe2, stframe3, fps, df_fq): # Updating Inference results with stframe1.container(): st.markdown("

Inference Statistics

", unsafe_allow_html=True) if round(fps, 4)>1: st.markdown(f"

Frame Rate: {round(fps, 4)}

", unsafe_allow_html=True) else: st.markdown(f"

Frame Rate: {round(fps, 4)}

", unsafe_allow_html=True) with stframe2.container(): st.markdown("

Detected objects in curret Frame

", unsafe_allow_html=True) st.dataframe(df_fq, use_container_width=True) with stframe3.container(): st.markdown("

System Statistics

", unsafe_allow_html=True) js1, js2, js3 = st.columns(3) # Updating System stats with js1: st.markdown("

Memory usage

", unsafe_allow_html=True) mem_use = psutil.virtual_memory()[2] if mem_use > 50: js1_text = st.markdown(f"
{mem_use}%
", unsafe_allow_html=True) else: js1_text = st.markdown(f"
{mem_use}%
", unsafe_allow_html=True) with js2: st.markdown("

CPU Usage

", unsafe_allow_html=True) cpu_use = psutil.cpu_percent() if mem_use > 50: js2_text = st.markdown(f"
{cpu_use}%
", unsafe_allow_html=True) else: js2_text = st.markdown(f"
{cpu_use}%
", unsafe_allow_html=True) with js3: st.markdown("

GPU Memory Usage

", unsafe_allow_html=True) try: js3_text = st.markdown(f'
{get_gpu_memory()} MB
', unsafe_allow_html=True) except: js3_text = st.markdown('
NA
', unsafe_allow_html=True)