866
edits
Efernandez (talk | contribs) No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
<noinclude> | <noinclude> | ||
{{Metropolis Microservices/Head|previous=RidgeRun Services/AI Agent|next=RidgeRun Microservices Demo|metakeywords=Metropolis|title=RidgeRun Analytics Microservice|metadescription=This page provides a general overview of the | {{Metropolis Microservices/Head|previous=RidgeRun Services/AI Agent|next=RidgeRun Microservices Demo|metakeywords=Metropolis|title=RidgeRun Analytics Microservice|metadescription=This page provides a general overview of the Analytics RidgeRun Service}} | ||
</noinclude> | </noinclude> | ||
RidgeRun's Analytics Microservice is capable of receiving events through REDIS, specifically detection metadata, and execute actions when the event occurs. Currently the service supports two actions: | |||
* Move the camera to the detected object position in PTZ microservice | |||
* Start a event recording in VST microservice. | |||
As you can see the service interacts with 4 other services NVIDIA's VST service, NVIDIA's REDIS service, RidgeRun's Detection service and RidgeRun's PTZ service. | |||
[[File:aiagent_microservice.png|600px|center|thumb| Ridgerun's AI Agent Microservice General Idea]] | |||
By default all the actions are disabled, you need to enable them through a configuration file or through the server API. | |||
In both cases the configuration is defined in JSON format as follows: | |||
<syntaxhighlight lang="JSON"> | |||
{ | |||
"move_camera": { | |||
"enable": 1, | |||
"port": 5030, | |||
"ip": "127.0.0.1", | |||
"time_threshold": 10 | |||
}, | |||
"record": { | |||
"enable": 0, | |||
"port": 81, | |||
"ip": "127.0.0.1", | |||
"time_threshold": 10 | |||
} | |||
} | |||
</syntaxhighlight> | |||
As you can see the configuration allows you to enable/disable each of the available actions and configure the URI of the corresponding microservice. | |||
Also you can define a time threshold, it has a different meaning for record and move actions. For record, this time defines the elapsed time between recordings, a new recording request will be send until this threshold time is over. For move this time indicates the time to restart the PTZ position, if an event doesn't occur during the threshold time, the position will be restarted to 0 and zoom 1 when the time is over. | |||
== Running the Service == | |||
=== Launch Services === | |||
This microservice requires of NVIDIA's VST and Redis Platform Services. Use systemctl to launch each of the services. | |||
* Redis: | |||
<syntaxhighlight lang="bash"> | |||
sudo systemctl start jetson-redis | |||
</syntaxhighlight> | |||
* VST: | |||
<syntaxhighlight lang="bash"> | |||
sudo systemctl start jetson-vst | |||
</syntaxhighlight> | |||
Also requires RidgeRun's Detection and PTZ Services, run them before enabled actions, check the corresponding sections on this wiki to learn how. | |||
=== Using Docker === | |||
You can obtain or build a docker image for the detection microservice, check below the method of your preference. The image include a base L4T image and the dependencies to run the analytics microservice application. The image was developed and tested for NVIDIA JetPack 6.0. Once you get your image with either method proceed to [[Metropolis_Microservices/RidgeRun_Services/Analytics#Launch_the_container|Launch the container]] | |||
==== Pre-build Image ==== | |||
You can obtain a pre-build image of the analytics service from Docker Hub: | |||
<syntaxhighlight lang="bash"> | |||
docker pull ridgerun/analytics-service | |||
</syntaxhighlight> | |||
==== Build Image ==== | |||
You can build the analytics microservice image using the Dockerfile in the docker directory. First we need to prepare the context directory for this build, you need to create a directory and include this repository and the rrms-utils project. The Dockerfile will look for both packages in the context directory and copy them to the container. | |||
<syntaxhighlight lang="bash"> | |||
analytics-context/ | |||
├── analytics | |||
└── rrms-utils | |||
</syntaxhighlight> | |||
Then build the container image with the following command: | |||
<syntaxhighlight lang="bash"> | |||
DOCKER_BUILDKIT=0 docker build --network=host --tag ridgerun/analytics-service --file analytics-context/analytics/docker/Dockerfile analytics-context/ | |||
</syntaxhighlight> | |||
Change analytics-context/ to your context's path and the tag to the name you want to give to the image. | |||
==== Launch the container ==== | |||
You can ensure the image has been created successfully by running | |||
<syntaxhighlight lang="bash"> | |||
docker images | |||
</syntaxhighlight> | |||
You should get an entry showing the ridgerun/analytics-service image | |||
<syntaxhighlight lang="bash"> | |||
nvidia@ubuntu:~$ docker images | |||
REPOSITORY TAG IMAGE ID CREATED SIZE | |||
ridgerun/analytics-service latest 234ec6ac1fd3 42 hours ago 1.19GB | |||
</syntaxhighlight> | |||
The container can be launched by running the following command: | |||
<syntaxhighlight lang="bash"> | |||
docker run --runtime nvidia -it --network host --volume /home/nvidia/analytics-configs/:/configs --name analytics-service ridgerun/analytics-service:latest analytics --host 0.0.0.0 --config-file /configs/analytics.json | |||
</syntaxhighlight> | |||
Here we are creating a container called analytics-service that will start the analytics application (check [[Using Standalone Application]]), launching the server allowing access to any IP available in the device in port 5040. Also provides a configuration file through the configs volume. | |||
You can verify the container is running with: | |||
<syntaxhighlight lang="bash"> | |||
docker ps | |||
</syntaxhighlight> | |||
You should see an entry with the detection-service container: | |||
<syntaxhighlight lang="bash"> | |||
nvidia@ubuntu:~$ docker ps | |||
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES | |||
f75125479840 nvcr.io/nvidia/jps/vst:v1.2.58_aarch64 "sh -c '/root/vst_re…" 14 minutes ago Up 14 minutes vst | |||
00e36eebeb34 nvcr.io/nvidia/jps/ialpha-ingress-arm64v8:0.10 "sh -c '/nginx.sh 2>…" 15 minutes ago Up 15 minutes ingress | |||
0b316b01160b redisfab/redistimeseries:master-arm64v8-jammy "docker-entrypoint.s…" 15 minutes ago Up 15 minutes redis | |||
6d3de9e48fc9 ridgerun/ai-agent-service "ai-agent --system_p…" 24 hours ago Up 16 minutes agent-service | |||
e339561ada13 ridgerun/ptz-service "ptz --host 127.0.0.…" 24 hours ago Up 8 minutes ptz-service | |||
a488ddbdd71b ridgerun/analytics-service "analytics --config-…" 24 hours ago Up 14 minutes analytics-service | |||
529b11d69113 ridgerun/detection-service "detection --horizon…" 24 hours ago Up 14 minutes detection-service | |||
</syntaxhighlight> | |||
=== Using Standalone Application === | |||
The project is configured (via setup.py) and install the service application called analytics. Just need to run: | |||
<syntaxhighlight lang="bash"> | |||
pip install . | |||
</syntaxhighlight> | |||
Then you will have the service with the following options: | |||
<syntaxhighlight lang="bash"> | |||
usage: analytics [-h] [--port PORT] [--host HOST] [--config-file CONFIG_FILE] | |||
options: | |||
-h, --help show this help message and exit | |||
--port PORT Port for server | |||
--host HOST Server ip address | |||
--config-file CONFIG_FILE | |||
Configuration JSON file | |||
</syntaxhighlight> | |||
To start the service in address 127.0.0.1 and port 5040 just run: | |||
<syntaxhighlight lang="bash"> | |||
analytics | |||
</syntaxhighlight> | |||
If you want to serve in a different port or address, use the --port and --host options. | |||
Remember that analytics by default doesn't execute any action, it will receive the redis event and discard it, but you can enable the actions using the --config-file argument point to a JSON configuration file. | |||
== Analytics in Action == | |||
Due to the nature of the analytics functionality we cannot show how it works as standalone service, it requires the interaction with the other services, so the video below shows its interaction with VST, PTZ and Detection services. In display we have the video feed used in the detection at the top-left corner, PTZ output at the bottom-left corner and at the right side a browser with a tab of swagger for analytics API request and a tab of VST web page. The detection service is detecting guitars. | |||
[[File:Analytics.gif|center|Example of RidgeRun's Analytics Microservice functionality]] | |||
First we request for the current analytics configuration, where we can see both record and move actions are disabled. So even if a guitar appears in the video feed the PTZ stream doesn't move or zoom. Also we verify there is no current recording in the VST records. Then we enable both actions through a configuration request. As soon a guitar appears in the feed, the PTZ moves to the guitar locations and zoom in, after 10 seconds the position returns to 0,0 and zoom out. We also verify that now we have a recording with a man walking with a guitar. We wait for a second loop of the video, the ptz moves to the guitar and we verify that now we have two recording of the man with the guitar. | |||
edits