I am building a video classification app in streamlit and trying to do…
- Get query video via
- Convert it to numpy array or torch tensor
- Preview it with
- Run my model.
My app is working as expected but my current implementation requires the app to copy the uploaded file into working directory and passing the path of copied one to st.video to preview it.
uploaded_video = st.file_uploader("Choose video", type=["mp4", "avi"]) if uploaded_video is not None: # run only when user uploads video vid = uploaded_video.name with open(vid, mode="wb") as f: f.write(uploaded_video.read()) query = (glob("*.mp4") + glob("./*.avi")) video_tensor = torchvision.io.read_video(query) st.video(query)
I am feeling it pretty wasteful and looking for the way to directory convert
uploadedFile object into numpy array. Is there anyway to do so?
If there is such way, I think it’s useful for others dealing with video recognition task so wishing to get some help. Thanks in advance.