Skip to content

Commit

Permalink
Add distributed version of the h.264 Endoscopy Tool Tracking app (#496)
Browse files Browse the repository at this point in the history
* Add distributed version of the h.264 Endoscopy Tool Tracking app in C++ & Python

Signed-off-by: Victor Chang <[email protected]>

* Fix lint issues

Signed-off-by: Victor Chang <[email protected]>

* Address feedback

Signed-off-by: Victor Chang <[email protected]>

* Update extension paths

Signed-off-by: Victor Chang <[email protected]>

---------

Signed-off-by: Victor Chang <[email protected]>
  • Loading branch information
mocsharp authored Oct 24, 2024
1 parent 446803c commit 4391d51
Show file tree
Hide file tree
Showing 22 changed files with 1,620 additions and 17 deletions.
63 changes: 63 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,69 @@
}
},
//#endregion h264_video_decode

//#region h264_endoscopy_tool_tracking_distributed
{
"name": "(gdb) h264_endoscopy_tool_tracking_distributed/cpp (all fragments)",
"type": "cppdbg",
"request": "launch",
"preLaunchTask": "Build h264_endoscopy_tool_tracking_distributed",
"program": "${workspaceFolder}/build/h264_endoscopy_tool_tracking_distributed/applications/h264/h264_endoscopy_tool_tracking_distributed/cpp/h264_endoscopy_tool_tracking_distributed",
"environment": [
{
"name": "HOLOSCAN_INPUT_PATH",
"value": "${env:HOLOHUB_DATA_DIR}/endoscopy"
}
],
"stopAtEntry": false,
"cwd": "${workspaceFolder}/build/h264_endoscopy_tool_tracking_distributed/applications/h264/h264_endoscopy_tool_tracking_distributed/cpp",
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"presentation": {
"hidden": false,
"group": "h264_endoscopy_tool_tracking_distributed",
"order": 1
}
},
{
"name": "(debugpy) h264_endoscopy_tool_tracking_distributed/python (all fragments)",
"type": "debugpy",
"request": "launch",
"preLaunchTask": "Build h264_endoscopy_tool_tracking_distributed",
"program": "${workspaceFolder}/applications/h264/h264_endoscopy_tool_tracking_distributed/python/h264_endoscopy_tool_tracking_distributed.py",
"cwd": "${workspaceFolder}/build/h264_endoscopy_tool_tracking_distributed/",
"env": {
"PYTHONPATH": "${workspaceFolder}/build/h264_endoscopy_tool_tracking_distributed/python/lib:${env:PYTHONPATH}",
"HOLOSCAN_INPUT_PATH": "${env:HOLOHUB_DATA_DIR}/endoscopy"
},
"args": [
"--data",
"${env:HOLOHUB_DATA_DIR}/endoscopy"
],
"presentation": {
"hidden": true,
}
},
{
"name": "(pythoncpp) h264_endoscopy_tool_tracking_distributed/python (all fragments)",
"type": "pythoncpp",
"request": "launch",
"pythonLaunchName": "(debugpy) h264_endoscopy_tool_tracking_distributed/python (all fragments)",
"cppConfig": "default (gdb) Attach",
"presentation": {
"hidden": false,
"group": "h264_endoscopy_tool_tracking_distributed",
"order": 2
}
},
//#endregion h264_endoscopy_tool_tracking_distributed
//#region holoviz
{
"name": "(gdb) Holoviz examples",
Expand Down
26 changes: 26 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,32 @@
"problemMatcher": [],
"detail": "CMake template build task"
},
{
"type": "shell",
"label": "Build h264_endoscopy_tool_tracking_distributed",
"command": "./run",
"args": [
"build",
"h264_endoscopy_tool_tracking_distributed",
"--type",
"debug"
],
"options": {
"cwd": "${env:WORKSPACE_DIR}"
},
"group": "build",
"problemMatcher": [],
"detail": "CMake template build task",
"presentation": {
"echo": true,
"reveal": "silent",
"focus": true,
"panel": "dedicated",
"showReuseMessage": false,
"clear": true,
"group": "h264_endoscopy_tool_tracking_distributed"
}
},
{
"type": "shell",
"label": "Build h264_video_decode",
Expand Down
8 changes: 7 additions & 1 deletion applications/h264/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,11 @@ add_holohub_application(h264_endoscopy_tool_tracking DEPENDS
tool_tracking_postprocessor
)

add_holohub_application(h264_endoscopy_tool_tracking_distributed DEPENDS
OPERATORS video_encoder
tensor_to_video_buffer
lstm_tensor_rt_inference
tool_tracking_postprocessor)

add_holohub_application(h264_video_decode DEPENDS
OPERATORS video_decoder video_read_bitstream)
OPERATORS video_decoder video_read_bitstream)
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,36 @@
cmake_minimum_required(VERSION 3.20)

