openvino icon indicating copy to clipboard operation
openvino copied to clipboard

[Build]: get_input_tensor() must be called on a function with exactly one parameter

Open Alex37882388 opened this issue 1 year ago • 4 comments

OpenVINO Version

2023.3.0

Operating System

Windows System

Hardware Architecture

x86 (64 bits)

Target Platform

设备名称 DESKTOP-ULOARD0 处理器 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz 2.80 GHz 机带 RAM 16.0 GB (15.7 GB 可用) 设备 ID 660EB58B-37BC-471B-89BE-F7014C3473DA 产品 ID 00329-00000-00003-AA553 系统类型 64 位操作系统, 基于 x64 的处理器 笔和触控 没有可用于此显示器的笔或触控输入

Build issue description

I tried to use the yolo model to complete the image detection and cutting task, but I got an error when inferring. I refer to #15902 but apparently not the same issue.

Build scrip or step-by-step to reproduce

import cv2
import numpy as np
from openvino.runtime import Core
from typing import List, Tuple


def letterbox(img: np.ndarray, new_shape: Tuple[int, int] = (640, 640), color: Tuple[int, int, int] = (114, 114, 114), auto: bool = False,
              scale_fill: bool = False, scaleup: bool = False, stride: int = 32):
    shape = img.shape[:2]
    if isinstance(new_shape, int):
        new_shape = (new_shape, new_shape)

    r = min(new_shape[0] / shape[0], new_shape[1] / shape[1])
    if not scaleup:
        r = min(r, 1.0)

    ratio = r, r  # width, height ratios
    new_unpad = int(round(shape[1] * r)), int(round(shape[0] * r))
    dw, dh = new_shape[1] - new_unpad[0], new_shape[0] - new_unpad[1]  # wh padding
    if auto:  # minimum rectangle
        dw, dh = np.mod(dw, stride), np.mod(dh, stride)  # wh padding
    elif scale_fill:  # stretch
        dw, dh = 0.0, 0.0
        new_unpad = (new_shape[1], new_shape[0])
        ratio = new_shape[1] / shape[1], new_shape[0] / shape[0]  # width, height ratios

    dw /= 2  # divide padding into 2 sides
    dh /= 2

    if shape[::-1] != new_unpad:  # resize
        img = cv2.resize(img, new_unpad, interpolation=cv2.INTER_LINEAR)
    top, bottom = int(round(dh - 0.1)), int(round(dh + 0.1))
    left, right = int(round(dw - 0.1)), int(round(dw + 0.1))
    img = cv2.copyMakeBorder(img, top, bottom, left, right, cv2.BORDER_CONSTANT, value=color)  # add border
    return img, ratio, (dw, dh)


def preprocess_image(img0: np.ndarray):
    img = letterbox(img0)[0]

    img = img.transpose(2, 0, 1)
    img = np.ascontiguousarray(img)
    return img


def image_to_tensor(image: np.ndarray):
    input_tensor = image.astype(np.float32)  # uint8 to fp32
    input_tensor /= 255.0  # 0 - 255 to 0.0 - 1.0

    if input_tensor.ndim == 3:
        input_tensor = np.expand_dims(input_tensor, 0)
    return input_tensor


models_path = "/data/models/multiple_invocie_yolox_l_300e_coco_bak_20230814"
ov_model_path = f"{models_path}/openvino.xml"

core = Core()
ov_model_ir = core.read_model(ov_model_path)
model = core.compile_model(ov_model_ir, device_name="CPU")

input_image = cv2.imread("/data/sec_001.png")
preprocessed_image = preprocess_image(input_image)
input_tensor = image_to_tensor(preprocessed_image)

results = model(input_tensor)

Relevant log output

Traceback (most recent call last):
  File "D:\dl\ppp\topdp-serve-ocr\test\test22.py", line 66, in <module>
    results = model(input_tensor)
  File "D:\Users\topnet\miniconda3\lib\site-packages\openvino\runtime\ie_api.py", line 387, in __call__
    return self._infer_request.infer(
  File "D:\Users\topnet\miniconda3\lib\site-packages\openvino\runtime\ie_api.py", line 144, in infer
    return OVDict(super().infer(_data_dispatch(
  File "D:\Users\topnet\miniconda3\lib\site-packages\openvino\runtime\utils\data_helpers\data_dispatcher.py", line 426, in _data_dispatch
    return create_shared(inputs, request) if is_shared else create_copied(inputs, request)
  File "D:\Users\topnet\miniconda3\lib\functools.py", line 875, in wrapper
    return dispatch(args[0].__class__)(*args, **kw)
  File "D:\Users\topnet\miniconda3\lib\site-packages\openvino\runtime\utils\data_helpers\data_dispatcher.py", line 241, in _
    return value_to_tensor(request._inputs_data, request=request, is_shared=True)
  File "D:\Users\topnet\miniconda3\lib\functools.py", line 875, in wrapper
    return dispatch(args[0].__class__)(*args, **kw)
  File "D:\Users\topnet\miniconda3\lib\site-packages\openvino\runtime\utils\data_helpers\data_dispatcher.py", line 71, in _
    tensor = get_request_tensor(request, key)
  File "D:\Users\topnet\miniconda3\lib\site-packages\openvino\runtime\utils\data_helpers\data_dispatcher.py", line 35, in get_request_tensor
    return request.get_input_tensor()
RuntimeError: Exception from src\inference\src\infer_request.cpp:218:
Check 'inputs.size() == 1' failed at src\inference\src\infer_request.cpp:218:
get_input_tensor() must be called on a function with exactly one parameter.

Issue submission checklist

  • [X] I'm reporting an issue. It's not a question.
  • [X] I checked the problem with the documentation, FAQ, open issues, Stack Overflow, etc., and have not found a solution.

Alex37882388 avatar Feb 18 '24 02:02 Alex37882388

@zhaixuejun1993 Can you help take a look? Thanks!

wenjiew avatar Feb 18 '24 03:02 wenjiew

Add models and parameter files for your reference. paddle_yolox_l_300e_coco.zip 是不是什么算子不支持导致报错的咧?

Alex37882388 avatar Feb 19 '24 08:02 Alex37882388

Add models and parameter files for your reference. paddle_yolox_l_300e_coco.zip 是不是什么算子不支持导致报错的咧?

Thanks for sharing the models, will take a look now

zhaixuejun1993 avatar Feb 20 '24 01:02 zhaixuejun1993

@first236108 Seems the model you used with multi inputs, so the using of request.get_input_tensor() will throw exception, as following: https://github.com/openvinotoolkit/openvino/blob/b8c3bae71e6d3417ade5cb537cb1785fd75a75c8/src/bindings/python/src/pyopenvino/core/infer_request.cpp#L427-L439 Pls use this replace: https://github.com/openvinotoolkit/openvino/blob/b8c3bae71e6d3417ade5cb537cb1785fd75a75c8/src/bindings/python/src/pyopenvino/core/infer_request.cpp#L410-L426

zhaixuejun1993 avatar Feb 20 '24 01:02 zhaixuejun1993

@first236108 Does Xuejun's answer address the issue?

peterchen-intel avatar Feb 28 '24 05:02 peterchen-intel

Closed this issue since there is no new requests.

peterchen-intel avatar Jun 02 '24 14:06 peterchen-intel