Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't test on single image with model yolov8 #2004

Closed
DungHD-1997 opened this issue May 8, 2024 · 1 comment
Closed

Can't test on single image with model yolov8 #2004

DungHD-1997 opened this issue May 8, 2024 · 1 comment

Comments

@DungHD-1997
Copy link

DungHD-1997 commented May 8, 2024

Describe the bug

AttributeError: 'NoneType' object has no attribute 'infer'
I understand that there does not exist attribute infer from yolo code but why can the tutorial output the results?

Environment information
my environment information:

      - jinja2==3.1.4
      - jupyterlab-widgets==3.0.10
      - kiwisolver==1.4.5
      - markupsafe==2.1.5
      - matplotlib==3.8.4
      - matplotlib-inline==0.1.7
      - mkl==2021.4.0
      - mpmath==1.3.0
      - networkx==3.3
      - numpy==1.26.4
      - onnx==1.16.0
      - opencv-python==4.9.0.80
      - openvino==2024.1.0
      - openvino-telemetry==2024.1.0
      - packaging==24.0
      - pandas==2.2.2
      - parso==0.8.4
      - pillow==10.3.0
      - prompt-toolkit==3.0.43
      - protobuf==5.26.1
      - psutil==5.9.8
      - pure-eval==0.2.2
      - py-cpuinfo==9.0.0
      - pygments==2.18.0
      - pyparsing==3.1.2
      - python-dateutil==2.9.0.post0
      - pytz==2024.1
      - pyyaml==6.0.1
      - requests==2.31.0
      - scipy==1.13.0
      - seaborn==0.13.2
      - six==1.16.0
      - stack-data==0.6.3
      - sympy==1.12
      - tbb==2021.12.0
      - thop==0.1.1-2209072238
      - torch==2.3.0+cpu
      - torchvision==0.18.0+cpu
      - tqdm==4.66.4
      - traitlets==5.14.3
      - typing-extensions==4.11.0
      - tzdata==2024.1
      - ultralytics==8.1.42
      - urllib3==2.2.1
      - wcwidth==0.2.13
      - widgetsnbextension==4.0.10

My code is based on instructions from the following website:
https://docs.openvino.ai/2024/notebooks/yolov8-object-detection-with-output.html#test-on-single-image

import ipywidgets as widgets
import openvino as ov

from PIL import Image
from ultralytics import YOLO

models_dir = "C:/Project/result_train/yolov8/clean_data_obj/weights/best.pt"
det_model = YOLO(models_dir)
label_map = det_model.model.names

IMAGE_PATH = "C:/Project/test_img_truck/image_2023-12-25_07z37z31.jpg"
core = ov.Core()
device = widgets.Dropdown(
    options=core.available_devices + ["AUTO"],
    value="AUTO",
    description="Device:",
    disabled=False,
)
import torch
core = ov.Core()
det_model_path = "C:/Project/result_train/yolov8/clean_data_obj/weights/best_openvino_model/best.xml"
det_ov_model = core.read_model(det_model_path)

ov_config = {}
if device.value != "CPU":
    det_ov_model.reshape({0: [1, 3, 640, 640]})
if "GPU" in device.value or ("AUTO" in device.value and "GPU" in core.available_devices):
    ov_config = {"GPU_DISABLE_WINOGRAD_CONVOLUTION": "YES"}
det_compiled_model = core.compile_model(det_ov_model, device.value, ov_config)

def infer(*args):
    result = det_compiled_model(args)
    return torch.from_numpy(result[0])

det_model.predictor.infer = infer
det_model.predict.model.pt = False

res = det_model(IMAGE_PATH)
# Image.fromarray(res[0].plot()[:, :, ::-1])
for i, r in enumerate(res):
    # Plot results image
    im_bgr = r.plot()  # BGR-order numpy array
    im_rgb = Image.fromarray(im_bgr[..., ::-1])  # RGB-order PIL image

    # Show results to screen (in supported environments)
    r.show()
@DungHD-1997
Copy link
Author

I changed my code according to the instructions here:
https://github.com/openvinotoolkit/openvino_notebooks/blob/main/notebooks/230-yolov8-optimization/230-yolov8-object-detection.ipynb
it worked!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants