Files
openvino/ngraph/test/util/test_case.hpp
Vladimir Gavrilov 7a74792ac4 Intepolate-4 nGraph operation (#1412)
* Fixed prototype of evaluate method.

* Rewritten Interpolate-4 ctors (added argument output_shape). Corrected tests.

* Fixed typo.

* Fixed number of args of make_shared in op::v4::Interpolate::clone_with_new_inputs.

* Fixes in Interpolate-4 tests.

* Now ONNX Upsample-1 is readed as Interpolate-4 with 4 inputs.

* Code style fixes.

* Some fixes in Interpolate-4 layer test.

* Now ONNX Upsample-9 is readed as Interpolate-4 with 4 inputs.

* Small fixes.

* Some changes.

* Fixed processing of 'scales' input in evaluation of Interpolate-4: now 'scales' contains scales only from 'axes'.

* Fixes in documentation.

* Now reference implementation of Interpolate-4 is rewritten for using 3 required inputs.

* Some code style fixes.

* Small fix.

* Started to write tests for method evaluate() of Interpolate-4.

* Continued to write tests for evaluate() of Interpolate-4.

* Some fixes.

* Some additions.

* Written draft of tests for 'cubic' mode with using scales.

* Some changes.

* Started to write tests for 'nearest' mode.

* Started to write tests for 'linear_onnx' mode.

* Some changes.

* Small fixes.

* Added setup of output type.

* Small addition.

* Added debug print into Interpolate-4 evaluate.

* Now in Interpolate-4 evaluation tests 3 inputs of Interpolate are Constants.

* Small changes.

* Added some debug print.

* Added more debug print.

* Some fixes.

* Now 4th argument of runtime::interpolate has type std::vector<int64_t>.

* Added checks for result of calculations.

* Added another expected values vector for the mode 'cubic'.

* Temporarily commented result value checks  for the cubic mode.

* Written tests for 'nearest' mode.

* Some reorganization.

* Written tests for 'linear_onnx' mode.

* Fixed padding loop.

* Fixed docs for 'linear_onnx' mode.

* Written tests for 'cubic' mode.

* Deleted debug print.

* Fixed code style.

* Enabled CPU layer tests for Interpolate-4.

* Reverted changes of this file.

* Now ONNX importer reads Resize-1 as Interpolate-4 with 4 inputs.

* Now ONNX importer reads Resize-11 as Interpolate-4 with 4 inputs.

* Small fixes.

* Fixed docs.

* Added small epsilon in the shape calculation in the function op::v4::Interpolate::infer_using_scales.

* Small fix.

* Reduced size of the template function eval().

* Now the 'nearest' mode is rewritten to CoordinateTransfom instead of NDim* classes

* Now the 'cubic' mode is rewritten to use CoordinateTransformation instead of NDim classes.

* Started to rewrite 'linear' mode using CoordinateTransform.

* Started to write helper class.

* Small fix.

* Small changes.

* Some fix.

* Fixed typo.

* Now the preamble of 'linear_onnx' mode implementation is a method of helper class.

* Now the function clip_coord is the method of helper class, and the mode 'linear' uses CoordinateTransform instead of NDim classes.

* Deleted NDim classes.

* Some fixes.

* Some refactoring.

* Some refactoring: now inner calculation of 'linear' is in helper class.

* Moved reference implementation of Interpolate-4 into library with reference implementations.

* Small fix.

* Deleted commented tests.

* Code stile fixes.

* Deleted redundant type prop tests for Interpolate-4.

* Documentation fixes.

* Disabled IE_CPU tests for ONNX Resize: Interpolate-4 is not implemented in plugins.

* Temporarily disabled some ONNX tests.

* Some refactoring: deleted redundant attributes of InterpolateEval class.

* Small fix.

* Added NGRAPH_RTTI_DECLARATION and NGRAPH_RTTI_DEFINITION.

* Added debug print to 'cubic' mode calculation.

* Some deletions.

* Small fix.

* Fixed typos.

* Added another debug print.

* Now indices_shape is constructed from std::vector<std::size_t>(num_of_axes, 4) again.

* Fixed CMakeLists.txt.

* Small fix.

* Added more debug print.

* Fixed typo.

* Fixed calculation of the first argument of helper.clip_coord in the inner loop of cubic_func.

* Some code style fixes.

* Alphabetically sorted operations of opset4.

* Deleted constant cannot_define_axes.

* Used std::iota instead of loop.

* Renamed structure InfoToCallReference.

* Now void op::v4::Interpolate::validate_and_infer_types() checks an element type of an input tensor.

* Code style fix.

* Changes in reading of ONNX Resize and Upsample: we generate Interpolate-4 without 'axes' input.

* Now bodies of functions evaluate_interpolate_v4() and inline bool evaluate() are moved in the method bool op::v4::Interpolate::evaluate.

* Fixes in example of the documentation of Interpolate-4.

* Fixed typos.

* Small fix.

* Some fixes.

* Deleted some type aliases.

* Uncommented a test for 'cubic' mode.

* Small code style fix in bool op::v4::Interpolate::evaluate.

* Uncommented more test for Interpolate-4 reference implementation.

* Added more debug print.

* Some changes.

* Uncommented all tests for Interpolate-4 evaluate().

* Deleted debug print.

* Deleted 'simple' mode from the map nearest_mode_map.

* Code style fixes.

* Disabled some CPU tests.

* Some fixes.

* Small fixes.

* Some fixes.

* Fixed typo.

* Fixed typo.

* Small change.

* Fixed some typos.

* Fixed some typos.

* Fix in operator() of the class GetOriginalCoordinate.

* Disabled some CPU tests.

* Small changes.

* Deleted template function from resize.cpp.

* Code style fixes.

* Refactored the method op::v4::Interpolate::evaluate.

* Added documentation for infer_using_scales() and infer_using_shapes().

* Added documentation for classes GetNearestPixel and GetOriginalCoordinate.

* Small fixes.

* Some code style fixes.

* Small fixes.

* Some changes.

* Added NGRAPH_SUPPRESS_DEPRECATED_START and NGRAPH_SUPPRESS_DEPRECATED_END for using v0::InterpolateAttrs; and using v0::Interpolate;

* Code style fix.

* Enabled ONNX import only tests for Resize-10, Upsample-8, Upsample-9.

* Fixed element type for scales_const. Fixed targetShapes and pads in single layer tests.

* Small changes.

* Added conversion from NGRAPH to CNNLayer.

* Added documentation for the class InterpolateEval.

* Now 'nearest' mode has special tests in cpu single layer tests.

* Small changes.

* Fixes in cpu single layer tests.

* Temporarily commented Interpolate-4 in ConvertFunctionToCNNNetworkTests.

* Added some docs.

* Enabled some tests for Resize-11.

* Added test.

* Corrected expected values in the resize_downsample_scales_align_corners case.

* Added more test for the 'cubic' mode.

* Added more test for linear_onnx mode.

* Deleted debug print for linear_onnx mode.

* Deleted debug prints. Added yet another test for 'nearest' mode.

* Fixes for import of ONNX Resize-10 and Upsamples.

* Applyed Evgeny Lazarev fix for Interpolate-4 infer function.

* Code style fixes.

* Some tests were deleted from unit_test.manifest file for INTERPRETER.

* Deleted test for downscale Resize-10: results of infer are correct, but comparison is not.

* Enabled test INTERPRETER.onnx_empty_initializers_handling.

* Some fixes.

* Added the method run_with_tolerance_as_fp() to the class TestCase and the method compare_results_with_tolerance_as_fp() to the class TestCaseEngine.

* Small fix.

* Small fix.

* Added yet another type_prop test.

* Disabled CPU test IE_CPU.onnx_empty_initializers_handling.

* Code style fixes.

* Enabled some ONNX tests.

* Some changes.

* Code style fix.

* Enabled test INTERPRETER.onnx_model_round.

* Disabled tests with behavior as behavior of INTERPRETER.onnx_resize11_scales_down_linear.

* Changed tolerance for test onnx_empty_initializers_handling.

* Changed tolerance in the test onnx_resize11_sizes_linear (otherwise this test is failed in MacOS). Disabled test INTERPRETER.onnx_resize11_sizes_nearest_asymmetric_floor, because this test failed in MacOS only.
2020-09-01 06:57:34 +03:00

210 lines
7.7 KiB
C++

//*****************************************************************************
// Copyright 2017-2020 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//*****************************************************************************
#pragma once
#include <utility>
#include "all_close.hpp"
#include "all_close_f.hpp"
#include "ngraph/function.hpp"
#include "ngraph/ngraph.hpp"
#include "test_tools.hpp"
#include "util/engine/engine_factory.hpp"
namespace ngraph
{
namespace test
{
template <typename Engine, TestCaseType tct = TestCaseType::STATIC>
class TestCase
{
public:
TestCase(const std::shared_ptr<Function>& function)
: m_function{function}
, m_engine{create_engine<Engine>(function, tct)}
{
}
template <typename T>
void add_input(const Shape& shape, const std::vector<T>& values)
{
const auto params = m_function->get_parameters();
NGRAPH_CHECK(m_input_index < params.size(),
"All function parameters already have inputs.");
const auto& input_pshape = params.at(m_input_index)->get_partial_shape();
NGRAPH_CHECK(input_pshape.compatible(shape),
"Provided input shape ",
shape,
" is not compatible with nGraph function's expected input shape ",
input_pshape,
" for input ",
m_input_index);
m_engine.template add_input<T>(shape, values);
++m_input_index;
}
template <typename T>
void add_input(const std::vector<T>& values)
{
const auto& input_pshape =
m_function->get_parameters().at(m_input_index)->get_partial_shape();
NGRAPH_CHECK(input_pshape.is_static(),
"Input number ",
m_input_index,
" in the tested graph has dynamic shape. You need to provide ",
"shape information when setting values for this input.");
add_input<T>(input_pshape.to_shape(), values);
}
template <typename T>
void add_multiple_inputs(const std::vector<std::vector<T>>& vector_of_values)
{
for (const auto& value : vector_of_values)
{
add_input<T>(value);
}
}
template <typename T>
void add_input_from_file(const Shape& shape,
const std::string& basepath,
const std::string& filename)
{
const auto filepath = ngraph::file_util::path_join(basepath, filename);
add_input_from_file<T>(shape, filepath);
}
template <typename T>
void add_input_from_file(const std::string& basepath, const std::string& filename)
{
const auto filepath = ngraph::file_util::path_join(basepath, filename);
add_input_from_file<T>(filepath);
}
template <typename T>
void add_input_from_file(const Shape& shape, const std::string& filepath)
{
const auto value = read_binary_file<T>(filepath);
add_input<T>(shape, value);
}
template <typename T>
void add_input_from_file(const std::string& filepath)
{
const auto value = read_binary_file<T>(filepath);
add_input<T>(value);
}
template <typename T>
void add_expected_output(const Shape& expected_shape, const std::vector<T>& values)
{
const auto results = m_function->get_results();
NGRAPH_CHECK(m_output_index < results.size(),
"All function results already have expected outputs.");
const auto& output_pshape = results.at(m_output_index)->get_output_partial_shape(0);
NGRAPH_CHECK(output_pshape.compatible(expected_shape),
"Provided expected output shape ",
expected_shape,
" is not compatible with nGraph function's output shape ",
output_pshape,
" for output ",
m_output_index);
m_engine.template add_expected_output<T>(expected_shape, values);
++m_output_index;
}
template <typename T>
void add_expected_output(const std::vector<T>& values)
{
const auto results = m_function->get_results();
NGRAPH_CHECK(m_output_index < results.size(),
"All function results already have expected outputs.");
const auto shape = results.at(m_output_index)->get_shape();
add_expected_output<T>(shape, values);
}
template <typename T>
void add_expected_output_from_file(const ngraph::Shape& expected_shape,
const std::string& basepath,
const std::string& filename)
{
const auto filepath = ngraph::file_util::path_join(basepath, filename);
add_expected_output_from_file<T>(expected_shape, filepath);
}
template <typename T>
void add_expected_output_from_file(const ngraph::Shape& expected_shape,
const std::string& filepath)
{
const auto values = read_binary_file<T>(filepath);
add_expected_output<T>(expected_shape, values);
}
void run(const size_t tolerance_bits = DEFAULT_FLOAT_TOLERANCE_BITS)
{
m_engine.infer();
const auto res = m_engine.compare_results(tolerance_bits);
if (res != testing::AssertionSuccess())
{
std::cout << res.message() << std::endl;
}
m_input_index = 0;
m_output_index = 0;
m_engine.reset();
EXPECT_TRUE(res);
}
void run_with_tolerance_as_fp(const float tolerance = 1.0e-5f)
{
m_engine.infer();
const auto res = m_engine.compare_results_with_tolerance_as_fp(tolerance);
if (res != testing::AssertionSuccess())
{
std::cout << res.message() << std::endl;
}
m_input_index = 0;
m_output_index = 0;
m_engine.reset();
EXPECT_TRUE(res);
}
private:
Engine m_engine;
std::shared_ptr<Function> m_function;
size_t m_input_index = 0;
size_t m_output_index = 0;
};
}
}