Skip to content

Amazon SageMaker (Video or Image?)

0

Hello!

I am planning on labeling a dataset through SageMaker in a custom way. The current data is in mp4 format. The goal of the ML is to do positional analysis on the object in focus from the video. The camera is fixed in this case. In technicality, I only need a one frame/jpeg from the video of the object in focus. There are two questions I am currently asking myself of where I am stuck.

  1. Is doing a computer vision ML Algorithm with images better than doing it with videos? What are the pros and cons of utilizing images over videos, considering that there will also have to a script that extracts a specific frame from the video (will take time).

  2. The video sometimes includes obstructions such as a human passing by the camera. I only want to extract a frame that does not include those obstructions. How should I go about solving this issue if I am to write a script to extract a specific frame based on certain parameters?

Thank you!

2 Answers
0
Accepted Answer

The best solution will likely depend on:

  1. What kind of object you're looking at (whether it's something common that Rekognition could already pick up with no training required, as mentioned in Didier's answer - or whether it's something that might be intrinsically difficult like shiny/mirrored surfaces, or etc)
  2. Whether your solution needs to operate "online" with streaming video & low-latency detections, or just process already-captured video files in batch.
  3. How fast of a frame rate you need to capture the important things happening in your scene.
  4. Whether you need to track the object around between multiple frames, or (it sounds like) just extract one particular occasion where the object appeared.

In general, video is very high-bandwidth data and real-world storage formats (e.g. mp4) are compressed very efficiently. If your scene moves quite slowly so that you only need to analyse 1FPS or less to get a good picture of what's going on, then yes treating this as an image analysis problem might be most efficient. If you need to analyze every frame of e.g. 30FPS video (perhaps because your target object is only in shot briefly, or actions/motion in the video are important, or you need to track the same object's motion over time) - then I'd really try to avoid anything that converts every frame image into an HTTP(S) request because it'll be a lot of data movement. Even if the network cost isn't an issue, the speed is likely to be slow.

Most ML models for video are anyway a combination of some frame-wise image processing and then some aggregator between frames: For example see ByteTrack and FairMOT for multi-object tracking. The lower the frame-rate, the more things reduce to just being the same as image analysis.

Libraries like ffmpeg (which has some Python binding options) and OpenCV can help with splitting video into chunks and iterating through frames from Python. You can absolutely make a SageMaker model that takes short video chunks (mp4/mkv/etc) rather than images as a payload, so long as your input_fn or similar knows how to load them into a format your ML model understands.

If you need streaming, Kinesis Video Streams Consumer Library for Python could give you an option to use Kinesis to handle your video streaming and then read those streamed chunks into a Python environment. Consumers need to pull chunks from Kinesis, so you'd need to have some kind of long-lived service e.g. ECS running that to forward the requests to your ML model.

If you're okay to process in batch, you might be interested to chunk your videos anyway to parallelize for faster processing. You could just run your analysis in a SageMaker Processing/Training job or similar

Obstruction / occlusion is a little tricky because most of the research & models I've been aware of have been aiming for robustness to occlusion: Still detecting the object even if part is covered. If you know what's likely to get in the way, you could try to use an open-vocabulary object detector like Amazon Rekognition or YOLO-World on SageMaker to detect other overlapping objects & prefer other frames where possible. If you want robustness to any unexpected obstructions, you might want to do something more complex like pixel segmentation & post-processing... Or even try asking a generative model like Anthropic Claude 3 Sonnet on Amazon Bedrock whether anything is obstructing the view of {your object}?

AWS
EXPERT

answered 2 years ago

EXPERT

reviewed a year ago

0

Hi,

Did you consider AWS Rekognition for your use case: it already provides out of the box much of the features that you are looking for.

See https://aws.amazon.com/rekognition/ as a starting point

Best,

Didier

EXPERT

answered 2 years ago

  • Hi Didier,

    I have considered it for the overall project, but it seems like there are no APIs that directly do positional analysis of objects. It seems like I would have to do customLabels or either utilize SageMaker.

    Please let me know if you think otherwise.

  • Rekognition's DetectLabels API should provide bounding box localization of a wide range of objects with no training required, and you can try it out from the AWS Console so it might be worth uploading a couple of test frames there to see if it can already reliably detect whatever object it is you're looking for... But if your object isn't something Rekognition recognises well out-of-the-box, then yeah would probably be looking at SageMaker or Rek Custom Labels

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.