Video analysis is computationally and monetarily expensive. We present a scalable video analysis framework based on Scanner that uses AWS Lambda to efficiently meet users’ computational needs while minimizing unused resources by quickly scaling up and down.
First, clone the repo:
git clone https://github.com/qinglan233/this.git && cd this
git submodule update --init
Build and install Scanner in /opt
directory, please refer to the installation guide
of the Scanner installation guide.
We also found the docker file is a good guidance for installation.
Note that you must use our modified version. Because in our end-to-end code, we will use Scanner to ingest the video and prepare arguments for the decoder Lambdas, then our modified Scanner will terminate instead of proceeding to the normal path!
Since we will use AWS Lambda that currently does not support GPU, please install the CPU version of Scanner.
Use the following instructions to build your own static executable decode binary file from scratch.
We implemented two models: the fuse model and the split model.
If you wanted to run the split model, then you can build the standalone decoder:
cd src/decode-scanner/ && mkdir build
cd build/
cmake ..
make
Then use Ermine to create a static build binary file.
ErmineProTrial.x86_64 DecoderAutomataCmd --output=DecoderAutomataCmd-static
This static binary file will be used by decoder Lambdas.
If you want to test the fuse model, similarly, you should build the standalone fused decoder and the kernel (e.g., histogram).
cd src/fused-decode-hist/ && mkdir build
cd build/
cmake ..
make
And again use Ermine to create the static binary file called
FusedDecodeHist-static
.
You need to upload the decoder binary to S3 because they are too large to fit into a Lambda function. You'll also have to change the decoder download path in Lambda functions.
You need to create an AWS account to use AWS Lambda. The services will be used are: Lambda and S3. We also use Serverless to automatically create the deployable artifact so that you don’t need to worry about dependency issues.
You need to create two buckets on S3: one for decoder arguments and intermediate data, another for storing the output results.
You can use online console or AWS CLI to deploy Lambda functions:
aws lambda create-function --function-name <function name> \
--zip-file fileb://<local zip file> --runtime python2.7 \
--region <us-west-2 or others> --role <role arn> \
--handler <lambda file.function name> --memory-size 3008 --timeout 300
An example here:
aws lambda create-function --function-name fused-decode-hist \
--zip-file fileb://fused_decode_hist.zip --runtime python2.7 \
--region us-west-2 --role arn:aws:iam:xxxxxxx<your own num>:role/<rolename> \
--handler lambda.handler --memory-size 3008 --timeout 300
As we described, we implement both the fuse and split models. Here are two examples to use them respectively.
We have one entry file for fuse model that supports all different evaluation kernels. To use this file, type the following command:
cd end_to_end/
python end2end_fuse.py --batch=50 --function=<lambda name> \
--upload-bucket=<input bucket> \
--download-bucket=<output bucket> \
Run python end2end_fuse.py -h
to get information about more optional arguments.
We use the fused histogram as an example. As described before, you can upload your own
FusedDecodeHist-static
file to S3 and change the dowload path in the Lambda function, or you can use our default shared public static build file (no change needed). Then deploy the Lambda function by:
cd lambdas/fused-decode-hist-lambda/
./collect.sh
Create a new Lambda function called fused-decode-hist
using the generated .zip
file.
Then run:
python end2end_fuse.py --batch=50 --function=fused-decode-hist \
--upload-bucket=<input bucket> \
--download-bucket=<output bucket> \
You should be able to see the progress bars in your console. You can DIY your own Lambda functions and just change the --function
parameter to use new features!
If you want to deploy fused-mxnet Lambda functions, be aware of tricky dependencies. So we provide our pre-compiled .zip file on S3. You can use this file to create new fused-mxnet Lambda function.
Or you can use Serverless, since we provide serverless.yml and other dependece files. Make sure you understand what is going on in serverless.yml
file, including the region and function name. Modify as you want! With serverless framework, you can easily deploy Lambda function by:
serverless deploy
We will deploy two Lambda functions: decoder Lambda and MXNet Lambda. Then use S3 event to link these two Lambda functions. That is, upon uploading decoded frames from the decoder Lambdas, the S3 event will
the MXNet Lambdas. So you need to add the decoder uploading path as a resource of trigger to your MXNet Lambda. For more information, please refer to Lambda document.
So first, deploy the decoder Lambda:
mv src/decode-scanner/build/DecoderAutomataCmd-static lambdas/decode-scanner-lambda
cd lambdas/decode-scanner-lambda
./collect.sh
Upload the .zip
file to S3 and create a new Lambda function decoder-scanner
, import the zip file from S3 since it is too large to upload locally.
Then, deploy the MXNet Lambda:
cd lambdas/mxnet-serverless/
serverless deploy
And remember to configure the S3 event trigger source.
Finally, you can run the end-to-end script. Again, you need to modify this end-to-end file to your own S3 buckets. Run:
cd end_to_end/
python2 end2end_mxnet.py 3 1 ./ 50 1
And wait for the progress bars finished.
See also the list of contributors who participated in this project.
This project is licensed under the Apache License 2.0 - see the LICENSE file for details
We would like to thank everyone who has helped and supported this project.