Skip to content

Commit

Permalink
Add clone_with_new_inputs to visitor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
olpipi committed Oct 21, 2022
1 parent ef180e6 commit 9a85397
Show file tree
Hide file tree
Showing 109 changed files with 278 additions and 200 deletions.
14 changes: 12 additions & 2 deletions src/core/src/attribute_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,18 @@ void ov::AttributeVisitor::register_node(const std::shared_ptr<ngraph::Node>& no
if (id == invalid_node_id) {
id = node->get_friendly_name();
}
m_id_node_map[id] = node;
m_node_id_map[node] = id;
if (m_id_node_map.find(id) == m_id_node_map.end()) {
m_id_node_map.insert(std::make_pair(id, node));
}
else {
m_id_node_map[id] = node;
}
if (m_node_id_map.find(node) == m_node_id_map.end()) {
m_node_id_map.insert(std::make_pair(node, id));
}
else {
m_node_id_map[node] = id;
}
}

std::shared_ptr<ngraph::Node> ov::AttributeVisitor::get_registered_node(node_id_t id) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/tests/visitors/op/adaptive_avg_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ TEST(attributes, adaptive_avg_pool_op) {
const auto out_shape = op::Constant::create<int64_t>(element::i64, Shape{2}, {4, 3});

const auto adaptive_pool = make_shared<opset8::AdaptiveAvgPool>(A, out_shape);
NodeBuilder builder(adaptive_pool);
NodeBuilder builder(adaptive_pool, {A, out_shape});

const auto expected_attr_count = 0;
EXPECT_EQ(builder.get_value_map_size(), expected_attr_count);
Expand Down
2 changes: 1 addition & 1 deletion src/core/tests/visitors/op/adaptive_max_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ TEST(attributes, adaptive_max_pool_op) {
const auto out_shape = op::Constant::create<int64_t>(element::i64, Shape{2}, {4, 3});

const auto adaptive_pool = make_shared<opset8::AdaptiveMaxPool>(A, out_shape);
NodeBuilder builder(adaptive_pool);
NodeBuilder builder(adaptive_pool, {A, out_shape});
auto g_adaptive_pool = ov::as_type_ptr<opset8::AdaptiveMaxPool>(builder.create());

const auto expected_attr_count = 1;
Expand Down
4 changes: 2 additions & 2 deletions src/core/tests/visitors/op/assign.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ TEST(attributes, assign_v3_op) {
const string variable_id = "v0";
const auto read_value = make_shared<opset3::ReadValue>(in, variable_id);
const auto assign = make_shared<opset3::Assign>(read_value, variable_id);
NodeBuilder builder(assign);
NodeBuilder builder(assign, {read_value});

// attribute count
const auto expected_attr_count = 1;
Expand All @@ -33,7 +33,7 @@ TEST(attributes, assign_v6_op) {
const auto variable = std::make_shared<Variable>(VariableInfo{PartialShape::dynamic(), element::dynamic, "v0"});
const auto read_value = make_shared<opset6::ReadValue>(in, variable);
const auto assign = make_shared<opset6::Assign>(read_value, variable);
NodeBuilder builder(assign);
NodeBuilder builder(assign, {read_value});

// attribute count
const auto expected_attr_count = 1;
Expand Down
4 changes: 2 additions & 2 deletions src/core/tests/visitors/op/avg_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ TEST(attributes, avg_pool_op) {
auto avg_pool =
make_shared<opset1::AvgPool>(data, strides, pads_begin, pads_end, kernel, exclude_pad, rounding_mode, auto_pad);

NodeBuilder builder(avg_pool);
NodeBuilder builder(avg_pool, {data});
auto g_avg_pool = ov::as_type_ptr<opset1::AvgPool>(builder.create());

EXPECT_EQ(g_avg_pool->get_strides(), avg_pool->get_strides());
Expand All @@ -54,7 +54,7 @@ TEST(attributes, avg_pool_v8_op) {

const auto avg_pool =
make_shared<opset8::AvgPool>(data, strides, pads_begin, pads_end, kernel, exclude_pad, rounding_mode, auto_pad);
NodeBuilder builder(avg_pool);
NodeBuilder builder(avg_pool, {data});
auto g_avg_pool = ov::as_type_ptr<opset8::AvgPool>(builder.create());

EXPECT_EQ(g_avg_pool->get_strides(), avg_pool->get_strides());
Expand Down
36 changes: 23 additions & 13 deletions src/core/tests/visitors/op/batch_norm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,44 @@ using namespace ngraph;
using ngraph::test::NodeBuilder;
using ngraph::test::ValueMap;

template <class T>
class BatchNormAttrTest : public ::testing::Test {};

TYPED_TEST_SUITE_P(BatchNormAttrTest);

TYPED_TEST_P(BatchNormAttrTest, batch_norm_inference_op) {
TEST(attributes, batch_norm_inference_op_v5) {
PartialShape in_shape{1, 10};
PartialShape ch_shape{in_shape[1]};
element::Type et = element::f32;
double epsilon = 0.001;

NodeBuilder::get_ops().register_factory<TypeParam>();
NodeBuilder::get_ops().register_factory<op::v5::BatchNormInference>();
auto data_batch = make_shared<op::Parameter>(et, in_shape);
auto gamma = make_shared<op::Parameter>(et, ch_shape);
auto beta = make_shared<op::Parameter>(et, ch_shape);
auto mean = make_shared<op::Parameter>(et, ch_shape);
auto var = make_shared<op::Parameter>(et, ch_shape);
auto batch_norm = make_shared<TypeParam>(data_batch, gamma, beta, mean, var, epsilon);
auto batch_norm = make_shared<op::v5::BatchNormInference>(data_batch, gamma, beta, mean, var, epsilon);

const auto expected_attr_count = 1;
NodeBuilder builder(batch_norm);
NodeBuilder builder(batch_norm, {data_batch, gamma, beta, mean, var});
EXPECT_EQ(builder.get_value_map_size(), expected_attr_count);
auto g_batch_norm = ov::as_type_ptr<TypeParam>(builder.create());
auto g_batch_norm = ov::as_type_ptr<op::v5::BatchNormInference>(builder.create());
EXPECT_EQ(g_batch_norm->get_eps_value(), batch_norm->get_eps_value());
}

REGISTER_TYPED_TEST_SUITE_P(BatchNormAttrTest, batch_norm_inference_op);
TEST(attributes, batch_norm_inference_op_v0) {
PartialShape in_shape{1, 10};
PartialShape ch_shape{in_shape[1]};
element::Type et = element::f32;
double epsilon = 0.001;

using Types = ::testing::Types<op::v0::BatchNormInference, op::v5::BatchNormInference>;
NodeBuilder::get_ops().register_factory<op::v0::BatchNormInference>();
auto data_batch = make_shared<op::Parameter>(et, in_shape);
auto gamma = make_shared<op::Parameter>(et, ch_shape);
auto beta = make_shared<op::Parameter>(et, ch_shape);
auto mean = make_shared<op::Parameter>(et, ch_shape);
auto var = make_shared<op::Parameter>(et, ch_shape);
auto batch_norm = make_shared<op::v0::BatchNormInference>(data_batch, gamma, beta, mean, var, epsilon);

INSTANTIATE_TYPED_TEST_SUITE_P(attributes, BatchNormAttrTest, Types);
const auto expected_attr_count = 1;
NodeBuilder builder(batch_norm, {gamma, beta, data_batch, mean, var});
EXPECT_EQ(builder.get_value_map_size(), expected_attr_count);
auto g_batch_norm = ov::as_type_ptr<op::v0::BatchNormInference>(builder.create());
EXPECT_EQ(g_batch_norm->get_eps_value(), batch_norm->get_eps_value());
}
2 changes: 1 addition & 1 deletion src/core/tests/visitors/op/batch_to_space.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ TEST(attributes, batch_to_space_op) {
auto crops_end = make_shared<op::Constant>(element::i64, Shape{2}, vector<int64_t>{0, 0});
auto batch2space = make_shared<op::v1::BatchToSpace>(data, block_shape, crops_begin, crops_end);

NodeBuilder builder(batch2space);
NodeBuilder builder(batch2space, {data});
const auto expected_attr_count = 0;

EXPECT_EQ(builder.get_value_map_size(), expected_attr_count);
Expand Down
2 changes: 1 addition & 1 deletion src/core/tests/visitors/op/binary_convolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ TEST(attributes, bin_convolution) {
mode,
pad_value,
auto_pad);
NodeBuilder builder(conv);
NodeBuilder builder(conv, {data_batch, filters});
auto g_convolution = ov::as_type_ptr<op::v1::BinaryConvolution>(builder.create());

// attribute count
Expand Down
4 changes: 2 additions & 2 deletions src/core/tests/visitors/op/binary_ops.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ TYPED_TEST_P(BinaryOperatorVisitor, Auto_Broadcast)
auto auto_broadcast = ngraph::op::AutoBroadcastType::NUMPY;

const auto op_func = std::make_shared<OP_Type>(A, B, auto_broadcast);
ngraph::test::NodeBuilder builder(op_func);
ngraph::test::NodeBuilder builder(op_func, {A, B});
const auto g_op_func = ngraph::as_type_ptr<OP_Type>(builder.create());

const auto expected_attr_count = 1;
Expand All @@ -69,7 +69,7 @@ TYPED_TEST_P(BinaryOperatorVisitor, No_Broadcast)
std::make_shared<ngraph::op::Parameter>(element_type, ngraph::PartialShape{1, 2, 3});

const auto op_func = std::make_shared<OP_Type>(A, B);
ngraph::test::NodeBuilder builder(op_func);
ngraph::test::NodeBuilder builder(op_func, {A, B});
const auto g_op_func = ngraph::as_type_ptr<OP_Type>(builder.create());

const auto expected_attr_count = 1;
Expand Down
2 changes: 1 addition & 1 deletion src/core/tests/visitors/op/broadcast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ TEST(attributes, broadcast_v3) {
const auto broadcast_spec = op::BroadcastType::BIDIRECTIONAL;

const auto broadcast_v3 = make_shared<op::v3::Broadcast>(arg, shape, broadcast_spec);
NodeBuilder builder(broadcast_v3);
NodeBuilder builder(broadcast_v3, {arg, shape});
auto g_broadcast_v3 = ov::as_type_ptr<opset3::Broadcast>(builder.create());

EXPECT_EQ(g_broadcast_v3->get_broadcast_spec(), broadcast_spec);
Expand Down
4 changes: 2 additions & 2 deletions src/core/tests/visitors/op/bucketize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ TEST(attributes, bucketize_v3_op_default_attributes) {
auto data = make_shared<op::Parameter>(element::f32, Shape{2, 3, 4});
auto buckets = make_shared<op::Parameter>(element::f32, Shape{5});
auto bucketize = make_shared<opset3::Bucketize>(data, buckets);
NodeBuilder builder(bucketize);
NodeBuilder builder(bucketize, {data, buckets});

auto g_bucketize = ov::as_type_ptr<opset3::Bucketize>(builder.create());

Expand All @@ -37,7 +37,7 @@ TEST(attributes, bucketize_v3_op_custom_attributes) {
bool with_right_bound = false;

auto bucketize = make_shared<opset3::Bucketize>(data, buckets, output_type, with_right_bound);
NodeBuilder builder(bucketize);
NodeBuilder builder(bucketize, {data, buckets});

auto g_bucketize = ov::as_type_ptr<opset3::Bucketize>(builder.create());

Expand Down
2 changes: 1 addition & 1 deletion src/core/tests/visitors/op/clamp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ TEST(attributes, clamp_op) {
double max = 5.6;

const auto clamp = make_shared<opset1::Clamp>(data, min, max);
NodeBuilder builder(clamp);
NodeBuilder builder(clamp, {data});
auto g_clamp = ov::as_type_ptr<opset1::Clamp>(builder.create());

const auto expected_attr_count = 2;
Expand Down
2 changes: 1 addition & 1 deletion src/core/tests/visitors/op/concat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ TEST(attributes, concat_op) {
int64_t axis = 2;

auto concat = make_shared<opset1::Concat>(ov::NodeVector{input1, input2, input3}, axis);
NodeBuilder builder(concat);
NodeBuilder builder(concat, {input1, input2, input3});
auto g_concat = ov::as_type_ptr<opset1::Concat>(builder.create());

EXPECT_EQ(g_concat->get_axis(), concat->get_axis());
Expand Down
2 changes: 1 addition & 1 deletion src/core/tests/visitors/op/convert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ TEST(attributes, convert_op_v0) {
const element::Type destination_type = element::Type_t::i32;

const auto convert = std::make_shared<Convert>(data, destination_type);
NodeBuilder builder(convert);
NodeBuilder builder(convert, {data});

// attribute count
const auto expected_attr_count = 1;
Expand Down
16 changes: 12 additions & 4 deletions src/core/tests/visitors/op/convert_color_i420.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ TEST(attributes, convert_color_i420_rgb) {
NodeBuilder::get_ops().register_factory<op::v8::I420toRGB>();
auto data = make_shared<op::v0::Parameter>(element::u8, Shape{3, 720, 640, 1});
auto convert_color = make_shared<op::v8::I420toRGB>(data);
NodeBuilder builder(convert_color);
NodeBuilder builder(convert_color, {data});
EXPECT_NO_THROW(auto g_concat = ov::as_type_ptr<op::v8::I420toRGB>(builder.create()));

const auto expected_attr_count = 0;
EXPECT_EQ(builder.get_value_map_size(), expected_attr_count);
}
Expand All @@ -26,7 +28,9 @@ TEST(attributes, convert_color_i420_bgr) {
NodeBuilder::get_ops().register_factory<op::v8::I420toBGR>();
auto data = make_shared<op::v0::Parameter>(element::u8, Shape{3, 720, 640, 1});
auto convert_color = make_shared<op::v8::I420toBGR>(data);
NodeBuilder builder(convert_color);
NodeBuilder builder(convert_color, {data});
EXPECT_NO_THROW(auto g_concat = ov::as_type_ptr<op::v8::I420toRGB>(builder.create()));

const auto expected_attr_count = 0;
EXPECT_EQ(builder.get_value_map_size(), expected_attr_count);
}
Expand All @@ -37,7 +41,9 @@ TEST(attributes, convert_color_i420_rgb_3planes) {
auto data2 = make_shared<op::v0::Parameter>(element::u8, Shape{3, 240, 320, 1});
auto data3 = make_shared<op::v0::Parameter>(element::u8, Shape{3, 240, 320, 1});
auto convert_color = make_shared<op::v8::I420toRGB>(data1, data2, data3);
NodeBuilder builder(convert_color);
NodeBuilder builder(convert_color, {data1, data2, data3});
EXPECT_NO_THROW(auto g_concat = ov::as_type_ptr<op::v8::I420toRGB>(builder.create()));

const auto expected_attr_count = 0;
EXPECT_EQ(builder.get_value_map_size(), expected_attr_count);
}
Expand All @@ -48,7 +54,9 @@ TEST(attributes, convert_color_i420_bgr_3planes) {
auto data2 = make_shared<op::v0::Parameter>(element::u8, Shape{3, 240, 320, 1});
auto data3 = make_shared<op::v0::Parameter>(element::u8, Shape{3, 240, 320, 1});
auto convert_color = make_shared<op::v8::I420toBGR>(data1, data2, data3);
NodeBuilder builder(convert_color);
NodeBuilder builder(convert_color, {data1, data2, data3});
EXPECT_NO_THROW(auto g_concat = ov::as_type_ptr<op::v8::I420toRGB>(builder.create()));

const auto expected_attr_count = 0;
EXPECT_EQ(builder.get_value_map_size(), expected_attr_count);
}
16 changes: 12 additions & 4 deletions src/core/tests/visitors/op/convert_color_nv12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ TEST(attributes, convert_color_nv12_rgb) {
NodeBuilder::get_ops().register_factory<op::v8::NV12toRGB>();
auto data = make_shared<op::v0::Parameter>(element::u8, Shape{3, 720, 640, 1});
auto convert_color = make_shared<op::v8::NV12toRGB>(data);
NodeBuilder builder(convert_color);
NodeBuilder builder(convert_color, {data});
EXPECT_NO_THROW(auto g_concat = ov::as_type_ptr<op::v8::NV12toRGB>(builder.create()));

const auto expected_attr_count = 0;
EXPECT_EQ(builder.get_value_map_size(), expected_attr_count);
}
Expand All @@ -26,7 +28,9 @@ TEST(attributes, convert_color_nv12_bgr) {
NodeBuilder::get_ops().register_factory<op::v8::NV12toBGR>();
auto data = make_shared<op::v0::Parameter>(element::u8, Shape{3, 720, 640, 1});
auto convert_color = make_shared<op::v8::NV12toBGR>(data);
NodeBuilder builder(convert_color);
NodeBuilder builder(convert_color, {data});
EXPECT_NO_THROW(auto g_concat = ov::as_type_ptr<op::v8::NV12toRGB>(builder.create()));

const auto expected_attr_count = 0;
EXPECT_EQ(builder.get_value_map_size(), expected_attr_count);
}
Expand All @@ -36,7 +40,9 @@ TEST(attributes, convert_color_nv12_rgb_2planes) {
auto data1 = make_shared<op::v0::Parameter>(element::u8, Shape{3, 480, 640, 1});
auto data2 = make_shared<op::v0::Parameter>(element::u8, Shape{3, 240, 320, 2});
auto convert_color = make_shared<op::v8::NV12toRGB>(data1, data2);
NodeBuilder builder(convert_color);
NodeBuilder builder(convert_color, {data1, data2});
EXPECT_NO_THROW(auto g_concat = ov::as_type_ptr<op::v8::NV12toRGB>(builder.create()));

const auto expected_attr_count = 0;
EXPECT_EQ(builder.get_value_map_size(), expected_attr_count);
}
Expand All @@ -46,7 +52,9 @@ TEST(attributes, convert_color_nv12_bgr_2planes) {
auto data1 = make_shared<op::v0::Parameter>(element::u8, Shape{3, 480, 640, 1});
auto data2 = make_shared<op::v0::Parameter>(element::u8, Shape{3, 240, 320, 2});
auto convert_color = make_shared<op::v8::NV12toBGR>(data1, data2);
NodeBuilder builder(convert_color);
NodeBuilder builder(convert_color, {data1, data2});
EXPECT_NO_THROW(auto g_concat = ov::as_type_ptr<op::v8::NV12toRGB>(builder.create()));

const auto expected_attr_count = 0;
EXPECT_EQ(builder.get_value_map_size(), expected_attr_count);
}
4 changes: 2 additions & 2 deletions src/core/tests/visitors/op/convolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ TEST(attributes, convolution) {
auto convolution =
make_shared<op::v1::Convolution>(data, filters, strides, pads_begin, pads_end, dilations, op::PadType::VALID);

NodeBuilder builder(convolution);
NodeBuilder builder(convolution, {data, filters});
auto g_convolution = ov::as_type_ptr<op::v1::Convolution>(builder.create());

// attribute count
Expand All @@ -51,7 +51,7 @@ TEST(attributes, convolution2) {
auto dilations = Strides{1, 1};
auto convolution =
make_shared<op::v1::Convolution>(data, filters, strides, pads_begin, pads_end, dilations, op::PadType::VALID);
NodeBuilder builder(convolution);
NodeBuilder builder(convolution, {data, filters});
auto g_convolution = ov::as_type_ptr<op::v1::Convolution>(builder.create());

// attribute count
Expand Down
4 changes: 2 additions & 2 deletions src/core/tests/visitors/op/convolution_backprop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ TEST(attributes, convolution_backprop_op) {
pads_end,
dilations,
op::PadType::VALID);
NodeBuilder builder(convolution);
NodeBuilder builder(convolution, {data, filters});
auto g_convolution = ov::as_type_ptr<opset1::ConvolutionBackpropData>(builder.create());

// attribute count
Expand Down Expand Up @@ -74,7 +74,7 @@ TEST(attributes, convolution_backprop_output_shape_output_padding) {
dilations,
padType,
output_padding);
NodeBuilder builder(convolution);
NodeBuilder builder(convolution, {data, filter});
const auto g_convolution = ov::as_type_ptr<opset1::ConvolutionBackpropData>(builder.create());

// attribute count
Expand Down
2 changes: 1 addition & 1 deletion src/core/tests/visitors/op/ctc_greedy_decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ TEST(attributes, ctc_greedy_decoder_op) {
auto masks = make_shared<op::Parameter>(element::i32, Shape{3, 1});
auto decoder = make_shared<op::v0::CTCGreedyDecoder>(data, masks, m_ctc_merge_repeated);

NodeBuilder builder(decoder);
NodeBuilder builder(decoder, {data, masks});
auto g_decoder = ov::as_type_ptr<opset1::CTCGreedyDecoder>(builder.create());

EXPECT_EQ(g_decoder->get_ctc_merge_repeated(), decoder->get_ctc_merge_repeated());
Expand Down
2 changes: 1 addition & 1 deletion src/core/tests/visitors/op/ctc_greedy_decoder_seq_len.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ TEST(attributes, ctc_greedy_decoder_seq_len_op) {
auto blank_index = op::Constant::create<int32_t>(element::i32, Shape{}, {2});
auto decoder = make_shared<op::v6::CTCGreedyDecoderSeqLen>(data, seq_len, blank_index, merge_repeated);

NodeBuilder builder(decoder);
NodeBuilder builder(decoder, {data, seq_len, blank_index});
auto g_decoder = ov::as_type_ptr<opset6::CTCGreedyDecoderSeqLen>(builder.create());

EXPECT_EQ(g_decoder->get_merge_repeated(), decoder->get_merge_repeated());
Expand Down
2 changes: 1 addition & 1 deletion src/core/tests/visitors/op/ctc_loss.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ TEST(attributes, ctc_loss) {
auto blank_index = make_shared<op::Parameter>(element::i32, Shape{});

auto ctc_loss = make_shared<opset4::CTCLoss>(logits, logit_length, labels, label_length, blank_index);
NodeBuilder builder(ctc_loss);
NodeBuilder builder(ctc_loss, {logits, logit_length, labels, label_length, blank_index});
auto g_ctc_loss = as_type_ptr<opset4::CTCLoss>(builder.create());

// attribute count
Expand Down
Loading

0 comments on commit 9a85397

Please sign in to comment.