[NNAPI EP] Fix MaxPool error using uint8 (#9129)

* fix issue in maxpool running using uint8

* Minor update
This commit is contained in:
Guoyu Wang 2021-09-21 00:44:43 -07:00 committed by GitHub
parent f7dedc9002
commit 4df94a631d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 9 deletions

View file

@ -1284,8 +1284,10 @@ Status PoolOpBuilder::AddToModelBuilderImpl(ModelBuilder& model_builder, const N
int32_t fuse_code = model_builder.FindActivation(node, *node.OutputDefs()[0]);
// Get output scale and zero point if this is QLinearAveragePool
float y_scale = 0.0f;
int32_t y_zero_point = 0;
// Otherwise we will use the scale and zero point of the input
const OperandType& input_operand_type = operand_types.at(input);
float y_scale = input_operand_type.operandType.scale;
int32_t y_zero_point = input_operand_type.operandType.zeroPoint;
if (is_qlinear_average_pool) {
const auto& initializers = model_builder.GetInitializerTensors();
float x_scale = 0.0f;

View file

@ -82,7 +82,7 @@ TEST(NnapiExecutionProviderTest, InternalUint8SupportTest) {
const ORTCHAR_T* model_file_name = ORT_TSTR("testdata/nnapi_internal_uint8_support.onnx");
#if defined(__ANDROID__)
std::vector<int64_t> dims_x = {1, 3};
std::vector<int64_t> dims_x = {1, 1, 1, 3};
std::vector<float> values_x = {0.0f, 256.0f, 512.0f};
OrtValue ml_value_x;
CreateMLValue<float>(TestNnapiExecutionProvider()->GetAllocator(0, OrtMemTypeDefault), dims_x, values_x,

View file

@ -8,10 +8,11 @@ from onnx import TensorProto
# def GenerateModel(model_name):
def GenerateModel(model_name):
nodes = [
helper.make_node("QuantizeLinear", ["X", "Scale", "Zero_point"], ["X_quantized"], "quantize"),
helper.make_node("Concat", ["X_quantized", "X_quantized"], ["X_concat"], axis=0, name="concat"),
helper.make_node("Transpose", ["X_concat"], ["X_transposed"], "transpose"),
helper.make_node("DequantizeLinear", ["X_transposed", "Scale", "Zero_point"], ["Y"], "dequantize"),
helper.make_node("QuantizeLinear", ["X", "Scale", "Zero_point"], ["X_quantized"], "quantize_0"),
helper.make_node("Concat", ["X_quantized", "X_quantized"], ["X_concat"], axis=-2, name="concat_0"),
helper.make_node("MaxPool", ["X_concat"], ["X_maxpool"], kernel_shape=[2, 2], name="maxpool_0"),
helper.make_node("Transpose", ["X_maxpool"], ["X_transposed"], perm=[0, 1, 3, 2], name="transpose_0"),
helper.make_node("DequantizeLinear", ["X_transposed", "Scale", "Zero_point"], ["Y"], "dequantize_0"),
]
initializers = [
@ -20,14 +21,14 @@ def GenerateModel(model_name):
]
inputs = [
helper.make_tensor_value_info('X', TensorProto.FLOAT, [1, 3]),
helper.make_tensor_value_info('X', TensorProto.FLOAT, [1, 1, 1, 3]),
]
graph = helper.make_graph(
nodes,
"NNAPI_Internal_uint8_Test",
inputs,
[helper.make_tensor_value_info('Y', TensorProto.FLOAT, [3, 2])],
[helper.make_tensor_value_info('Y', TensorProto.FLOAT, [1, 1, 2, 1])],
initializers
)