From 512b539f37624c4667699b9116e08bb36552e6b5 Mon Sep 17 00:00:00 2001 From: daquexian Date: Thu, 21 Nov 2019 17:33:55 +0800 Subject: [PATCH] Make AddLayer_* in model builder return expected object instead of throw exceptions on error --- dnnlibrary/ModelBuilderImpl.cpp | 170 +++++++++++++++++------------- generate_code.py | 9 +- include/common/data_types.h | 2 +- include/dnnlibrary/ModelBuilder.h | 101 ++++++++++-------- 4 files changed, 157 insertions(+), 125 deletions(-) diff --git a/dnnlibrary/ModelBuilderImpl.cpp b/dnnlibrary/ModelBuilderImpl.cpp index f87770b..dbe7ee6 100644 --- a/dnnlibrary/ModelBuilderImpl.cpp +++ b/dnnlibrary/ModelBuilderImpl.cpp @@ -11,7 +11,7 @@ namespace dnn { using namespace android::nn::wrapper; // ModelBuilder auto generated methods start -void ModelBuilder::AddLayer_CONV_2D( +expected ModelBuilder::AddLayer_CONV_2D( const std::string &input, const std::string &weight, const dnn::optional &bias, int32_t padding_left, int32_t padding_right, int32_t padding_top, int32_t padding_bottom, @@ -19,7 +19,7 @@ void ModelBuilder::AddLayer_CONV_2D( const std::string &output, const dnn::optional &output_quant_info) { if (nnapi_->android_sdk_version < 27) { - throw std::runtime_error("CONV_2D requires API 27"); + return make_unexpected("CONV_2D requires API 27"); } IndexSeq input_indexes; imm_blob_inputs_.insert(input); @@ -63,16 +63,17 @@ void ModelBuilder::AddLayer_CONV_2D( AddOperation(ANEURALNETWORKS_CONV_2D, input_indexes, operand_type)[0]; RegisterOperand(output, output_idx, operand_type); imm_blob_outputs_.insert(output); + return Unit(); } -void ModelBuilder::AddLayer_AVERAGE_POOL_2D( +expected ModelBuilder::AddLayer_AVERAGE_POOL_2D( const std::string &input, int32_t padding_left, int32_t padding_right, int32_t padding_top, int32_t padding_bottom, int32_t stride_x, int32_t stride_y, int32_t kernel_width, int32_t kernel_height, int32_t fuse_code, const std::string &output, const dnn::optional &output_quant_info) { if (nnapi_->android_sdk_version < 27) { - throw std::runtime_error("AVERAGE_POOL_2D requires API 27"); + return make_unexpected("AVERAGE_POOL_2D requires API 27"); } IndexSeq input_indexes; imm_blob_inputs_.insert(input); @@ -90,16 +91,17 @@ void ModelBuilder::AddLayer_AVERAGE_POOL_2D( input_indexes, operand_type)[0]; RegisterOperand(output, output_idx, operand_type); imm_blob_outputs_.insert(output); + return Unit(); } -void ModelBuilder::AddLayer_MAX_POOL_2D( +expected ModelBuilder::AddLayer_MAX_POOL_2D( const std::string &input, int32_t padding_left, int32_t padding_right, int32_t padding_top, int32_t padding_bottom, int32_t stride_x, int32_t stride_y, int32_t kernel_width, int32_t kernel_height, int32_t fuse_code, const std::string &output, const dnn::optional &output_quant_info) { if (nnapi_->android_sdk_version < 27) { - throw std::runtime_error("MAX_POOL_2D requires API 27"); + return make_unexpected("MAX_POOL_2D requires API 27"); } IndexSeq input_indexes; imm_blob_inputs_.insert(input); @@ -117,12 +119,13 @@ void ModelBuilder::AddLayer_MAX_POOL_2D( input_indexes, operand_type)[0]; RegisterOperand(output, output_idx, operand_type); imm_blob_outputs_.insert(output); + return Unit(); } -void ModelBuilder::AddLayer_RELU(const std::string &input, - const std::string &output) { +expected ModelBuilder::AddLayer_RELU( + const std::string &input, const std::string &output) { if (nnapi_->android_sdk_version < 27) { - throw std::runtime_error("RELU requires API 27"); + return make_unexpected("RELU requires API 27"); } IndexSeq input_indexes; imm_blob_inputs_.insert(input); @@ -135,12 +138,13 @@ void ModelBuilder::AddLayer_RELU(const std::string &input, AddOperation(ANEURALNETWORKS_RELU, input_indexes, operand_type)[0]; RegisterOperand(output, output_idx, operand_type); imm_blob_outputs_.insert(output); + return Unit(); } -void ModelBuilder::AddLayer_SOFTMAX(const std::string &input, float beta, - const std::string &output) { +expected ModelBuilder::AddLayer_SOFTMAX( + const std::string &input, float beta, const std::string &output) { if (nnapi_->android_sdk_version < 27) { - throw std::runtime_error("SOFTMAX requires API 27"); + return make_unexpected("SOFTMAX requires API 27"); } IndexSeq input_indexes; imm_blob_inputs_.insert(input); @@ -154,15 +158,16 @@ void ModelBuilder::AddLayer_SOFTMAX(const std::string &input, float beta, AddOperation(ANEURALNETWORKS_SOFTMAX, input_indexes, operand_type)[0]; RegisterOperand(output, output_idx, operand_type); imm_blob_outputs_.insert(output); + return Unit(); } -void ModelBuilder::AddLayer_FULLY_CONNECTED( +expected ModelBuilder::AddLayer_FULLY_CONNECTED( const std::string &input, const std::string &weight, const dnn::optional &bias, int32_t fuse_code, const std::string &output, const dnn::optional &output_quant_info) { if (nnapi_->android_sdk_version < 27) { - throw std::runtime_error("FULLY_CONNECTED requires API 27"); + return make_unexpected("FULLY_CONNECTED requires API 27"); } IndexSeq input_indexes; imm_blob_inputs_.insert(input); @@ -204,14 +209,15 @@ void ModelBuilder::AddLayer_FULLY_CONNECTED( input_indexes, operand_type)[0]; RegisterOperand(output, output_idx, operand_type); imm_blob_outputs_.insert(output); + return Unit(); } -void ModelBuilder::AddLayer_ADD( +expected ModelBuilder::AddLayer_ADD( const std::string &input1, const std::string &input2, int32_t fuse_code, const std::string &output, const dnn::optional &output_quant_info) { if (nnapi_->android_sdk_version < 27) { - throw std::runtime_error("ADD requires API 27"); + return make_unexpected("ADD requires API 27"); } IndexSeq input_indexes; imm_blob_inputs_.insert(input1); @@ -228,13 +234,14 @@ void ModelBuilder::AddLayer_ADD( AddOperation(ANEURALNETWORKS_ADD, input_indexes, operand_type)[0]; RegisterOperand(output, output_idx, operand_type); imm_blob_outputs_.insert(output); + return Unit(); } -void ModelBuilder::AddLayer_CONCATENATION( +expected ModelBuilder::AddLayer_CONCATENATION( const std::vector &inputs, int32_t axis, const std::string &output) { if (nnapi_->android_sdk_version < 27) { - throw std::runtime_error("CONCATENATION requires API 27"); + return make_unexpected("CONCATENATION requires API 27"); } IndexSeq input_indexes; for (const auto &x : inputs) { @@ -249,9 +256,10 @@ void ModelBuilder::AddLayer_CONCATENATION( input_indexes, operand_type)[0]; RegisterOperand(output, output_idx, operand_type); imm_blob_outputs_.insert(output); + return Unit(); } -void ModelBuilder::AddLayer_DEPTHWISE_CONV_2D( +expected ModelBuilder::AddLayer_DEPTHWISE_CONV_2D( const std::string &input, const std::string &weight, const dnn::optional &bias, int32_t padding_left, int32_t padding_right, int32_t padding_top, int32_t padding_bottom, @@ -259,7 +267,7 @@ void ModelBuilder::AddLayer_DEPTHWISE_CONV_2D( int32_t fuse_code, const std::string &output, const dnn::optional &output_quant_info) { if (nnapi_->android_sdk_version < 27) { - throw std::runtime_error("DEPTHWISE_CONV_2D requires API 27"); + return make_unexpected("DEPTHWISE_CONV_2D requires API 27"); } IndexSeq input_indexes; imm_blob_inputs_.insert(input); @@ -305,13 +313,14 @@ void ModelBuilder::AddLayer_DEPTHWISE_CONV_2D( input_indexes, operand_type)[0]; RegisterOperand(output, output_idx, operand_type); imm_blob_outputs_.insert(output); + return Unit(); } -void ModelBuilder::AddLayer_BATCH_TO_SPACE_ND( +expected ModelBuilder::AddLayer_BATCH_TO_SPACE_ND( const std::string &input, const std::vector &block_sizes, const std::string &output) { if (nnapi_->android_sdk_version < 28) { - throw std::runtime_error("BATCH_TO_SPACE_ND requires API 28"); + return make_unexpected("BATCH_TO_SPACE_ND requires API 28"); } IndexSeq input_indexes; imm_blob_inputs_.insert(input); @@ -328,13 +337,14 @@ void ModelBuilder::AddLayer_BATCH_TO_SPACE_ND( input_indexes, operand_type)[0]; RegisterOperand(output, output_idx, operand_type); imm_blob_outputs_.insert(output); + return Unit(); } -void ModelBuilder::AddLayer_SPACE_TO_BATCH_ND( +expected ModelBuilder::AddLayer_SPACE_TO_BATCH_ND( const std::string &input, const std::vector &block_sizes, const std::vector &pads, const std::string &output) { if (nnapi_->android_sdk_version < 28) { - throw std::runtime_error("SPACE_TO_BATCH_ND requires API 28"); + return make_unexpected("SPACE_TO_BATCH_ND requires API 28"); } IndexSeq input_indexes; imm_blob_inputs_.insert(input); @@ -355,17 +365,16 @@ void ModelBuilder::AddLayer_SPACE_TO_BATCH_ND( input_indexes, operand_type)[0]; RegisterOperand(output, output_idx, operand_type); imm_blob_outputs_.insert(output); + return Unit(); } -void ModelBuilder::AddLayer_STRIDED_SLICE(const std::string &input, - const std::vector &starts, - const std::vector &ends, - const std::vector &strides, - int32_t begin_mask, int32_t end_mask, - int32_t shrink_axis_mask, - const std::string &output) { +expected ModelBuilder::AddLayer_STRIDED_SLICE( + const std::string &input, const std::vector &starts, + const std::vector &ends, const std::vector &strides, + int32_t begin_mask, int32_t end_mask, int32_t shrink_axis_mask, + const std::string &output) { if (nnapi_->android_sdk_version < 28) { - throw std::runtime_error("STRIDED_SLICE requires API 28"); + return make_unexpected("STRIDED_SLICE requires API 28"); } IndexSeq input_indexes; imm_blob_inputs_.insert(input); @@ -392,14 +401,15 @@ void ModelBuilder::AddLayer_STRIDED_SLICE(const std::string &input, input_indexes, operand_type)[0]; RegisterOperand(output, output_idx, operand_type); imm_blob_outputs_.insert(output); + return Unit(); } -void ModelBuilder::AddLayer_MUL( +expected ModelBuilder::AddLayer_MUL( const std::string &input1, const std::string &input2, int32_t fuse_code, const std::string &output, const dnn::optional &output_quant_info) { if (nnapi_->android_sdk_version < 27) { - throw std::runtime_error("MUL requires API 27"); + return make_unexpected("MUL requires API 27"); } IndexSeq input_indexes; imm_blob_inputs_.insert(input1); @@ -416,12 +426,13 @@ void ModelBuilder::AddLayer_MUL( AddOperation(ANEURALNETWORKS_MUL, input_indexes, operand_type)[0]; RegisterOperand(output, output_idx, operand_type); imm_blob_outputs_.insert(output); + return Unit(); } -void ModelBuilder::AddLayer_DEQUANTIZE(const std::string &input, - const std::string &output) { +expected ModelBuilder::AddLayer_DEQUANTIZE( + const std::string &input, const std::string &output) { if (nnapi_->android_sdk_version < 27) { - throw std::runtime_error("DEQUANTIZE requires API 27"); + return make_unexpected("DEQUANTIZE requires API 27"); } IndexSeq input_indexes; imm_blob_inputs_.insert(input); @@ -434,14 +445,14 @@ void ModelBuilder::AddLayer_DEQUANTIZE(const std::string &input, input_indexes, operand_type)[0]; RegisterOperand(output, output_idx, operand_type); imm_blob_outputs_.insert(output); + return Unit(); } -void ModelBuilder::AddLayer_LOCAL_RESPONSE_NORMALIZATION( +expected ModelBuilder::AddLayer_LOCAL_RESPONSE_NORMALIZATION( const std::string &input, int32_t radius, float bias, float alpha, float beta, const std::string &output) { if (nnapi_->android_sdk_version < 27) { - throw std::runtime_error( - "LOCAL_RESPONSE_NORMALIZATION requires API 27"); + return make_unexpected("LOCAL_RESPONSE_NORMALIZATION requires API 27"); } IndexSeq input_indexes; imm_blob_inputs_.insert(input); @@ -456,12 +467,13 @@ void ModelBuilder::AddLayer_LOCAL_RESPONSE_NORMALIZATION( input_indexes, operand_type)[0]; RegisterOperand(output, output_idx, operand_type); imm_blob_outputs_.insert(output); + return Unit(); } -void ModelBuilder::AddLayer_TANH(const std::string &input, - const std::string &output) { +expected ModelBuilder::AddLayer_TANH( + const std::string &input, const std::string &output) { if (nnapi_->android_sdk_version < 27) { - throw std::runtime_error("TANH requires API 27"); + return make_unexpected("TANH requires API 27"); } IndexSeq input_indexes; imm_blob_inputs_.insert(input); @@ -474,12 +486,13 @@ void ModelBuilder::AddLayer_TANH(const std::string &input, AddOperation(ANEURALNETWORKS_TANH, input_indexes, operand_type)[0]; RegisterOperand(output, output_idx, operand_type); imm_blob_outputs_.insert(output); + return Unit(); } -void ModelBuilder::AddLayer_FLOOR(const std::string &input, - const std::string &output) { +expected ModelBuilder::AddLayer_FLOOR( + const std::string &input, const std::string &output) { if (nnapi_->android_sdk_version < 27) { - throw std::runtime_error("FLOOR requires API 27"); + return make_unexpected("FLOOR requires API 27"); } IndexSeq input_indexes; imm_blob_inputs_.insert(input); @@ -492,12 +505,13 @@ void ModelBuilder::AddLayer_FLOOR(const std::string &input, AddOperation(ANEURALNETWORKS_FLOOR, input_indexes, operand_type)[0]; RegisterOperand(output, output_idx, operand_type); imm_blob_outputs_.insert(output); + return Unit(); } -void ModelBuilder::AddLayer_LOGISTIC(const std::string &input, - const std::string &output) { +expected ModelBuilder::AddLayer_LOGISTIC( + const std::string &input, const std::string &output) { if (nnapi_->android_sdk_version < 27) { - throw std::runtime_error("LOGISTIC requires API 27"); + return make_unexpected("LOGISTIC requires API 27"); } IndexSeq input_indexes; imm_blob_inputs_.insert(input); @@ -510,13 +524,14 @@ void ModelBuilder::AddLayer_LOGISTIC(const std::string &input, AddOperation(ANEURALNETWORKS_LOGISTIC, input_indexes, operand_type)[0]; RegisterOperand(output, output_idx, operand_type); imm_blob_outputs_.insert(output); + return Unit(); } -void ModelBuilder::AddLayer_PRELU_Impl(const std::string &input, - const std::string &alpha, - const std::string &output) { +expected ModelBuilder::AddLayer_PRELU_Impl( + const std::string &input, const std::string &alpha, + const std::string &output) { if (nnapi_->android_sdk_version < 29) { - throw std::runtime_error("PRELU requires API 29"); + return make_unexpected("PRELU requires API 29"); } IndexSeq input_indexes; imm_blob_inputs_.insert(input); @@ -532,13 +547,14 @@ void ModelBuilder::AddLayer_PRELU_Impl(const std::string &input, AddOperation(ANEURALNETWORKS_PRELU, input_indexes, operand_type)[0]; RegisterOperand(output, output_idx, operand_type); imm_blob_outputs_.insert(output); + return Unit(); } -void ModelBuilder::AddLayer_POW(const std::string &input, - const std::string &exp, - const std::string &output) { +expected ModelBuilder::AddLayer_POW( + const std::string &input, const std::string &exp, + const std::string &output) { if (nnapi_->android_sdk_version < 29) { - throw std::runtime_error("POW requires API 29"); + return make_unexpected("POW requires API 29"); } IndexSeq input_indexes; imm_blob_inputs_.insert(input); @@ -554,12 +570,13 @@ void ModelBuilder::AddLayer_POW(const std::string &input, AddOperation(ANEURALNETWORKS_POW, input_indexes, operand_type)[0]; RegisterOperand(output, output_idx, operand_type); imm_blob_outputs_.insert(output); + return Unit(); } -void ModelBuilder::AddLayer_NEG(const std::string &input, - const std::string &output) { +expected ModelBuilder::AddLayer_NEG( + const std::string &input, const std::string &output) { if (nnapi_->android_sdk_version < 29) { - throw std::runtime_error("NEG requires API 29"); + return make_unexpected("NEG requires API 29"); } IndexSeq input_indexes; imm_blob_inputs_.insert(input); @@ -572,13 +589,14 @@ void ModelBuilder::AddLayer_NEG(const std::string &input, AddOperation(ANEURALNETWORKS_NEG, input_indexes, operand_type)[0]; RegisterOperand(output, output_idx, operand_type); imm_blob_outputs_.insert(output); + return Unit(); } -void ModelBuilder::AddLayer_MINIMUM(const std::string &input1, - const std::string &input2, - const std::string &output) { +expected ModelBuilder::AddLayer_MINIMUM( + const std::string &input1, const std::string &input2, + const std::string &output) { if (nnapi_->android_sdk_version < 29) { - throw std::runtime_error("MINIMUM requires API 29"); + return make_unexpected("MINIMUM requires API 29"); } IndexSeq input_indexes; imm_blob_inputs_.insert(input1); @@ -594,13 +612,14 @@ void ModelBuilder::AddLayer_MINIMUM(const std::string &input1, AddOperation(ANEURALNETWORKS_MINIMUM, input_indexes, operand_type)[0]; RegisterOperand(output, output_idx, operand_type); imm_blob_outputs_.insert(output); + return Unit(); } -void ModelBuilder::AddLayer_MAXIMUM(const std::string &input1, - const std::string &input2, - const std::string &output) { +expected ModelBuilder::AddLayer_MAXIMUM( + const std::string &input1, const std::string &input2, + const std::string &output) { if (nnapi_->android_sdk_version < 29) { - throw std::runtime_error("MAXIMUM requires API 29"); + return make_unexpected("MAXIMUM requires API 29"); } IndexSeq input_indexes; imm_blob_inputs_.insert(input1); @@ -616,12 +635,13 @@ void ModelBuilder::AddLayer_MAXIMUM(const std::string &input1, AddOperation(ANEURALNETWORKS_MAXIMUM, input_indexes, operand_type)[0]; RegisterOperand(output, output_idx, operand_type); imm_blob_outputs_.insert(output); + return Unit(); } -void ModelBuilder::AddLayer_LOG(const std::string &input, - const std::string &output) { +expected ModelBuilder::AddLayer_LOG( + const std::string &input, const std::string &output) { if (nnapi_->android_sdk_version < 29) { - throw std::runtime_error("LOG requires API 29"); + return make_unexpected("LOG requires API 29"); } IndexSeq input_indexes; imm_blob_inputs_.insert(input); @@ -634,13 +654,14 @@ void ModelBuilder::AddLayer_LOG(const std::string &input, AddOperation(ANEURALNETWORKS_LOG, input_indexes, operand_type)[0]; RegisterOperand(output, output_idx, operand_type); imm_blob_outputs_.insert(output); + return Unit(); } // ModelBuilder auto generated methods end -void ModelBuilder::AddLayer_PRELU(const std::string &input, - const std::string &alpha, - const std::string &output) { +expected ModelBuilder::AddLayer_PRELU( + const std::string &input, const std::string &alpha, + const std::string &output) { if (nnapi_->android_sdk_version < 29) { const auto neg1_name = output + "_neg1"; const auto imm1_name = output + "_imm1"; @@ -671,6 +692,7 @@ void ModelBuilder::AddLayer_PRELU(const std::string &input, } else { AddLayer_PRELU_Impl(input, alpha, output); } + return Unit(); } // Methods for backward compatibility diff --git a/generate_code.py b/generate_code.py index d9ef4af..d0dd3c1 100644 --- a/generate_code.py +++ b/generate_code.py @@ -348,10 +348,10 @@ def generate_model_builder(): if op['support_quant_asymm']: params.append(('const dnn::optional &', 'output_quant_info')) params_str = ', '.join(map(lambda param: "{} {}".format(*param), params)) - cogoutl("void ModelBuilder::AddLayer_{}{}({}) {{".format( + cogoutl("expected ModelBuilder::AddLayer_{}{}({}) {{".format( op['nnapi'], '' if op['builder_simple'] else '_Impl', params_str)) cogoutl(f'if (nnapi_->android_sdk_version < {op["api"]}) {{' - f'throw std::runtime_error("{op["nnapi"]} requires API {op["api"]}");' + f'return make_unexpected("{op["nnapi"]} requires API {op["api"]}");' f'}}') tensor_input = list(filter(lambda x: x['nnapi_type'] == 'tensor', op['input'])) scalar_input = list(filter(lambda x: x['nnapi_type'] == 'scalar', op['input'])) @@ -381,6 +381,7 @@ def generate_model_builder(): cogout( '''RegisterOperand(output, output_idx, operand_type); imm_blob_outputs_.insert(output); + return Unit(); } ''' @@ -395,13 +396,13 @@ def generate_model_builder(): # A hack params.append(('const dnn::optional &', 'output_quant_info=dnn::nullopt')) params_str = ', '.join(map(lambda param: "{} {}".format(*param), params)) - cogoutl("void AddLayer_{}({});".format( + cogoutl("expected AddLayer_{}({});".format( op['nnapi'], params_str)) # if op['builder_simple'] is not True, we generate both AddLayer_* and AddLayer_*_Impl declaration if not op['builder_simple']: cogoutl('private:') - cogoutl("void AddLayer_{}_Impl({});".format( + cogoutl("expected AddLayer_{}_Impl({});".format( op['nnapi'], params_str)) cogoutl('public:') update_code('include/dnnlibrary/ModelBuilder.h', 'ModelBuilder auto generated methods') diff --git a/include/common/data_types.h b/include/common/data_types.h index 2376d89..22d7ba0 100644 --- a/include/common/data_types.h +++ b/include/common/data_types.h @@ -9,6 +9,6 @@ namespace dnn { using nonstd::nullopt_t; using tl::expected; using tl::make_unexpected; - using tl::monostate; + using Unit = tl::monostate; using tl::unexpected; } diff --git a/include/dnnlibrary/ModelBuilder.h b/include/dnnlibrary/ModelBuilder.h index 094107b..e4d58a2 100644 --- a/include/dnnlibrary/ModelBuilder.h +++ b/include/dnnlibrary/ModelBuilder.h @@ -112,89 +112,98 @@ class ModelBuilder { Index AddInput(std::string name, const android::nn::wrapper::OperandType &operand_type); // ModelBuilder auto generated methods start - void AddLayer_CONV_2D( + expected AddLayer_CONV_2D( const std::string &input, const std::string &weight, const dnn::optional &bias, int32_t padding_left, int32_t padding_right, int32_t padding_top, int32_t padding_bottom, int32_t stride_x, int32_t stride_y, int32_t fuse_code, const std::string &output, const dnn::optional &output_quant_info = dnn::nullopt); - void AddLayer_AVERAGE_POOL_2D( + expected AddLayer_AVERAGE_POOL_2D( const std::string &input, int32_t padding_left, int32_t padding_right, int32_t padding_top, int32_t padding_bottom, int32_t stride_x, int32_t stride_y, int32_t kernel_width, int32_t kernel_height, int32_t fuse_code, const std::string &output, const dnn::optional &output_quant_info = dnn::nullopt); - void AddLayer_MAX_POOL_2D( + expected AddLayer_MAX_POOL_2D( const std::string &input, int32_t padding_left, int32_t padding_right, int32_t padding_top, int32_t padding_bottom, int32_t stride_x, int32_t stride_y, int32_t kernel_width, int32_t kernel_height, int32_t fuse_code, const std::string &output, const dnn::optional &output_quant_info = dnn::nullopt); - void AddLayer_RELU(const std::string &input, const std::string &output); - void AddLayer_SOFTMAX(const std::string &input, float beta, - const std::string &output); - void AddLayer_FULLY_CONNECTED( + expected AddLayer_RELU(const std::string &input, + const std::string &output); + expected AddLayer_SOFTMAX(const std::string &input, + float beta, + const std::string &output); + expected AddLayer_FULLY_CONNECTED( const std::string &input, const std::string &weight, const dnn::optional &bias, int32_t fuse_code, const std::string &output, const dnn::optional &output_quant_info = dnn::nullopt); - void AddLayer_ADD( + expected AddLayer_ADD( const std::string &input1, const std::string &input2, int32_t fuse_code, const std::string &output, const dnn::optional &output_quant_info = dnn::nullopt); - void AddLayer_CONCATENATION(const std::vector &inputs, - int32_t axis, const std::string &output); - void AddLayer_DEPTHWISE_CONV_2D( + expected AddLayer_CONCATENATION( + const std::vector &inputs, int32_t axis, + const std::string &output); + expected AddLayer_DEPTHWISE_CONV_2D( const std::string &input, const std::string &weight, const dnn::optional &bias, int32_t padding_left, int32_t padding_right, int32_t padding_top, int32_t padding_bottom, int32_t stride_x, int32_t stride_y, int32_t depth_multiplier, int32_t fuse_code, const std::string &output, const dnn::optional &output_quant_info = dnn::nullopt); - void AddLayer_BATCH_TO_SPACE_ND(const std::string &input, - const std::vector &block_sizes, - const std::string &output); - void AddLayer_SPACE_TO_BATCH_ND(const std::string &input, - const std::vector &block_sizes, - const std::vector &pads, - const std::string &output); - void AddLayer_STRIDED_SLICE(const std::string &input, - const std::vector &starts, - const std::vector &ends, - const std::vector &strides, - int32_t begin_mask, int32_t end_mask, - int32_t shrink_axis_mask, - const std::string &output); - void AddLayer_MUL( + expected AddLayer_BATCH_TO_SPACE_ND( + const std::string &input, const std::vector &block_sizes, + const std::string &output); + expected AddLayer_SPACE_TO_BATCH_ND( + const std::string &input, const std::vector &block_sizes, + const std::vector &pads, const std::string &output); + expected AddLayer_STRIDED_SLICE( + const std::string &input, const std::vector &starts, + const std::vector &ends, const std::vector &strides, + int32_t begin_mask, int32_t end_mask, int32_t shrink_axis_mask, + const std::string &output); + expected AddLayer_MUL( const std::string &input1, const std::string &input2, int32_t fuse_code, const std::string &output, const dnn::optional &output_quant_info = dnn::nullopt); - void AddLayer_DEQUANTIZE(const std::string &input, - const std::string &output); - void AddLayer_LOCAL_RESPONSE_NORMALIZATION(const std::string &input, - int32_t radius, float bias, - float alpha, float beta, + expected AddLayer_DEQUANTIZE(const std::string &input, + const std::string &output); + expected AddLayer_LOCAL_RESPONSE_NORMALIZATION( + const std::string &input, int32_t radius, float bias, float alpha, + float beta, const std::string &output); + expected AddLayer_TANH(const std::string &input, + const std::string &output); + expected AddLayer_FLOOR(const std::string &input, + const std::string &output); + expected AddLayer_LOGISTIC(const std::string &input, + const std::string &output); + expected AddLayer_PRELU(const std::string &input, + const std::string &alpha, const std::string &output); - void AddLayer_TANH(const std::string &input, const std::string &output); - void AddLayer_FLOOR(const std::string &input, const std::string &output); - void AddLayer_LOGISTIC(const std::string &input, const std::string &output); - void AddLayer_PRELU(const std::string &input, const std::string &alpha, - const std::string &output); private: - void AddLayer_PRELU_Impl(const std::string &input, const std::string &alpha, - const std::string &output); + expected AddLayer_PRELU_Impl(const std::string &input, + const std::string &alpha, + const std::string &output); public: - void AddLayer_POW(const std::string &input, const std::string &exp, - const std::string &output); - void AddLayer_NEG(const std::string &input, const std::string &output); - void AddLayer_MINIMUM(const std::string &input1, const std::string &input2, - const std::string &output); - void AddLayer_MAXIMUM(const std::string &input1, const std::string &input2, - const std::string &output); - void AddLayer_LOG(const std::string &input, const std::string &output); + expected AddLayer_POW(const std::string &input, + const std::string &exp, + const std::string &output); + expected AddLayer_NEG(const std::string &input, + const std::string &output); + expected AddLayer_MINIMUM(const std::string &input1, + const std::string &input2, + const std::string &output); + expected AddLayer_MAXIMUM(const std::string &input1, + const std::string &input2, + const std::string &output); + expected AddLayer_LOG(const std::string &input, + const std::string &output); // ModelBuilder auto generated methods end Index AddTensorFromPersistentBuffer( const std::string &name, const void *buffer,