Skip to content

Commit 2512c12

Browse files
committed
Enable packaging of the applications using Holoscan CLI
Signed-off-by: Victor Chang <vicchang@nvidia.com>
1 parent e1453b3 commit 2512c12

File tree

12 files changed

+256
-28
lines changed

12 files changed

+256
-28
lines changed

applications/endoscopy_tool_tracking/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,7 @@ There are a two launch profiles configured for this application:
109109

110110
1. **(debugpy) endoscopy_tool_tracking/python**: This launch profile enables debugging of Python code.
111111
2. **(pythoncpp) endoscopy_tool_tracking/python**: This launch profile enables debugging of Python and C++ code.
112+
113+
## Containerize the application
114+
115+
To containerize the application, first build the application, run the `package-app.sh` script in the [cpp](./cpp/package-app.sh) or the [python](./python/package-app.sh) directory and then follow the generated output to package and run the application.

applications/endoscopy_tool_tracking/cpp/endoscopy_tool_tracking.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616
---
17+
application:
18+
title: Holohub - Endoscopy Tool Tracking
19+
version: 1.0
20+
inputFormats: []
21+
outputFormats: ["screen"]
22+
23+
resources:
24+
cpu: 2
25+
gpu: 1
26+
memory: 1Gi
27+
gpuMemory: 1Gi
28+
1729
extensions:
1830
- gxf_extensions/lstm_tensor_rt_inference/libgxf_lstm_tensor_rt_inference.so
1931
# Uncomment the following extension when using deltacast as a source

applications/endoscopy_tool_tracking/cpp/main.cpp

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717

1818
#include <getopt.h>
1919

20-
#include "holoscan/holoscan.hpp"
2120
#include <holoscan/operators/aja_source/aja_source.hpp>
2221
#include <holoscan/operators/format_converter/format_converter.hpp>
2322
#include <holoscan/operators/holoviz/holoviz.hpp>
2423
#include <holoscan/operators/video_stream_recorder/video_stream_recorder.hpp>
2524
#include <holoscan/operators/video_stream_replayer/video_stream_replayer.hpp>
2625
#include <lstm_tensor_rt_inference.hpp>
2726
#include <tool_tracking_postprocessor.hpp>
27+
#include "holoscan/holoscan.hpp"
2828
#ifdef VTK_RENDERER
2929
#include <vtk_renderer.hpp>
3030
#endif
@@ -181,10 +181,8 @@ class App : public holoscan::Application {
181181
}
182182
#ifdef VTK_RENDERER
183183
if (this->visualizer_name == "vtk") {
184-
visualizer_operator = make_operator<ops::VtkRendererOp>("vtk",
185-
from_config("vtk_op"),
186-
Arg("width") = width,
187-
Arg("height") = height);
184+
visualizer_operator = make_operator<ops::VtkRendererOp>(
185+
"vtk", from_config("vtk_op"), Arg("width") = width, Arg("height") = height);
188186
}
189187
#endif
190188

@@ -279,43 +277,62 @@ class App : public holoscan::Application {
279277
};
280278

