导入自定义模块时出现Python ModuleNotFoundError

问题描述 投票:0回答:1

我目前正在使用 Python 开发一个对象检测项目,并在尝试从

ModuleNotFoundError
导入自定义模块
Detections
BoxAnnotator
时遇到
'supervision.tools.detections'
问题。我面临的错误消息如下:

Traceback (most recent call last):
  File "/Users/yahyahajali/Python/ComputerVision-master/yolov8.py", line 8, in <module>
    from supervision.tools.detections import Detections, BoxAnnotator
ModuleNotFoundError: No module named 'supervision.tools'

我正在使用 Python、Torch 和 OpenCV 编写一个对象检测脚本。 检测和 BoxAnnotator 类应该从名为“supervision.tools.detections”的自定义模块导入。 然而,尽管有这些模块,我还是遇到了 ModuleNotFoundError。

这是代码片段

import torch
import numpy as np
import cv2
from time import time
from ultralytics import YOLO

from supervision.draw.color import ColorPalette
from supervision.tools.detections import Detections, BoxAnnotator
python machine-learning computer-vision artificial-intelligence object-detection-api
1个回答
0
投票

尝试

from supervision import Detections, BoxAnnotator

来自官方仓库:

>>> from ultralytics import YOLO
>>> from supervision import Detections

>>> model = YOLO('yolov8s.pt')
>>> yolov8_results = model(IMAGE)[0]
>>> detections = Detections.from_yolov8(yolov8_results)
© www.soinside.com 2019 - 2024. All rights reserved.