-
Notifications
You must be signed in to change notification settings - Fork 814
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
On-premise near real-time video inference #1867
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1867 +/- ##
=======================================
Coverage 44.95% 44.95%
=======================================
Files 63 63
Lines 2609 2609
Branches 56 56
=======================================
Hits 1173 1173
Misses 1436 1436 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! This is awesome, I'd recommend writing a blog post about this application so you can do things like add a video stream screenshot
Left some minor nit feedback, the only main one is that we need a test to make sure this example doesnt break later
examples/image_classifier/streaming_video_client_side_batching/custom_handler.py
Outdated
Show resolved
Hide resolved
# if the image is a list | ||
image = torch.FloatTensor(image) | ||
|
||
images.append(image) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can torch.stack
images directly without an intermediate list
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do we do this? torch.stack needs multiple elements of the same size? I copied this from the image_classifier handler
examples/image_classifier/streaming_video_client_side_batching/README.md
Outdated
Show resolved
Hide resolved
examples/image_classifier/streaming_video_client_side_batching/README.md
Outdated
Show resolved
Hide resolved
examples/image_classifier/streaming_video_client_side_batching/README.md
Outdated
Show resolved
Hide resolved
examples/image_classifier/streaming_video_client_side_batching/request.py
Outdated
Show resolved
Hide resolved
examples/image_classifier/streaming_video_client_side_batching/request.py
Outdated
Show resolved
Hide resolved
examples/image_classifier/streaming_video_client_side_batching/request.py
Outdated
Show resolved
Hide resolved
examples/image_classifier/streaming_video_client_side_batching/request.py
Outdated
Show resolved
Hide resolved
examples/image_classifier/streaming_video_client_side_batching/README.md
Outdated
Show resolved
Hide resolved
examples/image_classifier/streaming_video_client_side_batching/custom_handler.py
Outdated
Show resolved
Hide resolved
examples/image_classifier/streaming_video_client_side_batching/README.md
Outdated
Show resolved
Hide resolved
examples/image_classifier/streaming_video_client_side_batching/custom_handler.py
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some minor feedback, please address before merge otherwise LGTM!
examples/image_classifier/streaming_video/create_mar_file_batch.py
Outdated
Show resolved
Hide resolved
examples/image_classifier/streaming_video/request_client_batching.py
Outdated
Show resolved
Hide resolved
@agunapal could you please attach regression test log to check pytest? |
@lxning Updated with regression logs. The test is being skipped from the regression suite, to avoid installing other client libraries ( so that binary size doesn't increase) |
Description
This PR includes the following
Problem
Consider a use-case where we have cameras connected to edge devices. These devices are connected to a compute cluster where TorchServe is running. Each edge device has a computer vision pipeline running, where we read frames from the camera and we need to perform tasks as Image Classification, Pose Estimation, Activity Recognition etc on the read frames. In order to make efficient use of hardware resources, we might want to do batching of the frames for efficient inference
This example shows how this can be achieved using TorchServe with the following 2 approaches
The architecture diagram is shown below
With TorchServe batching
On the client side, we have one thread for reading frames from a video source and another thread which sends the read frames as http request to TorchServe for image classification inference. We are using an asynchronous http requests as we want to make use of TorchServe batching.
We send one frame in each request and let TorchServe handle the batching
TorchServe is setup to process batch size of 4 in this example.
TorchServe receives individual requests, batches the requests to make a single inference request and sends out individual responses to the requests received.
Create a resnet-18 eager mode model archive, register it on TorchServe and run inference on a real time video
Run the commands given in following steps from the parent directory of the root of the repository. For example, if you cloned the repository into
/home/my_path/serve
, run the steps from/home/my_path
The default batch size is 4.
On the client side, we should see the following output
With Client-Side batching
On the client side, we have one thread for reading frames from a video source and another thread which batches(size n) the read frames and sends the request to TorchServe for image classification inference.
To send the batched data, we create a json payload of n frames.
On the TorchServe side, we read the json payload and preprocess the n frames. The postprocess function in the handler returns the output as a list of length 1.
Create a resnet-18 eager mode model archive, register it on TorchServe and run inference on a real time video
Run the commands given in following steps from the parent directory of the root of the repository. For example, if you cloned the repository into
/home/my_path/serve
, run the steps from/home/my_path
The default batch size is 4.
On the client side, we should see the following output
Fixes #(issue)
Type of change
Please delete options that are not relevant.
Feature/Issue validation/testing
Please describe the Unit or Integration tests that you ran to verify your changes and relevant result summary. Provide instructions so it can be reproduced.
Please also list any relevant details for your test configuration.
Checklist: