{ "cells": [ { "cell_type": "code", "execution_count": null, "id": "1965690c-2584-46ae-b1e8-3c93943cfed4", "metadata": {}, "outputs": [], "source": [ "import sagemaker\n", "import boto3\n", "from sagemaker.local import LocalSession\n", "from sagemaker.model import Model\n", "from sagemaker import get_execution_role\n", "from sagemaker.serializers import JSONSerializer\n", "from sagemaker.deserializers import JSONDeserializer\n", "import numpy as np\n", "import json" ] }, { "cell_type": "code", "execution_count": null, "id": "18bd9021-8b5f-42c7-8486-5a7a0caf7a11", "metadata": {}, "outputs": [], "source": [ "session = LocalSession()\n", "session.config = {'local': {'local_code': True}}\n", "role = get_execution_role()\n", "model_url = \"\"\n", "\n", "role = \"\"\n", "model_url = \"\"\n", "container=\"\n", " \n", " \n", "\"\"\")" ] }, { "cell_type": "markdown", "id": "215332ae-5457-4bfc-a936-ae2589f3e3b4", "metadata": {}, "source": [ "### Integrate Inference Application\n", "With a local endpoint deployed in your environment, \n", "you can now create ball tracking videos by integrating the deployed endpoint with your own videos. \n", "A sample application is included in this repository to demonstrate the capability in action.\n", "To run it simply do the followings in your terminal or run the below cell. If you are running this cell in SageMaker Notebook environment, you can select a tensorflow based kernels to run the notebook and skip through running ./setup.sh to install files. \n", "\n", "\n", "cd ../test\n", "./setup.sh \n", "python application.py --input_video_file input_video_file \\\n", "--output_video_file_path output_video_file \\\n", "--endpoint_name sm_endpoint_name" ] }, { "cell_type": "code", "execution_count": null, "id": "dac864d8-55c1-4f46-a916-7a62aa650981", "metadata": { "tags": [] }, "outputs": [], "source": [ "!cd ../test && ls && ./setup.sh && python application.py --input_video_file videos/1_01_00.mp4 --output_video_file_path videos/1_01_00.mp4 --endpoint_name local" ] }, { "cell_type": "markdown", "id": "07aa1638-c82e-4b14-8f67-eb75fd04dde1", "metadata": {}, "source": [ "### Prediction Results\n", "Inference application will save the results and prediction labels (visibility) and the location of the ball in a csv file. The sample file below represents an example of the prediction results above. Take a look at the ball closely and observe the red dot following the movement of the ball.\n", "\n", "![1_01_00_predict](https://user-images.githubusercontent.com/22420800/225199635-cfef3e45-b0e8-4eee-9218-9228b1523857.gif)" ] }, { "cell_type": "code", "execution_count": null, "id": "e8167d29-7ea4-484d-ae7e-b17d3fdfc123", "metadata": {}, "outputs": [], "source": [ "### Delete Endpoint\n", "# Delete the SageMaker endpoint and the attached resources\n", "predictor.delete_model()\n", "predictor.delete_endpoint()" ] } ], "metadata": { "kernelspec": { "display_name": "conda_tensorflow2_p310", "language": "python", "name": "conda_tensorflow2_p310" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.8" } }, "nbformat": 4, "nbformat_minor": 5 }