Yolov5 Real-time Inference for Images and Videos on Streamlit

Hello everyone, I wanted to share with you my first Streamlit app.
It’s a simple interface for yolov5 inference.

output

Live Demo

live demo

Features

  • Caches the model for faster inference on both CPU and GPU
  • Supports both images and videos.
  • Supports both CPU and GPU inference.
  • Supports Custom Classes and changing Confidence.

How to run

deploy using Streamlit Cloud or:
github repo

clone repo:
git clone https://github.com/moaaztaha/Yolo-Interface-using-Streamlit
After cloning the repo:

  1. Install requirements
  • pip install -r requirements.txt
  1. Add sample images to data/sample_images
  2. Add sample video to data/sample_videos and call it sample.mp4 or change the name in the code.
  3. Add the model file to models/ and change cfg_model_path to its path.
cd Yolo-Interface-using-Streamlit 
streamlit run app.py

References

3 Likes

I use st.image(frame) with size 640, fps 16
st.image(frame) with 1080, fpt 12
Do you know how to improve the speed of st.image function?
Thank you!

1 Like

I really tried to find a solution for this but I can’t find any.
So I’m planning to do patch processing and just show the final video

I used ffmpeg to push stream
ffmpeg .input('pipe:', format='rawvideo',codec="rawvideo", pix_fmt='bgr24', s='{}x{}'.format(1920, 1080)) .output( "stream.m3u8", preset="fast", vcodec="h264_nvenc", hls_time=10, hls_list_size=10, hls_segment_filename="stream_%03d.ts", f='hls' ) .overwrite_output() .run_async(pipe_stdin=True)
You can use ffmpeg to convert file video → file m3u8, use streamlit (st_player) to play m3u8
st_player + plugin video speed controller in firefox to run in firefox

Hi @moaztaha , thanks for sharing.

Is there anyway of doing this in real time? Say with web-rtc.