From: Ilya Churaev Date: Mon, 27 Jul 2020 09:34:20 +0000 (+0300) Subject: Removed v0 CropAndResize and EmbeddingLoop operations (#1450) X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=782749034098695b41647788cb7620aa5062e1d3;p=platform%2Fupstream%2Fdldt.git Removed v0 CropAndResize and EmbeddingLoop operations (#1450) --- diff --git a/ngraph/src/ngraph/CMakeLists.txt b/ngraph/src/ngraph/CMakeLists.txt index 351d88d..33dfe80 100644 --- a/ngraph/src/ngraph/CMakeLists.txt +++ b/ngraph/src/ngraph/CMakeLists.txt @@ -160,8 +160,6 @@ set (SRC op/ctc_loss.hpp op/cum_sum.cpp op/cum_sum.hpp - op/crop_and_resize.cpp - op/crop_and_resize.hpp op/deformable_convolution.cpp op/deformable_convolution.hpp op/deformable_psroi_pooling.cpp @@ -178,8 +176,6 @@ set (SRC op/elu.hpp op/embeddingbag_offsets_sum.cpp op/embeddingbag_offsets_sum.hpp - op/embedding_lookup.cpp - op/embedding_lookup.hpp op/embeddingbag_packedsum.cpp op/embeddingbag_packedsum.hpp op/embedding_segments_sum.cpp diff --git a/ngraph/src/ngraph/op/crop_and_resize.cpp b/ngraph/src/ngraph/op/crop_and_resize.cpp deleted file mode 100644 index 802f70f..0000000 --- a/ngraph/src/ngraph/op/crop_and_resize.cpp +++ /dev/null @@ -1,196 +0,0 @@ -//***************************************************************************** -// 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. -//***************************************************************************** - -#include - -#include "ngraph/op/constant.hpp" -#include "ngraph/op/crop_and_resize.hpp" -#include "ngraph/op/util/op_types.hpp" - -using namespace std; -using namespace ngraph; - -constexpr NodeTypeInfo op::CropAndResize::type_info; - -op::CropAndResize::CropAndResize(const Output& image, - const Output& boxes, - const Output& box_indices, - const Output& crop_size, - ResizeMethod resize_method, - float extrapolation_value) - : Op({image, boxes, box_indices, crop_size}) - , m_resize_method(resize_method) - , m_extrapolation_value(extrapolation_value) -{ - constructor_validate_and_infer_types(); -} - -void op::CropAndResize::validate_and_infer_types() -{ - NODE_VALIDATION_CHECK(this, get_input_size() == 4); - NODE_VALIDATION_CHECK( - this, m_resize_method != ResizeMethod::unspecified, "Resize method not specified"); - auto image = input_value(0); - auto& image_et = image.get_element_type(); - - // Will override if we can determine the shape - set_output_type(0, image_et, {}); - - auto image_shape = image.get_partial_shape(); - Dimension image_depth; - if (image_shape.is_static()) - { - NODE_VALIDATION_CHECK(this, image_shape.rank().get_length() == 4, "Image must be NHWC"); - image_depth = image_shape[3]; - } - - auto boxes = input_value(1); - auto boxes_shape = boxes.get_partial_shape(); - if (boxes_shape.is_static()) - { - auto boxes_rank = boxes_shape.rank(); - NODE_VALIDATION_CHECK(this, boxes_rank.get_length() == 2, "Boxes must be 2d"); - auto boxes_dim1 = boxes_shape[1]; - NODE_VALIDATION_CHECK( - this, boxes_dim1.get_length() == 4, "Second boxes dimension must be 4"); - } - NODE_VALIDATION_CHECK( - this, boxes.get_element_type().is_real(), "Boxes must be real values in [0, 1]"); - - auto box_indices = input_value(2); - auto box_indices_shape = box_indices.get_partial_shape(); - Dimension num_boxes; - if (box_indices_shape.is_static()) - { - NODE_VALIDATION_CHECK( - this, box_indices_shape.rank().get_length() == 1, "Box indices must have rank 1"); - num_boxes = box_indices_shape[0]; - } - NODE_VALIDATION_CHECK( - this, box_indices.get_element_type().is_integral(), "Box indices must be integers"); - - auto crop_size = input_value(3); - auto crop_size_shape = crop_size.get_partial_shape(); - auto crop_size_rank = crop_size_shape.rank(); - NODE_VALIDATION_CHECK(this, - crop_size_shape.is_static() || crop_size_rank.is_dynamic(), - "Dynamic crop_size not supported"); - - NODE_VALIDATION_CHECK(this, crop_size_rank.get_length() == 1, "crop_size must be a vector"); - NODE_VALIDATION_CHECK( - this, crop_size_shape[0].get_length() == 2, "crop_size must be a vector of length 2"); - auto& crop_size_et = crop_size.get_element_type(); - NODE_VALIDATION_CHECK(this, crop_size_et.is_integral(), "crops_size must be integral"); - auto crop_size_node = crop_size.get_node_shared_ptr(); - NODE_VALIDATION_CHECK( - this, ngraph::op::is_constant(crop_size_node), "crop_size must be a constant"); - auto crop_size_const = static_pointer_cast(crop_size_node); - if (crop_size_et == element::i8) - { - auto v = crop_size_const->get_vector(); - set_output_type(0, image_et, {num_boxes, v[0], v[1], image_depth}); - } - else if (crop_size_et == element::u8) - { - auto v = crop_size_const->get_vector(); - set_output_type(0, image_et, {num_boxes, v[0], v[1], image_depth}); - } - else if (crop_size_et == element::i16) - { - auto v = crop_size_const->get_vector(); - set_output_type(0, image_et, {num_boxes, v[0], v[1], image_depth}); - } - else if (crop_size_et == element::u16) - { - auto v = crop_size_const->get_vector(); - set_output_type(0, image_et, {num_boxes, v[0], v[1], image_depth}); - } - else if (crop_size_et == element::i32) - { - auto v = crop_size_const->get_vector(); - set_output_type(0, image_et, {num_boxes, v[0], v[1], image_depth}); - } - else if (crop_size_et == element::u32) - { - auto v = crop_size_const->get_vector(); - set_output_type(0, image_et, {num_boxes, v[0], v[1], image_depth}); - } - else if (crop_size_et == element::i64) - { - auto v = crop_size_const->get_vector(); - set_output_type(0, image_et, {num_boxes, v[0], v[1], image_depth}); - } - else if (crop_size_et == element::u64) - { - auto v = crop_size_const->get_vector(); - set_output_type( - 0, - image_et, - {num_boxes, static_cast(v[0]), static_cast(v[1]), image_depth}); - } - else - { - NODE_VALIDATION_CHECK(this, false, "Unknown integral type for crop size"); - } -} - -shared_ptr op::CropAndResize::clone_with_new_inputs(const OutputVector& new_args) const -{ - check_new_args_count(this, new_args); - return make_shared(new_args.at(0), - new_args.at(1), - new_args.at(2), - new_args.at(3), - m_resize_method, - m_extrapolation_value); -} - -static const vector>& get_resize_pairs() -{ - static vector> pairs{ - {"unspecified", op::CropAndResize::ResizeMethod::unspecified}, - {"bilinear", op::CropAndResize::ResizeMethod::bilinear}, - {"nearest", op::CropAndResize::ResizeMethod::nearest}}; - return pairs; -} - -const string& ngraph::as_string(op::CropAndResize::ResizeMethod resize_method) -{ - for (auto& p : get_resize_pairs()) - { - if (p.second == resize_method) - { - return p.first; - } - } - throw ngraph_error("Internal error: unhandled resize method"); -} - -namespace ngraph -{ - template <> - op::CropAndResize::ResizeMethod as_type(const std::string& s) - { - for (auto& p : get_resize_pairs()) - { - if (p.first == s) - { - return p.second; - } - } - throw ngraph_error("Internal error: unhandled resize method name"); - } -} diff --git a/ngraph/src/ngraph/op/crop_and_resize.hpp b/ngraph/src/ngraph/op/crop_and_resize.hpp deleted file mode 100644 index 3601dd2..0000000 --- a/ngraph/src/ngraph/op/crop_and_resize.hpp +++ /dev/null @@ -1,83 +0,0 @@ -//***************************************************************************** -// 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 "ngraph/op/op.hpp" - -namespace ngraph -{ - namespace op - { - namespace v0 - { - class NGRAPH_API CropAndResize : public Op - { - public: - enum class ResizeMethod - { - unspecified, - bilinear, - nearest - }; - - static constexpr NodeTypeInfo type_info{"CropAndResize", 0}; - const NodeTypeInfo& get_type_info() const override { return type_info; } - /// \brief Constructs a crop and resize operation. - CropAndResize() = default; - - /// \param image [N, H, W, C] - /// \param boxes [NUM_BOXES, 4] where boxes[box] is [y1, x1, y2, x2] each in [0, 1] - /// \param box_indices [NUM_BOXES] in [0, N) - /// \param crop_size [crop_height, crop_width] - CropAndResize(const Output& image, - const Output& boxes, - const Output& box_indices, - const Output& crop_size, - ResizeMethod resize_method, - float extrapolation_value); - - void validate_and_infer_types() override; - - std::shared_ptr - clone_with_new_inputs(const OutputVector& new_args) const override; - - ResizeMethod get_resize_method() const { return m_resize_method; } - void set_resize_method(ResizeMethod resize_method) - { - m_resize_method = resize_method; - } - float get_extrapolation_value() const { return m_extrapolation_value; } - void set_extrapolation_value(float extrapolation_value) - { - m_extrapolation_value = extrapolation_value; - } - - private: - ResizeMethod m_resize_method{ResizeMethod::unspecified}; - float m_extrapolation_value{0}; - }; - } - using v0::CropAndResize; - } - - const std::string& as_string(op::CropAndResize::ResizeMethod); - template - T as_type(const std::string&); - - template <> - op::CropAndResize::ResizeMethod as_type(const std::string&); -} diff --git a/ngraph/src/ngraph/op/embedding_lookup.cpp b/ngraph/src/ngraph/op/embedding_lookup.cpp deleted file mode 100644 index 94cbf01..0000000 --- a/ngraph/src/ngraph/op/embedding_lookup.cpp +++ /dev/null @@ -1,60 +0,0 @@ -//***************************************************************************** -// 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. -//***************************************************************************** - -#include "ngraph/op/embedding_lookup.hpp" - -using namespace std; -using namespace ngraph; - -constexpr NodeTypeInfo op::EmbeddingLookup::type_info; - -void op::EmbeddingLookup::validate_and_infer_types() -{ - element::Type result_et = get_input_element_type(1); - - const PartialShape& arg0_shape = get_input_partial_shape(0); - const PartialShape& arg1_shape = get_input_partial_shape(1); - - NODE_VALIDATION_CHECK(this, - arg1_shape.rank().is_dynamic() || arg1_shape.rank().get_length() == 2, - "weights are expected to be a matrix"); - - PartialShape result_shape; - if (arg0_shape.rank().is_static()) - { - std::vector result_dims(arg0_shape.rank().get_length() + 1); - for (size_t i = 0; i < arg0_shape.rank().get_length(); i++) - { - result_dims[i] = arg0_shape[i]; - } - - result_dims[result_dims.size() - 1] = - arg1_shape.rank().is_static() ? arg1_shape[1] : Dimension::dynamic(); - result_shape = PartialShape(result_dims); - } - else - { - result_shape = PartialShape::dynamic(); - } - - set_output_type(0, result_et, result_shape); -} - -shared_ptr op::EmbeddingLookup::clone_with_new_inputs(const OutputVector& new_args) const -{ - check_new_args_count(this, new_args); - return make_shared(new_args.at(0), new_args.at(1)); -} diff --git a/ngraph/src/ngraph/op/embedding_lookup.hpp b/ngraph/src/ngraph/op/embedding_lookup.hpp deleted file mode 100644 index e72b577..0000000 --- a/ngraph/src/ngraph/op/embedding_lookup.hpp +++ /dev/null @@ -1,58 +0,0 @@ -//***************************************************************************** -// 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 "ngraph/axis_set.hpp" -#include "ngraph/op/util/index_reduction.hpp" - -namespace ngraph -{ - namespace op - { - namespace v0 - { - /// \brief Returns embeddings for given indices - class NGRAPH_API EmbeddingLookup : public Op - { - public: - static constexpr NodeTypeInfo type_info{"EmbeddingLookup", 0}; - const NodeTypeInfo& get_type_info() const override { return type_info; } - /// \brief Constructs a EmbeddingLookup operation. - EmbeddingLookup() = default; - /// \brief Constructs a EmbeddingLookup operation. - /// - /// EmbeddingLookup constructs an output tensor by replacing every index in a given - /// input tensor with a row (from the weights matrix) at that index - /// - /// \param data The input indices for tokens to be translated into embeddings - /// \param weights is a dense matrix [N,M] where each row 0..N - /// corresponds to an embedding (i.e. typically, a vector of real numbers) of length - /// M - EmbeddingLookup(const Output& data, const Output& weights) - : Op({data, weights}) - { - constructor_validate_and_infer_types(); - } - - void validate_and_infer_types() override; - virtual std::shared_ptr - clone_with_new_inputs(const OutputVector& new_args) const override; - }; - } - using v0::EmbeddingLookup; - } -} diff --git a/ngraph/src/ngraph/op/op_version_tbl.hpp b/ngraph/src/ngraph/op/op_version_tbl.hpp index 12fe09a..04fb7e2 100644 --- a/ngraph/src/ngraph/op/op_version_tbl.hpp +++ b/ngraph/src/ngraph/op/op_version_tbl.hpp @@ -58,7 +58,6 @@ NGRAPH_OP(ConvolutionBackpropData, ngraph::op::v0, 0) NGRAPH_OP(ConvolutionBackpropData, ngraph::op::v1, 1) NGRAPH_OP(Cos, ngraph::op::v0, 0) NGRAPH_OP(Cosh, ngraph::op::v0, 0) -NGRAPH_OP(CropAndResize, ngraph::op::v0, 0) NGRAPH_OP(CumSum, ngraph::op::v0, 0) NGRAPH_OP(DeformableConvolution, ngraph::op::v1, 1) NGRAPH_OP(DeformablePSROIPooling, ngraph::op::v1, 1) @@ -70,7 +69,6 @@ NGRAPH_OP(Divide, ngraph::op::v1, 1) NGRAPH_OP(Dot, ngraph::op::v0, 0) NGRAPH_OP(Elu, ngraph::op::v0, 0) NGRAPH_OP(EmbeddingBagOffsetsSum, ngraph::op::v3, 3) -NGRAPH_OP(EmbeddingLookup, ngraph::op::v0, 0) NGRAPH_OP(EmbeddingBagPackedSum, ngraph::op::v3, 3) NGRAPH_OP(EmbeddingSegmentsSum, ngraph::op::v3, 3) NGRAPH_OP(Equal, ngraph::op::v0, 0) diff --git a/ngraph/src/ngraph/ops.hpp b/ngraph/src/ngraph/ops.hpp index 312184f..c3e3aec 100644 --- a/ngraph/src/ngraph/ops.hpp +++ b/ngraph/src/ngraph/ops.hpp @@ -42,7 +42,6 @@ #include "ngraph/op/convolution.hpp" #include "ngraph/op/cos.hpp" #include "ngraph/op/cosh.hpp" -#include "ngraph/op/crop_and_resize.hpp" #include "ngraph/op/ctc_greedy_decoder.hpp" #include "ngraph/op/ctc_loss.hpp" #include "ngraph/op/cum_sum.hpp" @@ -53,7 +52,6 @@ #include "ngraph/op/divide.hpp" #include "ngraph/op/dot.hpp" #include "ngraph/op/elu.hpp" -#include "ngraph/op/embedding_lookup.hpp" #include "ngraph/op/embedding_segments_sum.hpp" #include "ngraph/op/embeddingbag_offsets_sum.hpp" #include "ngraph/op/embeddingbag_packedsum.hpp" diff --git a/ngraph/src/ngraph/runtime/reference/embedding_lookup.hpp b/ngraph/src/ngraph/runtime/reference/embedding_lookup.hpp deleted file mode 100644 index cd76dd6..0000000 --- a/ngraph/src/ngraph/runtime/reference/embedding_lookup.hpp +++ /dev/null @@ -1,50 +0,0 @@ -//***************************************************************************** -// 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 -#include - -#include "ngraph/coordinate_transform.hpp" -#include "ngraph/shape_util.hpp" - -namespace ngraph -{ - namespace runtime - { - namespace reference - { - template - void embedding(const U* indices, - const T* weights, - T* out, - size_t indices_count, - const Shape& out_shape) - { - size_t vec_len = out_shape.at(1); - T* out_iter = out; - for (size_t i = 0; i < indices_count; i++) - { - memcpy(out_iter, - &weights[vec_len * static_cast(indices[i])], - sizeof(T) * vec_len); - out_iter += vec_len; - } - } - } - } -} diff --git a/ngraph/src/ngraph/serializer.cpp b/ngraph/src/ngraph/serializer.cpp index 4fe9b3b..0c62509 100644 --- a/ngraph/src/ngraph/serializer.cpp +++ b/ngraph/src/ngraph/serializer.cpp @@ -1116,15 +1116,6 @@ shared_ptr JSONDeserializer::deserialize_node(json node_js) node = make_shared(args[0], args[1], exclusive, reverse); break; } - case OP_TYPEID::CropAndResize: - { - auto resize_method = - as_type(node_js.at("resize_method").get()); - auto extrapolation_value = node_js.at("extrapolation_value").get(); - node = make_shared( - args[0], args[1], args[2], args[3], resize_method, extrapolation_value); - break; - } case OP_TYPEID::CTCGreedyDecoder: { break; } case OP_TYPEID::DeformableConvolution_v1: @@ -1193,11 +1184,6 @@ shared_ptr JSONDeserializer::deserialize_node(json node_js) node = make_shared(args[0], alpha); break; } - case OP_TYPEID::EmbeddingLookup: - { - node = make_shared(args[0], args[1]); - break; - } case OP_TYPEID::Equal: { node = make_shared( @@ -2311,13 +2297,6 @@ json JSONSerializer::serialize_node(const Node& n) node["reverse"] = tmp->is_reverse(); break; } - case OP_TYPEID::CropAndResize: - { - auto tmp = static_cast(&n); - node["resize_method"] = as_string(tmp->get_resize_method()); - node["extrapolation_value"] = tmp->get_extrapolation_value(); - break; - } case OP_TYPEID::CTCGreedyDecoder: { break; } case OP_TYPEID::DetectionOutput: { break; @@ -2381,8 +2360,6 @@ json JSONSerializer::serialize_node(const Node& n) node["alpha"] = tmp->get_alpha(); break; } - case OP_TYPEID::EmbeddingLookup: { break; - } case OP_TYPEID::Equal: { const op::util::BinaryElementwiseComparison* tmp = nullptr; diff --git a/ngraph/test/CMakeLists.txt b/ngraph/test/CMakeLists.txt index 5952192..29968d5 100644 --- a/ngraph/test/CMakeLists.txt +++ b/ngraph/test/CMakeLists.txt @@ -121,7 +121,6 @@ set(SRC type_prop/constant.cpp type_prop/convert.cpp type_prop/convolution.cpp - type_prop/crop_and_resize.cpp type_prop/ctc_loss.cpp type_prop/deformable_psroi_pooling.cpp type_prop/depth_to_space.cpp @@ -131,7 +130,6 @@ set(SRC type_prop/strided_slice.cpp type_prop/elu.cpp type_prop/embeddingbag_offsetssum.cpp - type_prop/embedding_lookup.cpp type_prop/extractimagepatches.cpp type_prop/embeddingbag_packedsum.cpp type_prop/embedding_segments_sum.cpp @@ -299,7 +297,6 @@ set(MULTI_TEST_SRC backend/dyn_reshape.in.cpp backend/strided_slice.in.cpp backend/dynamic.in.cpp - backend/embedding_lookup.in.cpp backend/erf.in.cpp backend/exp.in.cpp backend/floor.in.cpp diff --git a/ngraph/test/backend/embedding_lookup.in.cpp b/ngraph/test/backend/embedding_lookup.in.cpp deleted file mode 100644 index 422d216..0000000 --- a/ngraph/test/backend/embedding_lookup.in.cpp +++ /dev/null @@ -1,134 +0,0 @@ -//***************************************************************************** -// 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. -//***************************************************************************** - -#include -#include -#include -#include -#include -#include - -#include "gtest/gtest.h" -#include "ngraph/ngraph.hpp" -#include "ngraph/op/embedding_lookup.hpp" -#include "ngraph/runtime/tensor.hpp" -#include "runtime/backend.hpp" -#include "util/all_close.hpp" -#include "util/all_close_f.hpp" -#include "util/ndarray.hpp" -#include "util/random.hpp" -#include "util/test_control.hpp" -#include "util/test_tools.hpp" - -using namespace std; -using namespace ngraph; - -static string s_manifest = "${MANIFEST}"; - -NGRAPH_TEST(${BACKEND_NAME}, embedding_lookup_4x5_reverse) -{ - Shape shape{4}; - Shape rshape{4, 5}; - auto A = make_shared(element::f32, shape); - auto B = make_shared(element::f32, rshape); - auto embed = make_shared(A, B); - auto f0 = make_shared(NodeVector{embed}, ParameterVector{A, B}); - - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - auto a = backend->create_tensor(element::f32, shape); - copy_data(a, vector{3, 2, 1, 0}); - auto b = backend->create_tensor(element::f32, rshape); - copy_data(b, - vector{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}); - auto result0 = backend->create_tensor(element::f32, rshape); - auto handle = backend->compile(f0); - handle->call_with_validate({result0}, {a, b}); - vector expected{16, 17, 18, 19, 20, 11, 12, 13, 14, 15, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5}; - EXPECT_TRUE(test::all_close_f(expected, read_vector(result0), MIN_FLOAT_TOLERANCE_BITS)); -} - -NGRAPH_TEST(${BACKEND_NAME}, embedding_lookup_10x1_arbitrary) -{ - Shape shape{10}; - Shape rshape{10, 1}; - auto A = make_shared(element::f32, shape); - auto B = make_shared(element::f32, rshape); - auto embed = make_shared(A, B); - auto f0 = make_shared(NodeVector{embed}, ParameterVector{A, B}); - - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - auto a = backend->create_tensor(element::f32, shape); - copy_data(a, vector{9, 2, 1, 0, 3, 5, 4, 6, 8, 7}); - auto b = backend->create_tensor(element::f32, rshape); - copy_data(b, vector{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}); - auto result0 = backend->create_tensor(element::f32, rshape); - auto handle = backend->compile(f0); - handle->call_with_validate({result0}, {a, b}); - vector expected{9, 2, 1, 0, 3, 5, 4, 6, 8, 7}; - EXPECT_TRUE(test::all_close_f(expected, read_vector(result0), MIN_FLOAT_TOLERANCE_BITS)); -} - -NGRAPH_TEST(${BACKEND_NAME}, embedding_lookup_10x1_arbitrary_index_type_int) -{ - Shape shape{10}; - Shape rshape{10, 1}; - auto A = make_shared(element::i32, shape); - auto B = make_shared(element::f32, rshape); - auto embed = make_shared(A, B); - auto f0 = make_shared(NodeVector{embed}, ParameterVector{A, B}); - - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - auto a = backend->create_tensor(element::i32, shape); - copy_data(a, vector{9, 2, 1, 0, 3, 5, 4, 6, 8, 7}); - auto b = backend->create_tensor(element::f32, rshape); - copy_data(b, vector{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5}); - auto result0 = backend->create_tensor(element::f32, rshape); - auto handle = backend->compile(f0); - handle->call_with_validate({result0}, {a, b}); - // vector expected{9.5, 2.5, 1.5, 0.5, 3.5, 5.5, 4.5, 6.5, 8.5, 7.5}; - vector expected{9.5, 2.5, 1.5, 0.5, 3.5, 5.5, 4.5, 6.5, 8.5, 7.5}; - EXPECT_TRUE(test::all_close_f(expected, read_vector(result0), MIN_FLOAT_TOLERANCE_BITS)); -} - -NGRAPH_TEST(${BACKEND_NAME}, embedding_lookup_10x1_arbitrary_index_type_int64) -{ - Shape shape{10}; - Shape rshape{10, 1}; - auto A = make_shared(element::i64, shape); - auto B = make_shared(element::f32, rshape); - auto embed = make_shared(A, B); - auto f0 = make_shared(NodeVector{embed}, ParameterVector{A, B}); - - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - auto a = backend->create_tensor(element::i64, shape); - copy_data(a, vector{9, 2, 1, 0, 3, 5, 4, 6, 8, 7}); - auto b = backend->create_tensor(element::f32, rshape); - copy_data(b, vector{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5}); - auto result0 = backend->create_tensor(element::f32, rshape); - auto handle = backend->compile(f0); - handle->call_with_validate({result0}, {a, b}); - // vector expected{9.5, 2.5, 1.5, 0.5, 3.5, 5.5, 4.5, 6.5, 8.5, 7.5}; - vector expected{9.5, 2.5, 1.5, 0.5, 3.5, 5.5, 4.5, 6.5, 8.5, 7.5}; - EXPECT_TRUE(test::all_close_f(expected, read_vector(result0), MIN_FLOAT_TOLERANCE_BITS)); -} diff --git a/ngraph/test/op_is.cpp b/ngraph/test/op_is.cpp index db754b1..ab319b1 100644 --- a/ngraph/test/op_is.cpp +++ b/ngraph/test/op_is.cpp @@ -196,15 +196,6 @@ namespace EXPECT_FALSE(op::is_binary_elementwise_logical(&node)); } - void op_is_CropAndResize() - { - op::CropAndResize node; - EXPECT_FALSE(op::is_unary_elementwise_arithmetic(&node)); - EXPECT_FALSE(op::is_binary_elementwise_arithmetic(&node)); - EXPECT_FALSE(op::is_binary_elementwise_comparison(&node)); - EXPECT_FALSE(op::is_binary_elementwise_logical(&node)); - } - void op_is_CumSum() { op::CumSum node; @@ -277,15 +268,6 @@ namespace EXPECT_FALSE(op::is_binary_elementwise_logical(&node)); } - void op_is_EmbeddingLookup() - { - op::EmbeddingLookup node; - EXPECT_FALSE(op::is_unary_elementwise_arithmetic(&node)); - EXPECT_FALSE(op::is_binary_elementwise_arithmetic(&node)); - EXPECT_FALSE(op::is_binary_elementwise_comparison(&node)); - EXPECT_FALSE(op::is_binary_elementwise_logical(&node)); - } - void op_is_EmbeddingSegmentsSum() { op::EmbeddingSegmentsSum node; diff --git a/ngraph/test/runtime/ie/unit_test.manifest b/ngraph/test/runtime/ie/unit_test.manifest index c0a0b8e..a3b9f52 100644 --- a/ngraph/test/runtime/ie/unit_test.manifest +++ b/ngraph/test/runtime/ie/unit_test.manifest @@ -809,12 +809,6 @@ onnx_model_quant_conv_linear onnx_model_quant_conv_linear_2d onnx_model_quant_conv_linear_3d -# Cannot cast ngraph node EmbeddingLookup to CNNLayer! -embedding_lookup_4x5_reverse -embedding_lookup_10x1_arbitrary -embedding_lookup_10x1_arbitrary_index_type_int -embedding_lookup_10x1_arbitrary_index_type_int64 - # Cannot cast ngraph node Dot to CNNLayer! dot_4d_5d_multi_axis dot_4d_5d_multi_axis_more diff --git a/ngraph/test/runtime/interpreter/int_executable.hpp b/ngraph/test/runtime/interpreter/int_executable.hpp index edc0fc4..55a4f99 100644 --- a/ngraph/test/runtime/interpreter/int_executable.hpp +++ b/ngraph/test/runtime/interpreter/int_executable.hpp @@ -50,7 +50,6 @@ #include "ngraph/runtime/reference/elu.hpp" #include "ngraph/runtime/reference/embedding_bag_offsets_sum.hpp" #include "ngraph/runtime/reference/embedding_bag_packed_sum.hpp" -#include "ngraph/runtime/reference/embedding_lookup.hpp" #include "ngraph/runtime/reference/embedding_segments_sum.hpp" #include "ngraph/runtime/reference/erf.hpp" #include "ngraph/runtime/reference/exp.hpp" @@ -472,51 +471,6 @@ protected: dot->get_reduction_axes_count()); break; } - case OP_TYPEID::EmbeddingLookup: - { - const op::EmbeddingLookup* embed = static_cast(&node); - auto type = embed->input(0).get_element_type(); - size_t element_count = shape_size(embed->get_input_shape(0)); - - if (type == element::f32) - { - reference::embedding(args[0]->get_data_ptr(), - args[1]->get_data_ptr(), - out[0]->get_data_ptr(), - element_count, - embed->get_shape()); - } - else if (type == element::f64) - { - reference::embedding(args[0]->get_data_ptr(), - args[1]->get_data_ptr(), - out[0]->get_data_ptr(), - element_count, - embed->get_shape()); - } - else if (type == element::i32) - { - reference::embedding(args[0]->get_data_ptr(), - args[1]->get_data_ptr(), - out[0]->get_data_ptr(), - element_count, - embed->get_shape()); - } - else if (type == element::i64) - { - reference::embedding(args[0]->get_data_ptr(), - args[1]->get_data_ptr(), - out[0]->get_data_ptr(), - element_count, - embed->get_shape()); - } - else - { - throw ngraph_error(std::string("Unsupported index type ") + type.c_type_string() + - std::string(" in EmbeddingLookup")); - } - break; - } case OP_TYPEID::EmbeddingBagOffsetsSum_v3: { const op::EmbeddingBagOffsetsSum* embed = @@ -1208,7 +1162,6 @@ protected: } // Fused Ops are not supported in interpreter. They need to be decomposed before execution - case OP_TYPEID::CropAndResize: case OP_TYPEID::DepthToSpace: case OP_TYPEID::FakeQuantize: case OP_TYPEID::Gather: diff --git a/ngraph/test/runtime/opset0_tbl.hpp b/ngraph/test/runtime/opset0_tbl.hpp index 1526f73..5a40ecd 100644 --- a/ngraph/test/runtime/opset0_tbl.hpp +++ b/ngraph/test/runtime/opset0_tbl.hpp @@ -69,14 +69,12 @@ NGRAPH_OP(Convolution, ngraph::op) NGRAPH_OP(ConvolutionBackpropData, ngraph::op) NGRAPH_OP(Cos, ngraph::op) NGRAPH_OP(Cosh, ngraph::op) -NGRAPH_OP(CropAndResize, ngraph::op) NGRAPH_OP(CumSum, ngraph::op::v0) NGRAPH_OP(DepthToSpace, ngraph::op) NGRAPH_OP(Dequantize, ngraph::op) NGRAPH_OP(Divide, ngraph::op) NGRAPH_OP(Dot, ngraph::op) NGRAPH_OP(Elu, ngraph::op) -NGRAPH_OP(EmbeddingLookup, ngraph::op) NGRAPH_OP(Equal, ngraph::op) NGRAPH_OP(Erf, ngraph::op) NGRAPH_OP(Exp, ngraph::op) diff --git a/ngraph/test/type_prop/crop_and_resize.cpp b/ngraph/test/type_prop/crop_and_resize.cpp deleted file mode 100644 index 23a7262..0000000 --- a/ngraph/test/type_prop/crop_and_resize.cpp +++ /dev/null @@ -1,81 +0,0 @@ -//***************************************************************************** -// 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. -//***************************************************************************** - -#include "gtest/gtest.h" -#include "ngraph/ngraph.hpp" -#include "util/type_prop.hpp" - -using namespace std; -using namespace ngraph; - -TEST(type_prop, crop_and_resize_valid) -{ - Dimension N = 4; - Dimension W_image = 400; - Dimension H_image = 300; - Dimension C_image = 3; - Dimension num_boxes = 20; - int32_t W_crop = 30; - int32_t H_crop = 40; - - PartialShape result_shape{num_boxes, H_crop, W_crop, C_image}; - - auto image = - make_shared(element::f32, PartialShape{N, H_image, W_image, C_image}); - auto boxes = make_shared(element::f32, PartialShape{num_boxes, 4}); - auto box_indices = make_shared(element::i32, PartialShape{num_boxes}); - auto crop_shape = op::Constant::create(element::i32, Shape{2}, {H_crop, W_crop}); - - auto crop_and_resize = make_shared( - image, boxes, box_indices, crop_shape, op::CropAndResize::ResizeMethod::bilinear, 0); - auto result = crop_and_resize->output(0); - ASSERT_EQ(result.get_shape(), result_shape.to_shape()); - ASSERT_EQ(result.get_element_type(), image->get_output_element_type(0)); -} - -TEST(type_prop, crop_and_resize_not_constant) -{ - Dimension N = 4; - Dimension W_image = 400; - Dimension H_image = 300; - Dimension C_image = 3; - Dimension num_boxes = 20; - int32_t W_crop = 30; - int32_t H_crop = 40; - - PartialShape result_shape{num_boxes, H_crop, W_crop, C_image}; - - auto image = - make_shared(element::f32, PartialShape{N, H_image, W_image, C_image}); - auto boxes = make_shared(element::f32, PartialShape{num_boxes, 4}); - auto box_indices = make_shared(element::i32, PartialShape{num_boxes}); - auto crop_shape = make_shared(element::i32, PartialShape{2}); - - try - { - auto crop_and_resize = make_shared( - image, boxes, box_indices, crop_shape, op::CropAndResize::ResizeMethod::bilinear, 0); - FAIL() << "CropAndReshape without constant crop shape should fail"; - } - catch (const NodeValidationFailure& error) - { - EXPECT_HAS_SUBSTRING(error.what(), std::string("crop_size must be a constant")); - } - catch (...) - { - FAIL() << "Deduced type check failed for unexpected reason"; - } -} diff --git a/ngraph/test/type_prop/embedding_lookup.cpp b/ngraph/test/type_prop/embedding_lookup.cpp deleted file mode 100644 index 656902d..0000000 --- a/ngraph/test/type_prop/embedding_lookup.cpp +++ /dev/null @@ -1,80 +0,0 @@ -//***************************************************************************** -// 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. -//***************************************************************************** - -#include "gtest/gtest.h" -#include "ngraph/ngraph.hpp" -#include "util/type_prop.hpp" - -using namespace std; -using namespace ngraph; - -TEST(type_prop, embedding_lookup_non_matrix_weights) -{ - auto tv0_2_4_param_0 = make_shared(element::boolean, Shape{2, 4}); - auto tv0_2_4_param_1 = make_shared(element::boolean, Shape{2, 4, 5}); - try - { - auto bc = make_shared(tv0_2_4_param_0, tv0_2_4_param_1); - // Should have thrown, so fail if it didn't - FAIL() << "Did not detect incorrect element types for arithmetic operator"; - } - catch (const NodeValidationFailure& error) - { - EXPECT_HAS_SUBSTRING(error.what(), std::string("weights are expected to be a matrix")); - } - catch (...) - { - FAIL() << "Deduced type check failed for unexpected reason"; - } -} - -TEST(type_prop, embedding_lookup_static_shapes) -{ - auto data = make_shared(element::f32, Shape{8, 10, 12}); - auto weights = make_shared(element::f32, Shape{5, 10}); - auto embed = make_shared(data, weights); - ASSERT_EQ(embed->get_element_type(), element::f32); - ASSERT_EQ(embed->get_shape(), (Shape{8, 10, 12, 10})); -} - -TEST(type_prop, embedding_lookup_dynamic_shape_arg0) -{ - auto data = make_shared(element::f32, PartialShape::dynamic()); - auto weights = make_shared(element::f32, Shape{5, 10}); - auto embed = make_shared(data, weights); - ASSERT_EQ(embed->get_element_type(), element::f32); - ASSERT_TRUE(embed->get_output_partial_shape(0).rank().is_dynamic()); -} - -TEST(type_prop, embedding_lookup_dynamic_shape_arg1) -{ - auto data = make_shared(element::f32, Shape{8, 10, 12}); - auto weights = make_shared(element::f32, PartialShape::dynamic()); - auto embed = make_shared(data, weights); - ASSERT_EQ(embed->get_element_type(), element::f32); - PartialShape expected{8, 10, 12, Dimension::dynamic()}; - ASSERT_TRUE(embed->get_output_partial_shape(0).same_scheme(expected)); -} - -TEST(type_prop, embedding_lookup_shape_arg1_dynamic_embedding_length) -{ - auto data = make_shared(element::f32, Shape{8, 10, 12}); - auto weights = make_shared(element::f32, PartialShape{5, Dimension::dynamic()}); - auto embed = make_shared(data, weights); - ASSERT_EQ(embed->get_element_type(), element::f32); - PartialShape expected{8, 10, 12, Dimension::dynamic()}; - ASSERT_TRUE(embed->get_output_partial_shape(0).same_scheme(expected)); -}