find_package(holoscan 2.1.0 REQUIRED CONFIG
PATHS "/opt/nvidia/holoscan" "/workspace/holoscan-sdk/install")
PATHS "/opt/nvidia/holoscan" "/workspace/holoscan-sdk/install")

# Enable the operators
add_library(nvidia_nim_imaging INTERFACE)
target_link_libraries(nvidia_nim_imaging INTERFACE
holoscan::core
holoscan::ops::holoviz
holoscan::ops::lstm_tensor_rt_inference
holoscan::ops::tensor_to_video_buffer
holoscan::ops::tool_tracking_postprocessor)
add_library(h264_endoscopy_tool_tracking_python INTERFACE)
target_link_libraries(h264_endoscopy_tool_tracking_python
INTERFACE
holoscan::core
holoscan::ops::holoviz
holoscan::ops::lstm_tensor_rt_inference
holoscan::ops::tensor_to_video_buffer
holoscan::ops::tool_tracking_postprocessor)

# Add testing
if(BUILD_TESTING)
add_test(NAME h264_endoscopy_tool_tracking_python_test
COMMAND python3 ${CMAKE_CURRENT_SOURCE_DIR}/h264_endoscopy_tool_tracking.py
--config ${CMAKE_CURRENT_SOURCE_DIR}/h264_endoscopy_tool_tracking.yaml
--data ${HOLOHUB_DATA_DIR}/endoscopy
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
COMMAND python3 ${CMAKE_CURRENT_SOURCE_DIR}/h264_endoscopy_tool_tracking.py
--config ${CMAKE_CURRENT_SOURCE_DIR}/h264_endoscopy_tool_tracking.yaml
--data ${HOLOHUB_DATA_DIR}/endoscopy
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})

set_property(TEST h264_endoscopy_tool_tracking_python_test PROPERTY ENVIRONMENT
"PYTHONPATH=${GXF_LIB_DIR}/../python/lib:${CMAKE_BINARY_DIR}/python/lib")
"PYTHONPATH=${GXF_LIB_DIR}/../python/lib:${CMAKE_BINARY_DIR}/python/lib")

set_tests_properties(h264_endoscopy_tool_tracking_python_test PROPERTIES
PASS_REGULAR_EXPRESSION "Deactivating Graph"
FAIL_REGULAR_EXPRESSION "[^a-z]Error;ERROR;Failed")
PASS_REGULAR_EXPRESSION "Deactivating Graph"
FAIL_REGULAR_EXPRESSION "[^a-z]Error;ERROR;Failed")

# For aarch64 LD_LIBRARY_PATH needs to be set
if(CMAKE_SYSTEM_PROCESSOR STREQUAL aarch64 OR CMAKE_SYSTEM_PROCESSOR STREQUAL arm64)
set_property(TEST h264_endoscopy_tool_tracking_python_test APPEND PROPERTY ENVIRONMENT
"LD_LIBRARY_PATH=/usr/lib/aarch64-linux-gnu/tegra/")
"LD_LIBRARY_PATH=/usr/lib/aarch64-linux-gnu/tegra/")
endif()
endif()
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

cmake_minimum_required(VERSION 3.20)
project(h264_endoscopy_tool_tracking_distributed_apps LANGUAGES NONE)

add_subdirectory(cpp)
add_subdirectory(python)
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Distributed H.264 Endoscopy Tool Tracking Application

This application is similar to the [H.264 Endoscopy Tool Tracking](../h264_endoscopy_tool_tracking/) application, but this distributed version divides the application into three fragments:

1. Video Input: get video input from a pre-recorded video file.
2. Inference: run the inference using LSTM and run the post-processing script.
3. Visualization: display input video and inference results.


## Requirements

This application is configured to use H.264 elementary stream from endoscopy sample data as input.

### Data

