[PT FE] Fix regression in easyocr model (#24586)

### Details:
- *After support for i64 was added in frontend `aten::adaptive_avg_pool`
started to fail if shape input is list.*

### Tickets:
 - *CVS-141335*
This commit is contained in:
Maxim Vafin 2024-05-20 18:51:30 +02:00 committed by GitHub
parent 474a77a125
commit e9d42dd60b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 61 additions and 3 deletions

View File

@ -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<Node>, Output<Node>> get_tile_input_and_output_shape(const Nod
return std::make_tuple(tile, output_shape);
};
Output<Node> get_given_shape(const NodeContext& context) {
Output<Node> given_shape;
auto shape_type = context.get_input_type(1);
if (shape_type.is<type::List>()) {
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<v0::Convert>(elem, element::i32));
}
to_concat.push_back(context.mark_node(std::make_shared<v0::Unsqueeze>(elem, zero)));
}
given_shape = context.mark_node(std::make_shared<v0::Concat>(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<Node>& tile_shape,
const Output<Node>& 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<Node> given_shape = get_given_shape(context);
Output<Node> tile_input;
Output<Node> 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<Node> given_shape = get_given_shape(context);
Output<Node> tile_input;
Output<Node> 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<v8::AdaptiveMaxPool>(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<v0::Convert>(pooled_indices, element::i64));
pooled_tensor = context.mark_node(std::make_shared<v1::Reshape>(pooled_tensor, output_shape, false));
pooled_indices = context.mark_node(std::make_shared<v1::Reshape>(pooled_indices, output_shape, false));

View File

@ -4,6 +4,7 @@ auto-gptq>=0.5.1
av
basicsr
datasets
easyocr
facexlib
numpy
optimum

View File

@ -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)