diff --git a/src/frontends/pytorch/src/op/adaptive_poolnd.cpp b/src/frontends/pytorch/src/op/adaptive_poolnd.cpp index a8b748a29b5..1288f1402e7 100644 --- a/src/frontends/pytorch/src/op/adaptive_poolnd.cpp +++ b/src/frontends/pytorch/src/op/adaptive_poolnd.cpp @@ -12,6 +12,7 @@ #include "openvino/op/shape_of.hpp" #include "openvino/op/slice.hpp" #include "openvino/op/tile.hpp" +#include "openvino/op/unsqueeze.hpp" #include "utils.hpp" namespace ov { @@ -39,13 +40,37 @@ std::tuple, Output> get_tile_input_and_output_shape(const Nod return std::make_tuple(tile, output_shape); }; +Output get_given_shape(const NodeContext& context) { + Output given_shape; + auto shape_type = context.get_input_type(1); + if (shape_type.is()) { + const auto list_elems = get_list_as_outputs(context.get_input(1)); + if (list_elems.size() == 1) { + given_shape = get_input_as_i32(context, 1); + } else { + OutputVector to_concat; + auto zero = v0::Constant::create(element::i32, Shape{}, {0}); + for (auto elem : list_elems) { + if (elem.get_element_type() != element::i32) { + elem = context.mark_node(std::make_shared(elem, element::i32)); + } + to_concat.push_back(context.mark_node(std::make_shared(elem, zero))); + } + given_shape = context.mark_node(std::make_shared(to_concat, 0)); + } + } else { + given_shape = get_input_as_i32(context, 1); + } + return given_shape; +} + OutputVector translate_adaptive_avg_pool_base(const NodeContext& context, const Output& tile_shape, const Output& slice_end) { num_inputs_check(context, 2, 2); auto input_tensor = context.get_input(0); - auto given_shape = get_input_as_i32(context, 1); + Output given_shape = get_given_shape(context); Output tile_input; Output output_shape; std::tie(tile_input, output_shape) = @@ -61,7 +86,7 @@ OutputVector translate_adaptive_max_pool_base(const NodeContext& context, num_inputs_check(context, 2, 2); auto input_tensor = context.get_input(0); - auto given_shape = get_input_as_i32(context, 1); + Output given_shape = get_given_shape(context); Output tile_input; Output output_shape; std::tie(tile_input, output_shape) = @@ -71,7 +96,7 @@ OutputVector translate_adaptive_max_pool_base(const NodeContext& context, context.mark_node(std::make_shared(tile_input, given_shape, element::i32)); auto pooled_tensor = adaptive_max_pool->output(0); auto pooled_indices = adaptive_max_pool->output(1); - // adaptive max pool in torch return indices in i64, indices_element_type i64 is not implented on ov runtime side + // adaptive max pool in torch return indices in i64, indices_element_type i64 is not implemented on ov runtime side pooled_indices = context.mark_node(std::make_shared(pooled_indices, element::i64)); pooled_tensor = context.mark_node(std::make_shared(pooled_tensor, output_shape, false)); pooled_indices = context.mark_node(std::make_shared(pooled_indices, output_shape, false)); diff --git a/tests/model_hub_tests/pytorch/requirements.txt b/tests/model_hub_tests/pytorch/requirements.txt index 7063bc75849..b41978a0b2e 100644 --- a/tests/model_hub_tests/pytorch/requirements.txt +++ b/tests/model_hub_tests/pytorch/requirements.txt @@ -4,6 +4,7 @@ auto-gptq>=0.5.1 av basicsr datasets +easyocr facexlib numpy optimum diff --git a/tests/model_hub_tests/pytorch/test_easyocr.py b/tests/model_hub_tests/pytorch/test_easyocr.py new file mode 100644 index 00000000000..602b9e5160b --- /dev/null +++ b/tests/model_hub_tests/pytorch/test_easyocr.py @@ -0,0 +1,32 @@ +# Copyright (C) 2018-2024 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +import pytest +import torch + +from torch_utils import TestTorchConvertModel + +# To make tests reproducible we seed the random generator +torch.manual_seed(0) + + +class TestEasyOCRConvertModel(TestTorchConvertModel): + def load_model(self, model_name, model_link): + import easyocr + if model_name == "detector": + model = easyocr.Reader(["en"], quantize=False).detector + self.example = (torch.rand(1, 3, 608, 800),) + self.inputs = (torch.rand(1, 3, 608, 800),) + elif model_name == "recognizer": + model = easyocr.Reader(["en"], quantize=False).recognizer + self.example = (torch.rand(1, 1, 64, 320), torch.rand(1, 33)) + self.inputs = (torch.rand(1, 1, 64, 320), torch.rand(1, 33)) + else: + raise RuntimeError("Unknown model type") + return model + + @pytest.mark.precommit + @pytest.mark.nightly + @pytest.mark.parametrize("name", ["detector", "recognizer"]) + def test_convert_model(self, name, ie_device): + self.run(name, None, ie_device)