Revise PriorBox op (#6363)
* Use ngraph rtti macros * Check attribute count in visitor test case * Add priorBox class for SLT * Add priorBox SSLT * Add CPU SLT * moved type_prop tests to type_prop directory * Add backend tests * Add PriorBox to trusted ops list * infer first dimension of size 2
This commit is contained in:
committed by
GitHub
parent
07b0b4ea83
commit
b231b2b576
@@ -171,6 +171,7 @@ set(SRC
|
||||
type_prop/parameter.cpp
|
||||
type_prop/power.cpp
|
||||
type_prop/prelu.cpp
|
||||
type_prop/prior_box.cpp
|
||||
type_prop/proposal.cpp
|
||||
type_prop/psroi_pooling.cpp
|
||||
type_prop/range.cpp
|
||||
@@ -445,6 +446,7 @@ set(MULTI_TEST_SRC
|
||||
backend/parameter_as_output.in.cpp
|
||||
backend/power.in.cpp
|
||||
backend/prelu.in.cpp
|
||||
backend/prior_box.in.cpp
|
||||
backend/proposal.in.cpp
|
||||
backend/psroi_pooling.in.cpp
|
||||
backend/range.in.cpp
|
||||
|
||||
47
ngraph/test/backend/prior_box.in.cpp
Normal file
47
ngraph/test/backend/prior_box.in.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
// Copyright (C) 2018-2021 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "ngraph/ngraph.hpp"
|
||||
#include "ngraph/op/prior_box.hpp"
|
||||
|
||||
#include "util/engine/test_engines.hpp"
|
||||
#include "util/test_case.hpp"
|
||||
#include "util/test_control.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace ngraph;
|
||||
|
||||
static string s_manifest = "${MANIFEST}";
|
||||
using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME});
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, prior_box)
|
||||
{
|
||||
op::PriorBoxAttrs attrs;
|
||||
attrs.min_size = {2.0f};
|
||||
attrs.aspect_ratio = {1.5f};
|
||||
attrs.scale_all_sizes = false;
|
||||
|
||||
Shape layer_shape_shape{2};
|
||||
Shape image_shape_shape{2};
|
||||
vector<int64_t> layer_shape{2, 2};
|
||||
vector<int64_t> image_shape{10, 10};
|
||||
|
||||
auto LS = op::Constant::create(element::i64, layer_shape_shape, layer_shape);
|
||||
auto IS = op::Constant::create(element::i64, image_shape_shape, image_shape);
|
||||
auto f = make_shared<Function>(make_shared<op::PriorBox>(LS, IS, attrs), ParameterVector{});
|
||||
const auto exp_shape = Shape{2, 32};
|
||||
vector<float> out{-0.75, -0.75, 1.25, 1.25, -0.974745, -0.566497, 1.47474, 1.0665,
|
||||
-0.25, -0.75, 1.75, 1.25, -0.474745, -0.566497, 1.97474, 1.0665,
|
||||
-0.75, -0.25, 1.25, 1.75, -0.974745, -0.0664966, 1.47474, 1.5665,
|
||||
-0.25, -0.25, 1.75, 1.75, -0.474745, -0.0664966, 1.97474, 1.5665,
|
||||
0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1,
|
||||
0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1,
|
||||
0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1,
|
||||
0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1};
|
||||
|
||||
auto test_case = test::TestCase<TestEngine>(f);
|
||||
test_case.add_expected_output<float>(exp_shape, out);
|
||||
test_case.run_with_tolerance_as_fp(1.0e-5f);
|
||||
}
|
||||
51
ngraph/test/type_prop/prior_box.cpp
Normal file
51
ngraph/test/type_prop/prior_box.cpp
Normal file
@@ -0,0 +1,51 @@
|
||||
// Copyright (C) 2018-2021 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "ngraph/ngraph.hpp"
|
||||
#include "ngraph/op/prior_box.hpp"
|
||||
|
||||
using namespace ngraph;
|
||||
|
||||
TEST(type_prop, prior_box1)
|
||||
{
|
||||
op::PriorBoxAttrs attrs;
|
||||
attrs.min_size = {2.0f, 3.0f};
|
||||
attrs.aspect_ratio = {1.5f, 2.0f, 2.5f};
|
||||
attrs.scale_all_sizes = false;
|
||||
|
||||
auto layer_shape = op::Constant::create<int64_t>(element::i64, Shape{2}, {32, 32});
|
||||
auto image_shape = op::Constant::create<int64_t>(element::i64, Shape{2}, {300, 300});
|
||||
auto pb = std::make_shared<op::PriorBox>(layer_shape, image_shape, attrs);
|
||||
ASSERT_EQ(pb->get_shape(), (Shape{2, 20480}));
|
||||
}
|
||||
|
||||
TEST(type_prop, prior_box2)
|
||||
{
|
||||
op::PriorBoxAttrs attrs;
|
||||
attrs.min_size = {2.0f, 3.0f};
|
||||
attrs.aspect_ratio = {1.5f, 2.0f, 2.5f};
|
||||
attrs.flip = true;
|
||||
attrs.scale_all_sizes = false;
|
||||
|
||||
auto layer_shape = op::Constant::create<int64_t>(element::i64, Shape{2}, {32, 32});
|
||||
auto image_shape = op::Constant::create<int64_t>(element::i64, Shape{2}, {300, 300});
|
||||
auto pb = std::make_shared<op::PriorBox>(layer_shape, image_shape, attrs);
|
||||
ASSERT_EQ(pb->get_shape(), (Shape{2, 32768}));
|
||||
}
|
||||
|
||||
TEST(type_prop, prior_box3)
|
||||
{
|
||||
op::PriorBoxAttrs attrs;
|
||||
attrs.min_size = {256.0f};
|
||||
attrs.max_size = {315.0f};
|
||||
attrs.aspect_ratio = {2.0f};
|
||||
attrs.flip = true;
|
||||
|
||||
auto layer_shape = op::Constant::create<int64_t>(element::i64, Shape{2}, {1, 1});
|
||||
auto image_shape = op::Constant::create<int64_t>(element::i64, Shape{2}, {300, 300});
|
||||
auto pb = std::make_shared<op::PriorBox>(layer_shape, image_shape, attrs);
|
||||
ASSERT_EQ(pb->get_shape(), (Shape{2, 16}));
|
||||
}
|
||||
@@ -7,7 +7,6 @@
|
||||
#include "ngraph/ngraph.hpp"
|
||||
#include "ngraph/op/ctc_greedy_decoder.hpp"
|
||||
#include "ngraph/op/interpolate.hpp"
|
||||
#include "ngraph/op/prior_box.hpp"
|
||||
#include "ngraph/op/prior_box_clustered.hpp"
|
||||
#include "ngraph/op/region_yolo.hpp"
|
||||
#include "ngraph/op/reorg_yolo.hpp"
|
||||
@@ -46,47 +45,6 @@ TEST(type_prop_layers, interpolate)
|
||||
.same_scheme(PartialShape{2, 2, Dimension::dynamic(), Dimension::dynamic()}));
|
||||
}
|
||||
|
||||
TEST(type_prop_layers, prior_box1)
|
||||
{
|
||||
op::PriorBoxAttrs attrs;
|
||||
attrs.min_size = {2.0f, 3.0f};
|
||||
attrs.aspect_ratio = {1.5f, 2.0f, 2.5f};
|
||||
attrs.scale_all_sizes = false;
|
||||
|
||||
auto layer_shape = op::Constant::create<int64_t>(element::i64, Shape{2}, {32, 32});
|
||||
auto image_shape = op::Constant::create<int64_t>(element::i64, Shape{2}, {300, 300});
|
||||
auto pb = make_shared<op::PriorBox>(layer_shape, image_shape, attrs);
|
||||
ASSERT_EQ(pb->get_shape(), (Shape{2, 20480}));
|
||||
}
|
||||
|
||||
TEST(type_prop_layers, prior_box2)
|
||||
{
|
||||
op::PriorBoxAttrs attrs;
|
||||
attrs.min_size = {2.0f, 3.0f};
|
||||
attrs.aspect_ratio = {1.5f, 2.0f, 2.5f};
|
||||
attrs.flip = true;
|
||||
attrs.scale_all_sizes = false;
|
||||
|
||||
auto layer_shape = op::Constant::create<int64_t>(element::i64, Shape{2}, {32, 32});
|
||||
auto image_shape = op::Constant::create<int64_t>(element::i64, Shape{2}, {300, 300});
|
||||
auto pb = make_shared<op::PriorBox>(layer_shape, image_shape, attrs);
|
||||
ASSERT_EQ(pb->get_shape(), (Shape{2, 32768}));
|
||||
}
|
||||
|
||||
TEST(type_prop_layers, prior_box3)
|
||||
{
|
||||
op::PriorBoxAttrs attrs;
|
||||
attrs.min_size = {256.0f};
|
||||
attrs.max_size = {315.0f};
|
||||
attrs.aspect_ratio = {2.0f};
|
||||
attrs.flip = true;
|
||||
|
||||
auto layer_shape = op::Constant::create<int64_t>(element::i64, Shape{2}, {1, 1});
|
||||
auto image_shape = op::Constant::create<int64_t>(element::i64, Shape{2}, {300, 300});
|
||||
auto pb = make_shared<op::PriorBox>(layer_shape, image_shape, attrs);
|
||||
ASSERT_EQ(pb->get_shape(), (Shape{2, 16}));
|
||||
}
|
||||
|
||||
TEST(type_prop_layers, prior_box_clustered)
|
||||
{
|
||||
op::PriorBoxClusteredAttrs attrs;
|
||||
|
||||
@@ -45,6 +45,8 @@ TEST(attributes, prior_box_op)
|
||||
const auto prior_box_attrs = prior_box->get_attrs();
|
||||
const auto g_prior_box_attrs = g_prior_box->get_attrs();
|
||||
|
||||
const auto expected_attr_count = 12;
|
||||
EXPECT_EQ(builder.get_value_map_size(), expected_attr_count);
|
||||
EXPECT_EQ(g_prior_box_attrs.min_size, prior_box_attrs.min_size);
|
||||
EXPECT_EQ(g_prior_box_attrs.max_size, prior_box_attrs.max_size);
|
||||
EXPECT_EQ(g_prior_box_attrs.aspect_ratio, prior_box_attrs.aspect_ratio);
|
||||
|
||||
Reference in New Issue
Block a user