* Refactored infer function and function supported_attrs for the layer Interpolate. * Small change. * Deleted unneeded checks in transformations ResizeToInterpolate2D and ResizeToInterpolate3D. * Small fix in the extractor of ONNX Resize. * Now the extractor of TF ResizeBilinear generates Interpolate-1 again, because 'axis' in final version of Interpolate-4 specification is an input but is not attribute. * Now the extractor of TF ResizeNearest generates Interpolate-1 again, because 'axis' in final version of Interpolate-4 specification is an input but is not attribute. * Added static method get_axis into class Interpolate. * Refactored class CanBeFused in the transformation InterpolateSequenceToInterpolate. * Fixed transformation InterpolateSequenceToInterpolate according to the last version of the specification of Interpolate-4. * Started to write support of Interpolate-4 in the transformation InterpolateWithConcat. * Added support for Interpolate-4 into the transformation InterpolateWithConcat. * Added support for Interpolate-4 into the transformation InterpolateConcat. * Added support for Interpolate-4 into the transformation InterpolateReshapeWA. * Added support for Interpolate-4 into the transformation InterpolateTranspose. * Started to add test for opset4 case of the transformation InterpolateSequenceToInterpolate. * Added test for InterpolateSequenceToInterpolate (test_2d_interpolate_sequence_1_opset4_case). * Added test for InterpolateSequenceToInterpolate (test_2d_interpolate_sequence_4_opset4_case). * Added another test for InterpolateSequenceToInterpolate (test_2d_interpolate_sequence_5_opset4_case). * Added another test for InterpolateSequenceToInterpolate (test_3d_interpolate_sequence_1_opset4_case). * Finished addition of tests for opset4 case of InterpolateSequenceToInterpolate. * Small change. * Now opset is only opset1 or opset4 in the transformation InterpolateTranspose. * Small fixes in transformations ResizeToInterpolate2D and ResizeToInterpolate3D. * Deleted reading of unused ONNX attributes. * Fixed docstring of the transformation InterpolateV1ToInterpolateV4. * Added node name in assert about axes input. * Fixes in the definition of the operation ONNXResize11. * Now Interpolate-4 cannot have 'extension' as opset. * Now the transformation InterpolateV1ToInterpolateV4 uses find_and_replace_pattern but not replace_sub_graph. * Fixed tests for transformations InterpolateReshapeWA and InterpolateConcat. * Fixed some tests. * Rewritten operation Interpolate-4 class according to new variant of documentation. * Some fixes in ONNXResize11 operation class. * Now the transformation ONNXResize11ToInterpolate generates Interpolate-4 with 4 inputs. * Now the transformation UpsampleToResample generates Interpolate-4 with 4 inputs. * Now the transformation NearestNeighborUpsampling generates Interpolate-4 with 4 inputs. * Now transformations ResizeToInterpolate2D and ResizeToInterpolate3D generate Interpolate-4 with 4 inputs. * Now the transformation SplitConcatPairToInterpolate generates Interpolate-4 with 4 inputs. * Now the transformation UnsqueezeTileReshapeBlockToInterpolate generates Interpolate-4 with 4 inputs. * Now the transformation InterpolateV1ToInterpolateV4 generates Interpolate-4 with 4 inputs. * Some fixes. * Fixed the transformation InterpolateSequenceToInterpolate according to new variant of Interpolate-4 specification. * Fixed typos. * Added shape_calculation_mode to supported_attrs. * Small fixes. * Added operation ONNXResize10 and the transformation ONNXResize10ToInterpolate4. * Fixed function correct_scales_using_dst_shape. * Some fixes in InterpolateSequenceToInterpolate. * Fixed bug in the method __call__ of the class CanBeFused: now self.accumulated_axes is correctly cleared in all cases. * Small change. * Fixed tests for the transformation SplitConcatPairToInterpolate. * Now transformations InterpolateWithConcat, InterpolateReshapeWA, InterpolateConcat support Interpolate-4. * Fixed the transformation InterpolateTranspose for the case of Interpolate-4. * Written the back transformation InterpolateV4AxesCorrection to convert 'axes' input of Interpolate-4 from NHWC to NCHW layout. * Added PermuteInput in Interpolate-4 infer. * Fixed typos. * Deleted the transformation InterpolateAxesCorrection. * Now Interpolate-4 permutes axis, not shape in input port 3. * Small fix. * Some fix. * Fixed bug in the transformation UpsampleToResample. * Added some debug prints. * Added more debug prints. * Now ONNX Upsample-9 operation is read as ONNXResize10. * Small fix. * Small fixes. * Fixed tests for the transformation SplitConcatPairToInterpolate. * Deleted debug prints. * Deleted some debug prints. * Fixes in the transformation UnsqueezeTileReshapeBlockToInterpolate and its tests. * Small fix in the transformation InterpolateSequenceToInterpolate. * Started to write nGraph transformation to convert Interpolate-1 to Interpolate-4. * Deleted redundant files. * Small fixes. * Small fix. * Written draft of the transformation Interpolate-1 -> Interpolate-4. * Small fix. * Now ONNX Importer reads Resize-10 as Interpolate-4. * Fixes in the test onnx_model_resize10_import_only. * Small fix in the test for the conversion Interpolate-1 -> Interpolate-4. * Small fixes. * Fixed NGraphReaderTests for Interpolate. * Some fixes. * Deleted class for Resample operation. * Fix in the transformation NearestNeighborUpsampling: fixed precision of the input 'scales' of generated Interpolate-4. * Fixed typo. * Now the TF operations ResizeBilinear is readed as internal MO operation TFResizeBilinear. This internal operation is converted into Interpolate-4. * Small fix in BOM-file. * Added checks of existence of attributes of TF ResizeBilinear operation. * Small fixes in the conversion of the internal MO operation TFResizeBilinear to Interpolate-4. * Small fixes. * Small fixes. * Now the transformation ONNXResize10ToInterpolateV4 calculates sizes input as input_shape * (scales + epsilon). * Added the internal MO operation TFResizeNearestNeighbor. * Fixes in the transformation SplitConcatPairToInterpolate and its tests. * Fixes in the transformation UnsqueezeTileReshapeBlockToInterpolate and its tests. * Written the transformation that converts the internal operation TFResizeNearestNeighbor into Interpolate-4. * Now MO reads the TF operation ResizeNearestNeighbor as the internal MO operation TFResizeNearestNeighbor. * Small fix. * Now the specification of Interpolate-4 clarifies that the mode linear_onnx supports only 2D or 4D input tensors. * Small fix. * Some fixes. * Moved the transformation ONNXResize10ToInterpolateV4 to the front stage. * Deleted infer function and function supported_attrs for ONNXResize10 operation. * Deleted supported_attrs() for TFResizeBilinear and TFResizeNearestNeighbor. * Some fixes. * Fixes in the shape infer function of the nGraph operation Interpolate-4. Now 'axes' input can be non-constant. In the such case, all elements of the output shape are Dimension::dynamic(). * Deleted corner cases processing in transformations TFResizeBilinearToInterpolateV4 and TFResizeNearestNeighborToInterpolateV4. * Rewritten the function replace_resize_bilinear. * Written inner MO operation TFResize that covers TF operations ResizeBilinear and ResizeNearestNeighbor. * Now TF operations ResizeBilinear and ResizeNearestNeighbor are read as an internal operation TFResize in MO. Transformations TFResizeNearestNeighborToInterpolateV4 and TFResizeBilinearToInterpolateV4 are fused into one transformation TFResizeToInterpolateV4. * Some changes in the shape infer function of nGraph op Interpolate-4. * Small fix. * Some changes. * The transformation TFResizeToInterpolateV4 is moved to the front stage. * Deleted redundant assert. * Deleted transformations ResizeToInterpolate2D and ResizeToInterpolate3D. * Some renaming. * Small change. * Deleted .copy() in the shape infer function of the internal operation TFResize. * Small fix. * Small fixes. * Added comment about the case when the input 'axes' of Interpolate-4 is non-constant. * Written test for Interpolate-4 shape infer, for the case when the input 'axes' is non-constant and shape_calculation_mode = scales. * Some fixes. * Small fixes. * Small fix. * Added yet another test for the case of non-constant 'axes' input of Interpolate-4 (when shape_calculation_mode = sizes). * Added some comment. * Small fix. * Reverted changes for InterpolateWithConcat. * Added type checks for all inputs of nGraph operation Interpolate-4. * Added u32 and u64 to supported element types of sizes and axes inputs of nGraph operation Interpolate-4. * Fixed some functional tests. * Some changes. * Added helper function float32_array. * Now the MO transformation InterpolateV1ToInterpolate preserves names of layers. * Small fix. * Small fix. * Reverted some change. * Small fixes. * Small fix. * Small fix. * Small fix. * Small fix. * Reverted changes in the nGraph reader tests for Interpolate-1. * Some revert. * Fixed some copyright year.
403 lines
13 KiB
C++
403 lines
13 KiB
C++
// Copyright (C) 2018-2020 Intel Corporation
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
|
|
#include <string>
|
|
#include "ngraph_reader_tests.hpp"
|
|
TEST_F(NGraphReaderTests, ReadInterpolateNetwork) {
|
|
std::string model = R"V0G0N(
|
|
<net name="Network" version="10">
|
|
<layers>
|
|
<layer id="0" name="data" type="Parameter" precision="FP32" version="opset1">
|
|
<data element_type="f32" shape="1,2,48,80"/>
|
|
<output>
|
|
<port id="0" precision="FP32">
|
|
<dim>1</dim>
|
|
<dim>2</dim>
|
|
<dim>48</dim>
|
|
<dim>80</dim>
|
|
</port>
|
|
</output>
|
|
</layer>
|
|
<layer id="1" name="const1" type="Const" precision="I64" version="opset1">
|
|
<data element_type="i64" offset="0" shape="2" size="16"/>
|
|
<output>
|
|
<port id="1" precision="I64">
|
|
<dim>2</dim>
|
|
</port>
|
|
</output>
|
|
</layer>
|
|
<layer id="3" name="interpolate" type="Interpolate" precision="FP32" version="opset1">
|
|
<data axes="2,3" align_corners="0" pads_begin="0" pads_end="0" mode="linear"/>
|
|
<input>
|
|
<port id="0">
|
|
<dim>1</dim>
|
|
<dim>2</dim>
|
|
<dim>48</dim>
|
|
<dim>80</dim>
|
|
</port>
|
|
<port id="1">
|
|
<dim>2</dim>
|
|
</port>
|
|
</input>
|
|
<output>
|
|
<port id="3" precision="FP32">
|
|
<dim>1</dim>
|
|
<dim>2</dim>
|
|
<dim>50</dim>
|
|
<dim>60</dim>
|
|
</port>
|
|
</output>
|
|
</layer>
|
|
<layer name="output" type="Result" id="2" precision="FP32" version="opset1">
|
|
<input>
|
|
<port id="0">
|
|
<dim>1</dim>
|
|
<dim>2</dim>
|
|
<dim>50</dim>
|
|
<dim>60</dim>
|
|
</port>
|
|
</input>
|
|
</layer>
|
|
</layers>
|
|
<edges>
|
|
<edge from-layer="0" from-port="0" to-layer="3" to-port="0"/>
|
|
<edge from-layer="1" from-port="1" to-layer="3" to-port="1"/>
|
|
<edge from-layer="3" from-port="3" to-layer="2" to-port="0"/>
|
|
</edges>
|
|
</net>
|
|
)V0G0N";
|
|
std::string modelV5 = R"V0G0N(
|
|
<net name="Network" version="5" precision="FP32" batch="1">
|
|
<layers>
|
|
<layer id="0" name="data" precision="FP32" type="Input">
|
|
<output>
|
|
<port id="0">
|
|
<dim>1</dim>
|
|
<dim>2</dim>
|
|
<dim>48</dim>
|
|
<dim>80</dim>
|
|
</port>
|
|
</output>
|
|
</layer>
|
|
<layer id="1" name="interpolate" precision="FP32" type="Interp">
|
|
<data align_corners="0" pad_beg="0" pad_end="0" mode="linear" width="60" height="50"/>
|
|
<input>
|
|
<port id="0">
|
|
<dim>1</dim>
|
|
<dim>2</dim>
|
|
<dim>48</dim>
|
|
<dim>80</dim>
|
|
</port>
|
|
</input>
|
|
<output>
|
|
<port id="1">
|
|
<dim>1</dim>
|
|
<dim>2</dim>
|
|
<dim>50</dim>
|
|
<dim>60</dim>
|
|
</port>
|
|
</output>
|
|
</layer>
|
|
</layers>
|
|
<edges>
|
|
<edge from-layer="0" from-port="0" to-layer="1" to-port="0"/>
|
|
</edges>
|
|
</net>
|
|
)V0G0N";
|
|
compareIRs(model, modelV5, 16, [](Blob::Ptr& weights) {
|
|
auto *data = weights->buffer().as<int64_t *>();
|
|
data[0] = 50;
|
|
data[1] = 60;
|
|
});
|
|
}
|
|
TEST_F(NGraphReaderTests, ReadInterpolate2Network) {
|
|
std::string model = R"V0G0N(
|
|
<net name="Network" version="10">
|
|
<layers>
|
|
<layer id="0" name="data" type="Parameter" precision="FP32" version="opset1">
|
|
<data element_type="f32" shape="1,2,48,80"/>
|
|
<output>
|
|
<port id="0" precision="FP32">
|
|
<dim>1</dim>
|
|
<dim>2</dim>
|
|
<dim>48</dim>
|
|
<dim>80</dim>
|
|
</port>
|
|
</output>
|
|
</layer>
|
|
<layer id="1" name="const1" type="Const" precision="I64" version="opset1">
|
|
<data element_type="i64" offset="0" shape="4" size="32"/>
|
|
<output>
|
|
<port id="1" precision="I64">
|
|
<dim>4</dim>
|
|
</port>
|
|
</output>
|
|
</layer>
|
|
<layer id="3" name="interpolate" type="Interpolate" precision="FP32" version="opset1">
|
|
<data axes="0,2,1,3" align_corners="0" pads_begin="0" pads_end="0" mode="linear"/>
|
|
<input>
|
|
<port id="0">
|
|
<dim>1</dim>
|
|
<dim>2</dim>
|
|
<dim>48</dim>
|
|
<dim>80</dim>
|
|
</port>
|
|
<port id="1">
|
|
<dim>4</dim>
|
|
</port>
|
|
</input>
|
|
<output>
|
|
<port id="3" precision="FP32">
|
|
<dim>1</dim>
|
|
<dim>2</dim>
|
|
<dim>50</dim>
|
|
<dim>60</dim>
|
|
</port>
|
|
</output>
|
|
</layer>
|
|
<layer name="output" type="Result" id="2" precision="FP32" version="opset1">
|
|
<input>
|
|
<port id="0">
|
|
<dim>1</dim>
|
|
<dim>2</dim>
|
|
<dim>50</dim>
|
|
<dim>60</dim>
|
|
</port>
|
|
</input>
|
|
</layer>
|
|
</layers>
|
|
<edges>
|
|
<edge from-layer="0" from-port="0" to-layer="3" to-port="0"/>
|
|
<edge from-layer="1" from-port="1" to-layer="3" to-port="1"/>
|
|
<edge from-layer="3" from-port="3" to-layer="2" to-port="0"/>
|
|
</edges>
|
|
</net>
|
|
)V0G0N";
|
|
std::string modelV5 = R"V0G0N(
|
|
<net name="Network" version="5" precision="FP32" batch="1">
|
|
<layers>
|
|
<layer id="0" name="data" precision="FP32" type="Input">
|
|
<output>
|
|
<port id="0">
|
|
<dim>1</dim>
|
|
<dim>2</dim>
|
|
<dim>48</dim>
|
|
<dim>80</dim>
|
|
</port>
|
|
</output>
|
|
</layer>
|
|
<layer id="1" name="interpolate" precision="FP32" type="Interp">
|
|
<data align_corners="0" pad_beg="0" pad_end="0" mode="linear" width="60" height="50"/>
|
|
<input>
|
|
<port id="0">
|
|
<dim>1</dim>
|
|
<dim>2</dim>
|
|
<dim>48</dim>
|
|
<dim>80</dim>
|
|
</port>
|
|
</input>
|
|
<output>
|
|
<port id="1">
|
|
<dim>1</dim>
|
|
<dim>2</dim>
|
|
<dim>50</dim>
|
|
<dim>60</dim>
|
|
</port>
|
|
</output>
|
|
</layer>
|
|
</layers>
|
|
<edges>
|
|
<edge from-layer="0" from-port="0" to-layer="1" to-port="0"/>
|
|
</edges>
|
|
</net>
|
|
)V0G0N";
|
|
compareIRs(model, modelV5, 32, [](Blob::Ptr& weights) {
|
|
auto *data = weights->buffer().as<int64_t *>();
|
|
data[0] = 1;
|
|
data[1] = 2;
|
|
data[2] = 50;
|
|
data[3] = 60;
|
|
});
|
|
}
|
|
|
|
TEST_F(NGraphReaderTests, ReadInterpolate4Network) {
|
|
std::string model = R"V0G0N(
|
|
<net name="Network" version="10">
|
|
<layers>
|
|
<layer id="0" name="data" type="Parameter" precision="FP32" version="opset1">
|
|
<data element_type="f32" shape="1,2,300,300"/>
|
|
<output>
|
|
<port id="0" precision="FP32">
|
|
<dim>1</dim>
|
|
<dim>2</dim>
|
|
<dim>300</dim>
|
|
<dim>300</dim>
|
|
</port>
|
|
</output>
|
|
</layer>
|
|
<layer id="1" name="output_shape" type="Const" precision="I32" version="opset1">
|
|
<data element_type="i32" offset="0" shape="2" size="8"/>
|
|
<output>
|
|
<port id="1" precision="I32">
|
|
<dim>2</dim>
|
|
</port>
|
|
</output>
|
|
</layer>
|
|
<layer id="2" name="scales" type="Const" precision="FP32" version="opset1">
|
|
<data element_type="f32" offset="8" shape="2" size="8"/>
|
|
<output>
|
|
<port id="1" precision="FP32">
|
|
<dim>2</dim>
|
|
</port>
|
|
</output>
|
|
</layer>
|
|
<layer id="3" name="axes" type="Const" precision="I32" version="opset1">
|
|
<data element_type="i32" offset="16" shape="2" size="8"/>
|
|
<output>
|
|
<port id="1" precision="I32">
|
|
<dim>2</dim>
|
|
</port>
|
|
</output>
|
|
</layer>
|
|
<layer id="4" name="interpolate" type="Interpolate" precision="FP32" version="opset4">
|
|
<data antialias="0" coordinate_transformation_mode="asymmetric" cube_coeff="123" mode="nearest" nearest_mode="floor" pads_begin="2,3,4,5" pads_end="6,7,8,9" shape_calculation_mode="sizes"/>
|
|
<input>
|
|
<port id="0">
|
|
<dim>1</dim>
|
|
<dim>2</dim>
|
|
<dim>300</dim>
|
|
<dim>300</dim>
|
|
</port>
|
|
<port id="1">
|
|
<dim>2</dim>
|
|
</port>
|
|
<port id="2">
|
|
<dim>2</dim>
|
|
</port>
|
|
<port id="3">
|
|
<dim>2</dim>
|
|
</port>
|
|
</input>
|
|
<output>
|
|
<port id="4" precision="FP32">
|
|
<dim>9</dim>
|
|
<dim>12</dim>
|
|
<dim>600</dim>
|
|
<dim>900</dim>
|
|
</port>
|
|
</output>
|
|
</layer>
|
|
<layer name="output" type="Result" id="5" precision="FP32" version="opset1">
|
|
<input>
|
|
<port id="0">
|
|
<dim>9</dim>
|
|
<dim>12</dim>
|
|
<dim>600</dim>
|
|
<dim>900</dim>
|
|
</port>
|
|
</input>
|
|
</layer>
|
|
</layers>
|
|
<edges>
|
|
<edge from-layer="0" from-port="0" to-layer="4" to-port="0"/>
|
|
<edge from-layer="1" from-port="1" to-layer="4" to-port="1"/>
|
|
<edge from-layer="2" from-port="1" to-layer="4" to-port="2"/>
|
|
<edge from-layer="3" from-port="1" to-layer="4" to-port="3"/>
|
|
<edge from-layer="4" from-port="4" to-layer="5" to-port="0"/>
|
|
</edges>
|
|
</net>
|
|
)V0G0N";
|
|
std::string modelV5 = R"V0G0N(
|
|
<net name="Network" version="5" precision="FP32" batch="1">
|
|
<layers>
|
|
<layer id="0" name="data" precision="FP32" type="Input">
|
|
<output>
|
|
<port id="0">
|
|
<dim>1</dim>
|
|
<dim>2</dim>
|
|
<dim>300</dim>
|
|
<dim>300</dim>
|
|
</port>
|
|
</output>
|
|
</layer>
|
|
<layer id="1" name="output_shape" precision="I32" type="Const">
|
|
<output>
|
|
<port id="0">
|
|
<dim>2</dim>
|
|
</port>
|
|
</output>
|
|
<blobs>
|
|
<custom offset="0" size="8"/>
|
|
</blobs>
|
|
</layer>
|
|
<layer id="2" name="scales" precision="FP32" type="Const">
|
|
<output>
|
|
<port id="0">
|
|
<dim>2</dim>
|
|
</port>
|
|
</output>
|
|
<blobs>
|
|
<custom offset="8" size="8"/>
|
|
</blobs>
|
|
</layer>
|
|
<layer id="3" name="axes" precision="I32" type="Const">
|
|
<output>
|
|
<port id="0">
|
|
<dim>2</dim>
|
|
</port>
|
|
</output>
|
|
<blobs>
|
|
<custom offset="16" size="8"/>
|
|
</blobs>
|
|
</layer>
|
|
<layer id="4" name="interpolate" precision="FP32" type="Interpolate">
|
|
<data antialias="False" coordinate_transformation_mode="asymmetric" cube_coeff="123" mode="nearest" nearest_mode="floor" pads_begin="2,3,4,5" pads_end="6,7,8,9" shape_calculation_mode="sizes"/>
|
|
<input>
|
|
<port id="0">
|
|
<dim>1</dim>
|
|
<dim>2</dim>
|
|
<dim>300</dim>
|
|
<dim>300</dim>
|
|
</port>
|
|
<port id="1">
|
|
<dim>2</dim>
|
|
</port>
|
|
<port id="2">
|
|
<dim>2</dim>
|
|
</port>
|
|
<port id="3">
|
|
<dim>2</dim>
|
|
</port>
|
|
</input>
|
|
<output>
|
|
<port id="4" precision="FP32">
|
|
<dim>9</dim>
|
|
<dim>12</dim>
|
|
<dim>600</dim>
|
|
<dim>900</dim>
|
|
</port>
|
|
</output>
|
|
</layer>
|
|
</layers>
|
|
<edges>
|
|
<edge from-layer="0" from-port="0" to-layer="4" to-port="0"/>
|
|
<edge from-layer="1" from-port="0" to-layer="4" to-port="1"/>
|
|
<edge from-layer="2" from-port="0" to-layer="4" to-port="2"/>
|
|
<edge from-layer="3" from-port="0" to-layer="4" to-port="3"/>
|
|
</edges>
|
|
</net>
|
|
)V0G0N";
|
|
compareIRs(model, modelV5, 24, [](Blob::Ptr& weights) {
|
|
auto *data = weights->buffer().as<int*>();
|
|
data[0] = 600;
|
|
data[1] = 900;
|
|
data[4] = 2;
|
|
data[5] = 3;
|
|
|
|
auto *fdata = weights->buffer().as<float*>();
|
|
fdata[2] = 2.0;
|
|
fdata[3] = 2.0;
|
|
});
|
|
}
|