Commit 47dc073e authored by Mateusz Bencer's avatar Mateusz Bencer Committed by Scott Cyphers

[Spec] Adjust op Proposal (#3419)

* Changed required image_shape type from u64 to float

* Proposal op was adjusted

* Clang styles applied

* Added missing new line

* Fixed problem with narrowing conversion

* Code review remarks

* Removed checking types of Proposal input params

* Removed unused input element type variables
parent c3b53e5d
......@@ -35,25 +35,48 @@ op::Proposal::Proposal(const std::shared_ptr<Node>& class_probs,
void op::Proposal::validate_and_infer_types()
{
// shape node should have integer data type. For now we only allow i64
auto image_shape_et = get_input_element_type(2);
NODE_VALIDATION_CHECK(this,
image_shape_et.compatible(element::Type_t::i64),
"image shape input must have element type i64, but has ",
image_shape_et);
set_input_is_relevant_to_shape(2);
if (auto const_shape = dynamic_pointer_cast<op::Constant>(get_argument(2)))
const auto& class_probs_pshape = get_input_partial_shape(0);
const auto& class_logits_pshape = get_input_partial_shape(1);
const auto& image_shape_pshape = get_input_partial_shape(2);
if (class_probs_pshape.is_static() && class_logits_pshape.is_static() &&
image_shape_pshape.is_static())
{
NODE_VALIDATION_CHECK(this,
shape_size(const_shape->get_shape()) >= 1,
"Layer shape must have rank greater than 1",
const_shape->get_shape());
const Shape class_probs_shape{class_probs_pshape.to_shape()};
const Shape class_logits_shape{class_logits_pshape.to_shape()};
const Shape image_shape_shape{image_shape_pshape.to_shape()};
NODE_VALIDATION_CHECK(
this,
class_probs_shape.size() == 4,
"Proposal layer shape class_probs input must have rank 4 (class_probs_shape: ",
class_probs_shape,
").");
NODE_VALIDATION_CHECK(
this,
class_logits_shape.size() == 4,
"Proposal layer shape class_logits_shape input must have rank 4 (class_logits_shape: ",
class_logits_shape,
").");
NODE_VALIDATION_CHECK(
this,
image_shape_shape.size() == 1,
"Proposal layer image_shape input must have rank 1 (image_shape_shape: ",
image_shape_shape,
").");
auto image_shape = const_shape->get_shape_val();
NODE_VALIDATION_CHECK(
this,
image_shape_shape[0] >= 3 && image_shape_shape[0] <= 4,
"Image_shape 1D tensor must have => 3 and <= 4 elements (image_shape_shape[0]",
image_shape_shape[0],
").");
set_output_type(0, element::f32, Shape{image_shape[0] * m_attrs.post_nms_topn, 5});
auto batch_size = class_probs_shape[0];
set_output_type(0, element::f32, Shape{batch_size * m_attrs.post_nms_topn, 5});
}
else
{
......
......@@ -120,6 +120,7 @@ set(SRC
type_prop/pad.cpp
type_prop/parameter.cpp
type_prop/prelu.cpp
type_prop/proposal.cpp
type_prop/quantize.cpp
type_prop/quantized_convolution.cpp
type_prop/range.cpp
......
//*****************************************************************************
// Copyright 2017-2019 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.
//*****************************************************************************
#include "ngraph/op/experimental/layers/proposal.hpp"
#include "gtest/gtest.h"
#include "ngraph/ngraph.hpp"
#include "util/type_prop.hpp"
using namespace std;
using namespace ngraph;
TEST(type_prop, proposal_invalid_class_probs_rank)
{
op::ProposalAttrs attrs;
auto class_probs = make_shared<op::Parameter>(element::f32, Shape{1, 2, 3});
auto class_logits = make_shared<op::Parameter>(element::f32, Shape{1, 2, 3, 4});
auto image_shape = make_shared<op::Parameter>(element::f32, Shape{3});
try
{
auto proposal = make_shared<op::Proposal>(class_probs, class_logits, image_shape, attrs);
// Should have thrown, so fail if it didn't
FAIL() << "Invalid input tensor rank.";
}
catch (const NodeValidationFailure& error)
{
EXPECT_HAS_SUBSTRING(
error.what(), std::string("Proposal layer shape class_probs input must have rank 4"));
}
catch (...)
{
FAIL() << "Deduced type check failed for unexpected reason";
}
}
TEST(type_prop, proposal_invalid_class_logits_rank)
{
op::ProposalAttrs attrs;
auto class_probs = make_shared<op::Parameter>(element::f32, Shape{1, 2, 3, 4});
auto class_logits = make_shared<op::Parameter>(element::f32, Shape{1, 2, 3});
auto image_shape = make_shared<op::Parameter>(element::f32, Shape{3});
try
{
auto proposal = make_shared<op::Proposal>(class_probs, class_logits, image_shape, attrs);
// Should have thrown, so fail if it didn't
FAIL() << "Invalid input tensor rank.";
}
catch (const NodeValidationFailure& error)
{
EXPECT_HAS_SUBSTRING(
error.what(),
std::string("Proposal layer shape class_logits_shape input must have rank 4"));
}
catch (...)
{
FAIL() << "Deduced type check failed for unexpected reason";
}
}
TEST(type_prop, proposal_invalid_image_shape_rank)
{
op::ProposalAttrs attrs;
auto class_probs = make_shared<op::Parameter>(element::f32, Shape{1, 2, 3, 4});
auto class_logits = make_shared<op::Parameter>(element::f32, Shape{1, 2, 3, 4});
auto image_shape = make_shared<op::Parameter>(element::f32, Shape{2, 1});
try
{
auto proposal = make_shared<op::Proposal>(class_probs, class_logits, image_shape, attrs);
// Should have thrown, so fail if it didn't
FAIL() << "Invalid input tensor rank.";
}
catch (const NodeValidationFailure& error)
{
EXPECT_HAS_SUBSTRING(error.what(),
std::string("Proposal layer image_shape input must have rank 1"));
}
catch (...)
{
FAIL() << "Deduced type check failed for unexpected reason";
}
}
TEST(type_prop, proposal_invalid_image_shape_size)
{
op::ProposalAttrs attrs;
auto class_probs = make_shared<op::Parameter>(element::f32, Shape{1, 2, 3, 4});
auto class_logits = make_shared<op::Parameter>(element::f32, Shape{1, 2, 3, 4});
auto image_shape = make_shared<op::Parameter>(element::f32, Shape{5});
try
{
auto proposal = make_shared<op::Proposal>(class_probs, class_logits, image_shape, attrs);
// Should have thrown, so fail if it didn't
FAIL() << "Invalid input tensor rank.";
}
catch (const NodeValidationFailure& error)
{
EXPECT_HAS_SUBSTRING(
error.what(),
std::string(
"Image_shape 1D tensor must have => 3 and <= 4 elements (image_shape_shape[0]"));
}
catch (...)
{
FAIL() << "Deduced type check failed for unexpected reason";
}
}
......@@ -130,12 +130,13 @@ TEST(type_prop_layers, proposal)
attrs.base_size = 1;
attrs.pre_nms_topn = 20;
attrs.post_nms_topn = 200;
const uint64_t batch_size = 7;
auto class_probs = make_shared<op::Parameter>(element::f32, Shape{1, 12, 34, 62});
auto class_logits = make_shared<op::Parameter>(element::f32, Shape{1, 24, 34, 62});
auto image_shape = op::Constant::create<int64_t>(element::i64, Shape{2}, {1, 6});
auto class_probs = make_shared<op::Parameter>(element::f32, Shape{batch_size, 12, 34, 62});
auto class_logits = make_shared<op::Parameter>(element::f32, Shape{batch_size, 24, 34, 62});
auto image_shape = make_shared<op::Parameter>(element::f32, Shape{3});
auto op = make_shared<op::Proposal>(class_probs, class_logits, image_shape, attrs);
ASSERT_EQ(op->get_shape(), (Shape{200, 5}));
ASSERT_EQ(op->get_shape(), (Shape{batch_size * attrs.post_nms_topn, 5}));
}
TEST(type_prop_layers, region_yolo1)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment