I created a simple Web App using Streamlit that receives an RTSP stream from a source and, applies an object detection model, and updates the image.
The code is as follows
import streamlit as st
from streamlit_webrtc import webrtc_streamer
import av
import cv2
import time
import threading
import video_capture
import numpy as np
from detector import Detector
image = np.zeros((480, 640, 3), dtype=np.uint8)
def inference_worker(detector : Detector, cap : video_capture.VideoCapture, FPS : float):
global image
while True:
frame = cap.get_frame()
print(frame.shape)
detector.detect(frame)
vis = detector.draw_preds()
image = cv2.resize(vis, dsize=(640, 480))
st.title("Object Detection")
st1_text = st.markdown("FPS")
image_placeholder = st.empty()
cap = video_capture.VideoCapture(
video_source=RTSP_STREAM,
FPS=30
)
cap.start()
FPS : float = 20
detector = Detector(
"./weights/best.pt",
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
(640, 640)
)
inference_process = threading.Thread(target=inference_worker, args=(detector, cap, FPS))
inference_process.start()
while True:
t1 = time.perf_counter()
image_placeholder.image(image, channels="BGR")
t2 = time.perf_counter()
sleep : float = 1.0/FPS - (t2-t1)
if sleep < 0:
continue
else:
time.sleep(sleep)
st1_text.markdown(f"FPS: {1/(t2-t1):.2f}")
cap.close()
inference_process.join()
Locally, it works perfectly fine. But, I’m using a computer stronger than mine from vast.ai. It has a faster GPU and Processor to run the application. I deployed my app there.
When I open the external link to access the Web App, the images are not being updated as they were locally. I even included the FPS parameter to check the FPS of the application, but it is running at 30+ FPS.
Any thoughts?