朋友们,我正在 Phytec 板上编程。我正在尝试使用 Ultralytics 运行程序代码。我在本地安装库,即在系统的根目录中。它无法加载库。
错误代码:
Traceback (most recent call last):
File "/root/test_2.py", line 5, in <module>
from ultralytics import YOLO
File "/root/Ultralytics/ultralytics/__init__.py", line 10, in <module>
from ultralytics.data.explorer.explorer import Explorer
File "/root/Ultralytics/ultralytics/data/__init__.py", line 3, in <module>
from .base import BaseDataset
File "/root/Ultralytics/ultralytics/data/base.py", line 15, in <module>
from torch.utils.data import Dataset
ModuleNotFoundError: No module named 'torch.utils'
部分代码:
import cv2
import time
import sys
sys.path.append('/root/Ultralytics')
from ultralytics import YOLO
import torch
print(torch.__version__)
# Reading a video file
vid = cv2.VideoCapture('/media/andrei/Linux_dir/Analytics/YoloNew/p.mp4')
# Loading the YOLOv8n model
model = YOLO("yolov8n.pt")
# Specifying the "person" class
person_class_index = 0 # The 'person' class in the COCO dataset has ID = 0
# Initializing variables for frame and time
f = 0
t = 0
h, w = None, None
writer = None
....
我尝试单独安装Torch.Utils,但没有帮助
首先你需要安装火炬:
对于CPU
pip install torch torchvision torchaudio
然后:
import torch
from torch.utils.data import Dataset
如果你想使用
ultralytics
你可以这样做:
from ultralytics.data.dataset import Dataset