Let's say I have designed an ML model that can take video input of a dog running around and give the breed of the dog as output. However, I do not want to wait for the video to finish before it is input into my model. I want something like the following to happen:

I am casually taking a video of my backyard when mid-way through a dog runs past the camera. Immediately, my model should identify (a) a dog has appeared within view and (b) the dog is a Labrador Retriever.

In an attempt to achieve the above, I have the following questions:

  1. Do I need to train a new model that detects when a dog has appeared within view?
  2. How can I make my model such that the input is continuous and that the model keeps running providing instant output?

Note 1: My ML model has been trained on Google Colaboratory using Keras. As of now, I have not established any connection between the camera and my model (I am unaware of how to do so). If any further details are required, I would be more than happy to share them!

Note 2: This question was originally posted on Stack Overflow. It was closed as a consequence of it being unfitting to the site. Link to the original post here.

Note 3: I also posted this question on Artificial Intelligence StackExchange. I was directed here. Link to the post on Artificial Intelligence StackExchange here.

  • $\begingroup$ Could you clarify how you currently get your video from your camera to any computing device? Do you already have a way to capture live feeds - if so, what is it, e.g. OpenCV, OBS or something bespoke that comes with the camera? $\endgroup$ Jul 20 '21 at 8:00
  • $\begingroup$ @NeilSlater To be completely honest, this is a hypothetical question that I was thinking about. I do intend, however, to create something like the above as an interesting experiment. For now, I think you can assume that I use OpenCV to capture video feed from my CCTV camera (using something like this: capture = cv2.VideoCapture('rtsp://username:password@')) I am, however, completely open to any other suggestions for what to use. $\endgroup$ Jul 20 '21 at 10:37

You do not need train a new model. You can find an existing neural network architecture that has been trained for "dog"/"not dog".

One option for continuous video input is use Python's OpenCV package which has a VideoCapture class which can read from an input stream. Individual frames can be extracted the stream. The model would predict "dog"/"not dog" on the frames.

Something like this:

import cv2

video = cv2.VideoCapture(0)

while True:
    _, frame = video.read()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.