|
| 1 | +From 9c0054c868c9953553c594fe441af33d0b492bb8 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Ritul Jasuja <ritul.jasuja@intel.com> |
| 3 | +Date: Tue, 9 Nov 2021 13:43:19 +0530 |
| 4 | +Subject: [PATCH] Add Float16 support for Resize Bilinear and Resize Nearest |
| 5 | + Neighbor op |
| 6 | + |
| 7 | +Adds Float16 support for ResizeBilinear and ResizeNearestNeighbor |
| 8 | + |
| 9 | +Signed-off-by: Ritul Jasuja <ritul.jasuja@intel.com> |
| 10 | +--- |
| 11 | + .../operations/src/ResizeBilinear.cpp | 23 ++++++++----------- |
| 12 | + .../operations/src/ResizeNearestNeighbor.cpp | 23 ++++++++----------- |
| 13 | + 2 files changed, 18 insertions(+), 28 deletions(-) |
| 14 | + |
| 15 | +diff --git a/ngraph_creator/operations/src/ResizeBilinear.cpp b/ngraph_creator/operations/src/ResizeBilinear.cpp |
| 16 | +index eee470355d6a..cddbf4c84f70 100644 |
| 17 | +--- a/ngraph_creator/operations/src/ResizeBilinear.cpp |
| 18 | ++++ b/ngraph_creator/operations/src/ResizeBilinear.cpp |
| 19 | +@@ -11,18 +11,6 @@ ResizeBilinear::ResizeBilinear(int operationIndex) : OperationsBase(operationInd |
| 20 | + } |
| 21 | + |
| 22 | + bool ResizeBilinear::validate() { |
| 23 | +- // TODO Add FLOAT16 check when VPUX plugin is supported |
| 24 | +- if (!checkOutputOperandType(0, (int32_t)OperandType::TENSOR_FLOAT32) && |
| 25 | +- !checkOutputOperandType(0, (int32_t)OperandType::TENSOR_QUANT8_ASYMM)) { |
| 26 | +- ALOGE("%s check for output types failed", __func__); |
| 27 | +- return false; |
| 28 | +- } |
| 29 | +- |
| 30 | +- if (!checkInputOperandType(0, (int32_t)OperandType::TENSOR_FLOAT32) && |
| 31 | +- !checkInputOperandType(0, (int32_t)OperandType::TENSOR_QUANT8_ASYMM)) { |
| 32 | +- return false; |
| 33 | +- } |
| 34 | +- |
| 35 | + const auto& inputDimensionsSize = getInputOperandDimensions(0).size(); |
| 36 | + if (inputDimensionsSize != 4) { |
| 37 | + ALOGE("%s Invalid dimensions size for input(%lu)", __func__, inputDimensionsSize); |
| 38 | +@@ -73,8 +61,7 @@ std::shared_ptr<ngraph::Node> ResizeBilinear::createNode() { |
| 39 | + |
| 40 | + if (!useNchw) inputNode = transpose(NHWC_NCHW, inputNode); |
| 41 | + // FLOAT16 type check added for future when VPUX plugin support is added |
| 42 | +- if (checkInputOperandType(1, (int32_t)OperandType::FLOAT32) || |
| 43 | +- checkInputOperandType(1, (int32_t)OperandType::FLOAT16)) { |
| 44 | ++ if (checkInputOperandType(1, (int32_t)OperandType::FLOAT32)) { |
| 45 | + // In tensorflow lite, resizing by size is supported. Scaling factors are |
| 46 | + // calculated based on output shape. |
| 47 | + attrs.shape_calculation_mode = ngraph::op::v4::Interpolate::ShapeCalcMode::sizes; |
| 48 | +@@ -86,6 +73,14 @@ std::shared_ptr<ngraph::Node> ResizeBilinear::createNode() { |
| 49 | + // integer |
| 50 | + width_scale = (float)out_width / (float)input_width; |
| 51 | + height_scale = (float)out_height / (float)input_height; |
| 52 | ++ } else if (checkInputOperandType(1, (int32_t)OperandType::FLOAT16)) { |
| 53 | ++ attrs.shape_calculation_mode = ngraph::op::v4::Interpolate::ShapeCalcMode::sizes; |
| 54 | ++ width_scale = sModelInfo->ParseOperationInput<_Float16>(mNnapiOperationIndex, 1); |
| 55 | ++ height_scale = sModelInfo->ParseOperationInput<_Float16>(mNnapiOperationIndex, 2); |
| 56 | ++ out_width = (int)(input_width * width_scale); |
| 57 | ++ out_height = (int)(input_height * height_scale); |
| 58 | ++ width_scale = (float)out_width / (float)input_width; |
| 59 | ++ height_scale = (float)out_height / (float)input_height; |
| 60 | + } else if (checkInputOperandType(1, (int32_t)OperandType::INT32)) { |
| 61 | + attrs.shape_calculation_mode = ngraph::op::v4::Interpolate::ShapeCalcMode::sizes; |
| 62 | + out_width = sModelInfo->ParseOperationInput<int>(mNnapiOperationIndex, 1); |
| 63 | +diff --git a/ngraph_creator/operations/src/ResizeNearestNeighbor.cpp b/ngraph_creator/operations/src/ResizeNearestNeighbor.cpp |
| 64 | +index 23cb1dd3ff1e..a8eecfc03b9b 100644 |
| 65 | +--- a/ngraph_creator/operations/src/ResizeNearestNeighbor.cpp |
| 66 | ++++ b/ngraph_creator/operations/src/ResizeNearestNeighbor.cpp |
| 67 | +@@ -11,18 +11,6 @@ ResizeNearestNeighbor::ResizeNearestNeighbor(int operationIndex) : OperationsBas |
| 68 | + } |
| 69 | + |
| 70 | + bool ResizeNearestNeighbor::validate() { |
| 71 | +- // TODO Add FLOAT16 check when VPUX plugin is supported |
| 72 | +- if (!checkOutputOperandType(0, (int32_t)OperandType::TENSOR_FLOAT32) && |
| 73 | +- !checkOutputOperandType(0, (int32_t)OperandType::TENSOR_QUANT8_ASYMM)) { |
| 74 | +- ALOGE("%s check for output types failed", __func__); |
| 75 | +- return false; |
| 76 | +- } |
| 77 | +- |
| 78 | +- if (!checkInputOperandType(0, (int32_t)OperandType::TENSOR_FLOAT32) && |
| 79 | +- !checkInputOperandType(0, (int32_t)OperandType::TENSOR_QUANT8_ASYMM)) { |
| 80 | +- return false; |
| 81 | +- } |
| 82 | +- |
| 83 | + const auto& inputDimensionsSize = getInputOperandDimensions(0).size(); |
| 84 | + if (inputDimensionsSize != 4) { |
| 85 | + ALOGE("%s Invalid dimensions size for input(%lu)", __func__, inputDimensionsSize); |
| 86 | +@@ -73,8 +61,7 @@ std::shared_ptr<ngraph::Node> ResizeNearestNeighbor::createNode() { |
| 87 | + |
| 88 | + if (!useNchw) inputNode = transpose(NHWC_NCHW, inputNode); |
| 89 | + // FLOAT16 type check added for future when VPUX plugin support is added |
| 90 | +- if (checkInputOperandType(1, (int32_t)OperandType::FLOAT32) || |
| 91 | +- checkInputOperandType(1, (int32_t)OperandType::FLOAT16)) { |
| 92 | ++ if (checkInputOperandType(1, (int32_t)OperandType::FLOAT32)) { |
| 93 | + // In tensorflow lite, resizing by size is supported. Scaling factors are |
| 94 | + // calculated based on output shape. |
| 95 | + attrs.shape_calculation_mode = ngraph::op::v4::Interpolate::ShapeCalcMode::sizes; |
| 96 | +@@ -86,6 +73,14 @@ std::shared_ptr<ngraph::Node> ResizeNearestNeighbor::createNode() { |
| 97 | + // integer |
| 98 | + width_scale = (float)out_width / (float)input_width; |
| 99 | + height_scale = (float)out_height / (float)input_height; |
| 100 | ++ } else if (checkInputOperandType(1, (int32_t)OperandType::FLOAT16)) { |
| 101 | ++ attrs.shape_calculation_mode = ngraph::op::v4::Interpolate::ShapeCalcMode::sizes; |
| 102 | ++ width_scale = sModelInfo->ParseOperationInput<_Float16>(mNnapiOperationIndex, 1); |
| 103 | ++ height_scale = sModelInfo->ParseOperationInput<_Float16>(mNnapiOperationIndex, 2); |
| 104 | ++ out_width = (int)(input_width * width_scale); |
| 105 | ++ out_height = (int)(input_height * height_scale); |
| 106 | ++ width_scale = (float)out_width / (float)input_width; |
| 107 | ++ height_scale = (float)out_height / (float)input_height; |
| 108 | + } else if (checkInputOperandType(1, (int32_t)OperandType::INT32)) { |
| 109 | + attrs.shape_calculation_mode = ngraph::op::v4::Interpolate::ShapeCalcMode::sizes; |
| 110 | + out_width = sModelInfo->ParseOperationInput<int>(mNnapiOperationIndex, 1); |
| 111 | +-- |
| 112 | +2.25.1 |
| 113 | + |
0 commit comments