[📦️ (NGC) Sample App Data for AI-based Endoscopy Tool Tracking](https://catalog.ngc.nvidia.com/orgs/nvidia/teams/clara-holoscan/resources/holoscan_endoscopy_sample_data)

The data is automatically downloaded when building the application.

## Building and Running H.264 Endoscopy Tool Tracking Application

* Building and running the application from the top level Holohub directory:

### C++

```bash
# Start the application with all three fragments
./dev_container build_and_run h264_endoscopy_tool_tracking_distributed --docker_file applications/h264/Dockerfile --language cpp

# Use the following commands to run the same application three processes:
# Start the application with the video_in fragment
./dev_container build_and_run h264_endoscopy_tool_tracking_distributed --docker_file applications/h264/Dockerfile --language cpp --run_args "--driver --worker --fragments video_in --address :10000 --worker-address :10001"
# Start the application with the inference fragment
./dev_container build_and_run h264_endoscopy_tool_tracking_distributed --docker_file applications/h264/Dockerfile --language cpp --run_args "--worker --fragments inference --address :10000 --worker-address :10002"
# Start the application with the visualization fragment
./dev_container build_and_run h264_endoscopy_tool_tracking_distributed --docker_file applications/h264/Dockerfile --language cpp --run_args "--worker --fragments viz --address :10000 --worker-address :10003"
```
--base_img gitlab-master.nvidia.com:5005/holoscan/holoscan-sdk/dev-x86_64:main
### Python

```bash
# Start the application with all three fragments
./dev_container build_and_run h264_endoscopy_tool_tracking_distributed --docker_file applications/h264/Dockerfile --language python

# Use the following commands to run the same application three processes:
# Start the application with the video_in fragment
./dev_container build_and_run h264_endoscopy_tool_tracking_distributed --docker_file applications/h264/Dockerfile --language python --run_args "--driver --worker --fragments video_in --address :10000 --worker-address :10001"
# Start the application with the inference fragment
./dev_container build_and_run h264_endoscopy_tool_tracking_distributed --docker_file applications/h264/Dockerfile --language python --run_args "--worker --fragments inference --address :10000 --worker-address :10002"
# Start the application with the visualization fragment
./dev_container build_and_run h264_endoscopy_tool_tracking_distributed --docker_file applications/h264/Dockerfile --language python --run_args "--worker --fragments viz --address :10000 --worker-address :10003"
```

Important: on aarch64, applications also need tegra folder mounted inside the container and
the `LD_LIBRARY_PATH` environment variable should be updated to include
tegra folder path.

Open and edit the [Dockerfile](../Dockerfile) and uncomment line 66:

```bash
# Uncomment the following line for aarch64 support
ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/aarch64-linux-gnu/tegra/
```


## Dev Container

To start the VS Code Dev Container, run the following command from the root directory of Holohub:

```bash
./dev_container vscode h264
```

### VS Code Launch Profiles

#### C++

Use the **(gdb) h264_endoscopy_tool_tracking_distributed/cpp (all fragments)** launch profile to run and debug the C++ application.

#### Python

Use the **(pythoncpp) h264_endoscopy_tool_tracking_distributed/python (all fragments)** launch profile to run and debug the Python application.
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

cmake_minimum_required(VERSION 3.20)
project(h264_endoscopy_tool_tracking_distributed CXX)

find_package(holoscan 2.5 REQUIRED CONFIG
PATHS "/opt/nvidia/holoscan" "/workspace/holoscan-sdk/install")

add_executable(h264_endoscopy_tool_tracking_distributed
main.cpp
)

target_link_libraries(h264_endoscopy_tool_tracking_distributed
PRIVATE
holoscan::core
holoscan::ops::gxf_codelet
holoscan::ops::format_converter
holoscan::ops::holoviz
holoscan::ops::video_encoder
holoscan::ops::tensor_to_video_buffer
lstm_tensor_rt_inference
tool_tracking_postprocessor
)

# Copy the config to the binary directory
add_custom_target(h264_endoscopy_tool_tracking_distributed_yaml
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_SOURCE_DIR}/endoscopy_tool_tracking.yaml" ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS "endoscopy_tool_tracking.yaml"
BYPRODUCTS "endoscopy_tool_tracking.yaml"
)
add_dependencies(h264_endoscopy_tool_tracking_distributed h264_endoscopy_tool_tracking_distributed_yaml)

# Default to download datasets
option(HOLOHUB_DOWNLOAD_DATASETS "Download datasets" ON)

# Download the endoscopy sample data
if(HOLOHUB_DOWNLOAD_DATASETS)
include(holoscan_download_data)
holoscan_download_data(endoscopy
URL https://api.ngc.nvidia.com/v2/resources/nvidia/clara-holoscan/holoscan_endoscopy_sample_data/versions/20230222/zip
DOWNLOAD_NAME holoscan_endoscopy_sample_data_20230222.zip
URL_MD5 d54f84a562d29ed560a87d2607eba973
DOWNLOAD_DIR ${HOLOHUB_DATA_DIR}
)
add_dependencies(h264_endoscopy_tool_tracking_distributed endoscopy_data)
endif()
Loading

0 comments on commit 4391d51

Please sign in to comment.