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 05933aeea2daba081ed6a9af0266a3967d32abc3..77e52864ce9769033bb28315d07ba34ff1f91a11 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 18b8506db90b05d0e65282d1a056b93283010999..b8cf45026a0381e24bfe7c118fc2b334126069e5 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,15 +312,22 @@ 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) { + if (argc <= 1) { + DisplayUsage(); + return EXIT_FAILURE; + } + DelegateProviders delegateProviders; bool parseResult = delegateProviders.InitFromCmdlineArgs(&argc, const_cast(argv)); if (!parseResult) { @@ -328,7 +335,10 @@ int32_t Main(int32_t argc, char** argv) } Settings settings; - InitSettings(argc, argv, settings); + if (InitSettings(argc, argv, settings) == -1) { + return EXIT_FAILURE; + }; + InferenceModel(settings, delegateProviders); return 0; }