From d6477da75d65bffd71e866de7181223d5f8ab2ad Mon Sep 17 00:00:00 2001 From: chenqian Date: Tue, 8 Nov 2022 15:38:18 +0800 Subject: [PATCH 1/2] Modify executable file output help message content. Signed-off-by: chenqian --- .../nnrt_delegate/nnrt_delegate_kernel.cpp | 10 ++++----- .../tflite/label_classify/label_classify.cpp | 22 ++++++++++++++----- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/example/deep_learning_framework/tflite/delegates/nnrt_delegate/nnrt_delegate_kernel.cpp b/example/deep_learning_framework/tflite/delegates/nnrt_delegate/nnrt_delegate_kernel.cpp index 05933ae..77e5286 100644 --- a/example/deep_learning_framework/tflite/delegates/nnrt_delegate/nnrt_delegate_kernel.cpp +++ b/example/deep_learning_framework/tflite/delegates/nnrt_delegate/nnrt_delegate_kernel.cpp @@ -41,13 +41,13 @@ namespace delegate { namespace nnrt { constexpr int32_t SCALAR_RANK = 1; -#define RETURN_TFLITE_ERROR_IF_NN_ERROR_FOR_COMPILE(code, callDesc) \ +#define RETURN_TFLITE_ERROR_IF_NN_ERROR_FOR_COMPILE(code, callDesc) \ do { \ if ( (code) != OH_NN_SUCCESS) { \ - const auto errorDesc = NnrtErrorDescription((code)); \ - TFLITE_LOG_PROD(TFLITE_LOG_ERROR, "NN API returned error %s at line %d while %s.\n", errorDesc.c_str(), \ + const auto errorDesc = NnrtErrorDescription((code)); \ + TFLITE_LOG_PROD(TFLITE_LOG_ERROR, "NN API returned error %s at line %d while %s.\n", errorDesc.c_str(), \ __LINE__, (callDesc)); \ - m_nnrt->OH_NNCompilation_Destroy(&m_pNnCompilation); \ + m_nnrt->OH_NNCompilation_Destroy(&m_pNnCompilation); \ return kTfLiteError; \ } \ } while (0) @@ -417,4 +417,4 @@ TfLiteStatus NnrtDelegateKernel::SetNnOptions(TfLiteContext* context, const Nnrt } } // namespace nnrt } // namespace delegate -} // tflite \ No newline at end of file +} // tflite diff --git a/example/deep_learning_framework/tflite/label_classify/label_classify.cpp b/example/deep_learning_framework/tflite/label_classify/label_classify.cpp index 18b8506..c92f44d 100644 --- a/example/deep_learning_framework/tflite/label_classify/label_classify.cpp +++ b/example/deep_learning_framework/tflite/label_classify/label_classify.cpp @@ -250,9 +250,9 @@ void InferenceModel(Settings& settings, DelegateProviders& delegateProviders) void DisplayUsage() { - LOG(INFO) << "label_classify\n" + LOG(INFO) << "label_classify -m xxx.tflite -i xxx.bmp -l xxx.txt -c 1 -a 1\n" << "\t--help, -h: show the usage of the demo\n" - << "\t--use_nnrt, -a: [0|1], use NNRT or not\n" + << "\t--use_nnrt, -a: [0|1], 1 refers to use NNRT\n" << "\t--input_mean, -b: input mean\n" << "\t--count, -c: loop interpreter->Invoke() for certain times\n" << "\t--image, -i: image_name.bmp\n" @@ -266,7 +266,7 @@ void DisplayUsage() << "\t--input_shape, -p: Indicates the specified dynamic input node and the corresponding shape.\n"; } -void InitSettings(int32_t argc, char** argv, Settings& settings) +int32_t InitSettings(int32_t argc, char** argv, Settings& settings) { // getopt_long stores the option index here. int32_t optionIndex = 0; @@ -312,11 +312,13 @@ void InitSettings(int32_t argc, char** argv, Settings& settings) case '?': // getopt_long already printed an error message. DisplayUsage(); - return; + return -1; default: - return; + return -1; } } + + return 0; } int32_t Main(int32_t argc, char** argv) @@ -327,8 +329,16 @@ int32_t Main(int32_t argc, char** argv) return EXIT_FAILURE; } + if (argc <= 1) { + DisplayUsage(); + return EXIT_FAILURE; + } + Settings settings; - InitSettings(argc, argv, settings); + if (InitSettings(argc, argv, settings) == -1) { + return EXIT_FAILURE; + }; + InferenceModel(settings, delegateProviders); return 0; } -- Gitee From 3c7d0101bf6bb51a48a97dad7cc4f8e682f14929 Mon Sep 17 00:00:00 2001 From: chenqian Date: Tue, 8 Nov 2022 16:27:28 +0800 Subject: [PATCH 2/2] Signed-off-by: chenqian Modify the position of the Main function entry in label_classify. --- .../tflite/label_classify/label_classify.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/example/deep_learning_framework/tflite/label_classify/label_classify.cpp b/example/deep_learning_framework/tflite/label_classify/label_classify.cpp index c92f44d..b8cf450 100644 --- a/example/deep_learning_framework/tflite/label_classify/label_classify.cpp +++ b/example/deep_learning_framework/tflite/label_classify/label_classify.cpp @@ -323,14 +323,14 @@ int32_t InitSettings(int32_t argc, char** argv, Settings& settings) int32_t Main(int32_t argc, char** argv) { - DelegateProviders delegateProviders; - bool parseResult = delegateProviders.InitFromCmdlineArgs(&argc, const_cast(argv)); - if (!parseResult) { + if (argc <= 1) { + DisplayUsage(); return EXIT_FAILURE; } - if (argc <= 1) { - DisplayUsage(); + DelegateProviders delegateProviders; + bool parseResult = delegateProviders.InitFromCmdlineArgs(&argc, const_cast(argv)); + if (!parseResult) { return EXIT_FAILURE; } -- Gitee