-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Compiling * Fixed bug * Added to readme * Added to gitignore * Added support for loading TensorRT engine file directly * Minor fixes * Added log message * Added command line parser * Updated changelog * Added clang-format and reformatted all files * Changed formatting
- Loading branch information
Showing
8 changed files
with
875 additions
and
652 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
Language: Cpp | ||
# BasedOnStyle: LLVM | ||
AccessModifierOffset: -4 | ||
ColumnLimit: 140 | ||
IndentWidth: 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,5 +35,7 @@ | |
build*/ | ||
cmake-build-* | ||
.idea/ | ||
.vscode/ | ||
|
||
*.onnx | ||
|
||
*.onnx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
repos: | ||
- repo: https://github.com/pre-commit/mirrors-clang-format | ||
rev: 'v17.0.3' # Use the sha / tag you want to point at | ||
hooks: | ||
- id: clang-format | ||
types_or: [c++, c, cuda] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
#pragma once | ||
#include "engine.h" | ||
#include <iostream> | ||
|
||
struct CommandLineArguments { | ||
std::string onnxModelPath = ""; | ||
std::string trtModelPath = ""; | ||
}; | ||
|
||
inline void showHelp(char *argv[]) { | ||
std::cout << "Usage: " << argv[0] << " [OPTIONS]" << std::endl << std::endl; | ||
|
||
std::cout << "Options:" << std::endl; | ||
std::cout << "--onnx_model <string> Path to the ONNX model. " | ||
"(Either onnx_model or trt_model must be provided)" | ||
<< std::endl; | ||
std::cout << "--trt_model <string> Path to the TensorRT model. " | ||
"(Either onnx_model or trt_model must be provided)" | ||
<< std::endl; | ||
|
||
std::cout << "Example usage:" << std::endl; | ||
std::cout << argv[0] << " --onnx_model model.onnx" << std::endl; | ||
}; | ||
|
||
inline bool tryGetNextArgument(int argc, char *argv[], int ¤tIndex, std::string &value, std::string flag, bool printErrors = true) { | ||
if (currentIndex + 1 >= argc) { | ||
if (printErrors) | ||
std::cout << "Error: No arguments provided for flag '" << flag << "'" << std::endl; | ||
return false; | ||
} | ||
|
||
std::string nextArgument = argv[currentIndex + 1]; | ||
if (nextArgument.substr(0, 2) == "--") { | ||
if (printErrors) | ||
std::cout << "Error: No arguments provided for flag '" << flag << "'" << std::endl; | ||
return false; | ||
} | ||
|
||
value = argv[++currentIndex]; | ||
return true; | ||
}; | ||
|
||
inline bool parseArguments(int argc, char *argv[], CommandLineArguments &arguments) { | ||
if (argc == 1) { | ||
showHelp(argv); | ||
return false; | ||
} | ||
|
||
for (int i = 1; i < argc; i++) { | ||
std::string argument = argv[i]; | ||
|
||
if (argument.substr(0, 2) == "--") { | ||
std::string flag = argument.substr(2); | ||
std::string nextArgument; | ||
|
||
if (flag == "onnx_model") { | ||
if (!tryGetNextArgument(argc, argv, i, nextArgument, flag)) | ||
return false; | ||
|
||
if (!Util::doesFileExist(nextArgument)) { | ||
std::cout << "Error: Unable to find model at path '" << nextArgument << "' for flag '" << flag << "'" << std::endl; | ||
return false; | ||
} | ||
|
||
arguments.onnxModelPath = nextArgument; | ||
} | ||
|
||
else if (flag == "trt_model") { | ||
if (!tryGetNextArgument(argc, argv, i, nextArgument, flag)) | ||
return false; | ||
|
||
if (!Util::doesFileExist(nextArgument)) { | ||
std::cout << "Error: Unable to find model at path '" << nextArgument << "' for flag '" << flag << "'" << std::endl; | ||
return false; | ||
} | ||
|
||
arguments.trtModelPath = nextArgument; | ||
} | ||
|
||
else { | ||
std::cout << "Error: Unknown flag '" << flag << "'" << std::endl; | ||
showHelp(argv); | ||
return false; | ||
} | ||
} else { | ||
std::cout << "Error: Unknown argument '" << argument << "'" << std::endl; | ||
showHelp(argv); | ||
return false; | ||
} | ||
} | ||
|
||
if (arguments.onnxModelPath.empty() && arguments.trtModelPath.empty()) { | ||
std::cout << "Error: Must specify either 'onnx_model' or 'trt_model'" << std::endl; | ||
return false; | ||
} | ||
|
||
return true; | ||
} |
Oops, something went wrong.