281279
/** Helper function to parse the command line arguments */
282-
bool parse_arguments(int argc, char** argv, std::string& config_name, std::string& data_path) {
283-
static struct option long_options[] = {{"data", required_argument, 0, 'd'}, {0, 0, 0, 0}};
280+
bool parse_arguments(int argc, char** argv, std::string& data_path, std::string& config_path) {
281+
static struct option long_options[] = {
282+
{"data", required_argument, 0, 'd'}, {"config", required_argument, 0, 'c'}, {0, 0, 0, 0}};
284283

285-
while (int c = getopt_long(argc, argv, "d", long_options, NULL)) {
284+
while (int c = getopt_long(argc, argv, "d:c:", long_options, NULL)) {
286285
if (c == -1 || c == '?') break;
287286

288287
switch (c) {
288+
case 'c':
289+
config_path = optarg;
290+
break;
289291
case 'd':
290292
data_path = optarg;
291293
break;
292294
default:
293-
std::cout << "Unknown arguments returned: " << c << std::endl;
295+
holoscan::log_error("Unhandled option '{}'", static_cast<char>(c));
294296
return false;
295297
}
296298
}
297299

298-
if (optind < argc) { config_name = argv[optind++]; }
299300
return true;
300301
}
301302

302303
/** Main function */
303304
int main(int argc, char** argv) {
304-
auto app = holoscan::make_application<App>();
305-
306305
// Parse the arguments
307-
std::string data_path = "";
308-
std::string config_name = "";
309-
if (!parse_arguments(argc, argv, config_name, data_path)) { return 1; }
310-
311-
if (config_name != "") {
312-
app->config(config_name);
313-
} else {
314-
auto config_path = std::filesystem::canonical(argv[0]).parent_path();
315-
config_path += "/endoscopy_tool_tracking.yaml";
316-
app->config(config_path);
306+
std::string config_path = "";
307+
std::string data_directory = "";
308+
if (!parse_arguments(argc, argv, data_directory, config_path)) { return 1; }
309+
if (data_directory.empty()) {
310+
// Get the input data environment variable
311+
auto input_path = std::getenv("HOLOSCAN_INPUT_PATH");
312+
if (input_path == nullptr || input_path[0] == '\0') {
313+
HOLOSCAN_LOG_ERROR(
314+
"Input data not provided. Use --data or set HOLOSCAN_INPUT_PATH environment variable.");
315+
exit(-1);
316+
}
317+
data_directory = std::string(input_path);
317318
}
318319

320+
if (config_path.empty()) {
321+
// Get the input data environment variable
322+
auto config_file_path = std::getenv("HOLOSCAN_CONFIG_PATH");
323+
if (config_file_path == nullptr || config_file_path[0] == '\0') {
324+
auto config_file = std::filesystem::canonical(argv[0]).parent_path();
325+
config_path = config_file / std::filesystem::path("endoscopy_tool_tracking.yaml");
326+
} else {
327+
config_path = config_file_path;
328+
}
329+
}
330+
331+
auto app = holoscan::make_application<App>();
332+
333+
HOLOSCAN_LOG_INFO("Using configuration file from {}", data_directory);
334+
app->config(config_path);
335+
319336
auto source = app->from_config("source").as<std::string>();
320337
app->set_source(source);
321338

@@ -325,7 +342,8 @@ int main(int argc, char** argv) {
325342
auto visualizer_name = app->from_config("visualizer").as<std::string>();
326343
app->set_visualizer_name(visualizer_name);
327344

328-
if (data_path != "") app->set_datapath(data_path);
345+
HOLOSCAN_LOG_INFO("Using input data from {}", data_directory);
346+
app->set_datapath(data_directory);
329347

330348
app->run();
331349

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/bin/bash
2+
# SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3+
# SPDX-License-Identifier: Apache-2.0
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
GIT_ROOT=$(readlink -f ./$(git rev-parse --show-cdup))
18+
19+
# Utilities
20+
21+
YELLOW="\e[1;33m"
22+
RED="\e[1;31m"
23+
NOCOLOR="\e[0m"
24+
25+
print_error() {
26+
echo -e "${RED}ERROR${NOCOLOR}:" $*
27+
}
28+
29+
if [ ! -d $GIT_ROOT/build/endoscopy_tool_tracking ]; then
30+
print_error "Please build the Endoscopy Tool Tracking application first with the following command:"
31+
print_error "./dev_container build_and_run endoscopy_tool_tracking"
32+
exit -1
33+
fi
34+
35+
APP_PATH="$GIT_ROOT/endoscopy_tool_tracking_cpp"
36+
echo Creating application directory $APP_PATH...
37+
mkdir -p $APP_PATH
38+
echo Copying application files to $APP_PATH...
39+
cp -f $GIT_ROOT/build/endoscopy_tool_tracking/applications/endoscopy_tool_tracking/cpp/endoscopy_tool_tracking $APP_PATH
40+
cp -f $GIT_ROOT/build/endoscopy_tool_tracking/applications/endoscopy_tool_tracking/cpp/endoscopy_tool_tracking.yaml $APP_PATH
41+
cp -f $GIT_ROOT/build/endoscopy_tool_tracking/gxf_extensions/lstm_tensor_rt_inference/*.so $APP_PATH
42+
cp -f $GIT_ROOT/build/endoscopy_tool_tracking/operators/lstm_tensor_rt_inference/liblstm_tensor_rt_inference.so $APP_PATH
43+
cp -f $GIT_ROOT/build/endoscopy_tool_tracking/operators/tool_tracking_postprocessor/libtool_tracking_postprocessor.so $APP_PATH
44+
45+
echo Updating application configuration...
46+
sed -e s!gxf_extensions/lstm_tensor_rt_inference/!!g -i $APP_PATH/endoscopy_tool_tracking.yaml
47+
48+
49+
echo -e "done\n"
50+
echo -e Use the following commands to package and run the Endoscopy Tool Tracking application:\n
51+
echo -e "Package the application:\n"
52+
echo -e "${YELLOW}holoscan package -c $APP_PATH/endoscopy_tool_tracking.yaml --platform x64-workstation -t holohub-endoscopy-tool-tracking-cpp $APP_PATH/endoscopy_tool_tracking --include onnx holoviz${NOCOLOR}"
53+
echo -e "Run the application:\n"
54+
echo -e "${YELLOW}holoscan run -r \$(docker images | grep "holohub-endoscopy-tool-tracking-cpp" | awk '{print \$1\":\"\$2}') -i $GIT_ROOT/data/endoscopy${NOCOLOR}"

applications/endoscopy_tool_tracking/python/endoscopy_tool_tracking.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ def compose(self):
303303
parser.add_argument(
304304
"-d",
305305
"--data",
306-
default="none",
306+
default=os.environ.get("HOLOSCAN_INPUT_PATH", None),
307307
help=("Set the data path"),
308308
)
309309
args = parser.parse_args()

applications/endoscopy_tool_tracking/python/endoscopy_tool_tracking.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616
---
17+
application:
18+
title: Holohub - Endoscopy Tool Tracking
19+
version: 1.0
20+
inputFormats: []
21+
outputFormats: ["screen"]
22+
23+
resources:
24+
cpu: 2
25+
gpu: 1
26+
memory: 1Gi
27+
gpuMemory: 1Gi
28+
1729
extensions:
1830
- gxf_extensions/lstm_tensor_rt_inference/libgxf_lstm_tensor_rt_inference.so
1931
- gxf_extensions/yuan_qcap/libgxf_qcap_source.so
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/bin/bash
2+
# SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3+
# SPDX-License-Identifier: Apache-2.0
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
GIT_ROOT=$(readlink -f ./$(git rev-parse --show-cdup))
18+
19+
# Utilities
20+
21+
YELLOW="\e[1;33m"
22+
RED="\e[1;31m"
23+
NOCOLOR="\e[0m"
24+
25+
print_error() {
26+
echo -e "${RED}ERROR${NOCOLOR}:" $*
27+
}
28+
29+
if [ ! -d $GIT_ROOT/build/endoscopy_tool_tracking ]; then
30+
print_error "Please build the Endoscopy Tool Tracking application first with the following command:"
31+
print_error "./dev_container build_and_run endoscopy_tool_tracking"
32+
exit -1
33+
fi
34+
35+
APP_PATH="$GIT_ROOT/endoscopy_tool_tracking_python"
36+
echo Creating application directory $APP_PATH...
37+
mkdir -p $APP_PATH
38+
echo Copying application files to $APP_PATH...
39+
cp -f $GIT_ROOT/applications/endoscopy_tool_tracking/python/endoscopy_tool_tracking.py $APP_PATH
40+
cp -f $GIT_ROOT/applications/endoscopy_tool_tracking/python/endoscopy_tool_tracking.yaml $APP_PATH
41+
cp -f $GIT_ROOT/build/endoscopy_tool_tracking/gxf_extensions/lstm_tensor_rt_inference/*.so $APP_PATH
42+
cp -f $GIT_ROOT/build/endoscopy_tool_tracking/operators/lstm_tensor_rt_inference/liblstm_tensor_rt_inference.so $APP_PATH
43+
cp -f $GIT_ROOT/build/endoscopy_tool_tracking/operators/tool_tracking_postprocessor/libtool_tracking_postprocessor.so $APP_PATH
44+
cp -rf $GIT_ROOT/build/endoscopy_tool_tracking/python/lib/holohub $APP_PATH
45+
echo Updating application configuration...
46+
sed -e s!gxf_extensions/lstm_tensor_rt_inference/!!g -i $APP_PATH/endoscopy_tool_tracking.yaml
47+
48+
49+
echo -e "done\n"
50+
echo -e Use the following commands to package and run the Endoscopy Tool Tracking application:\n
51+
echo -e "Package the application:\n"
52+
echo -e "${YELLOW}holoscan package -c $APP_PATH/endoscopy_tool_tracking.yaml --platform x64-workstation -t holohub-endoscopy-tool-tracking-python $APP_PATH/endoscopy_tool_tracking.py --include onnx holoviz${NOCOLOR}"
53+
echo -e "Run the application:\n"
54+
echo -e "${YELLOW}holoscan run -r \$(docker images | grep "holohub-endoscopy-tool-tracking-python" | awk '{print \$1\":\"\$2}') -i $GIT_ROOT/data/endoscopy${NOCOLOR}"

applications/object_detection_torch/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,7 @@ On aarch64, if application is executed from within the holoscan sdk container an
7171
```bash
7272
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/opt/hpcx/ompi/lib"
7373
```
74+
75+
## Containerize the application
76+
77+
To containerize the application, first build the application and then run the `package-app.sh` script and follow the generated output to package and run the application.

applications/object_detection_torch/main.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,18 @@ int main(int argc, char **argv) {
264264
return 1;
265265
}
266266

267+
if (data_path.empty()) {
268+
// Get the input data environment variable
269+
auto input_path = std::getenv("HOLOSCAN_INPUT_PATH");
270+
if (input_path == nullptr || input_path[0] == '\0') {
271+
HOLOSCAN_LOG_ERROR(
272+
"Input data not provided. Use --data or set HOLOSCAN_INPUT_PATH environment variable.");
273+
exit(-1);
274+
}
275+
data_path = std::string(input_path);
276+
}
277+
HOLOSCAN_LOG_INFO("Using input data from {}", data_path);
278+
267279
if (config_name != "") {
268280
app->config(config_name);
269281
} else {
@@ -277,8 +289,7 @@ int main(int argc, char **argv) {
277289

278290
auto source = app->from_config("source").as<std::string>();
279291
app->set_source(source);
280-
if (data_path != "")
281-
app->set_datapath(data_path);
292+
app->set_datapath(data_path);
282293
app->run();
283294

284295
return 0;

applications/object_detection_torch/object_detection_torch.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616
---
17+
application:
18+
title: Holohub - Object Detection Torch
19+
version: 1.0
20+
inputFormats: []
21+
outputFormats: ["screen"]
22+
23+
resources:
24+
cpu: 2
25+
gpu: 1
26+
memory: 1Gi
27+
gpuMemory: 2Gi
28+
1729
extensions:
1830

1931
source: "replayer" # or "aja"
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/bash
2+
# SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3+
# SPDX-License-Identifier: Apache-2.0
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
GIT_ROOT=$(readlink -f ./$(git rev-parse --show-cdup))
18+
19+
# Utilities
20+
21+
YELLOW="\e[1;33m"
22+
RED="\e[1;31m"
23+
NOCOLOR="\e[0m"
24+
25+
print_error() {
26+
echo -e "${RED}ERROR${NOCOLOR}:" $*
27+
}
28+
29+
if [ ! -d $GIT_ROOT/build/object_detection_torch ]; then
30+
print_error "Please build the Object Detection Torch application first with the following command:"
31+
print_error "./dev_container build_and_run object_detection_torch"
32+
exit -1
33+
fi
34+
35+
APP_PATH="$GIT_ROOT/object_detection_torch"
36+
echo Creating application directory $APP_PATH...
37+
mkdir -p $APP_PATH
38+
echo Copying application files to $APP_PATH...
39+
cp -f $GIT_ROOT/build/object_detection_torch/applications/object_detection_torch/object_detection_torch $APP_PATH
40+
cp -f $GIT_ROOT/build/object_detection_torch/applications/object_detection_torch/object_detection_torch.yaml $APP_PATH
41+
42+
echo -e "done\n"
43+
echo -e Use the following commands to package and run the Object Detection Torch application:\n
44+
echo -e "Package the application:\n"
45+
echo -e "${YELLOW}holoscan package -c $APP_PATH/object_detection_torch.yaml --platform x64-workstation -t holohub-object-detection-torch $APP_PATH/object_detection_torch --include onnx holoviz torch${NOCOLOR}"
46+
echo -e "Run the application:\n"
47+
echo -e "${YELLOW}holoscan run -r \$(docker images | grep "holohub-object-detection-torch" | awk '{print \$1\":\"\$2}') -i $GIT_ROOT/data/object_detection_torch${NOCOLOR}"

0 commit comments

Comments
 (0)