yolov8训练环境安装一些坑

安装环境

不能使用conda安装pytorch,如果使用安装的conda可以让torch.cuda.is_available()为true,但是Ultralytics YOLOv8 还是显示无法使用GPU!

  1. 在虚拟环境安装yolov8,并激活
  2. 安装requirements.txt里面的包,但是注释掉torch,因为默认安装的为cpu版本
# Ultralytics requirements
# Usage: pip install -r requirements.txt

# Base ----------------------------------------
matplotlib>=3.2.2
numpy>=1.18.5
opencv-python>=4.1.1
Pillow>=7.1.2
PyYAML>=5.3.1
requests>=2.23.0
scipy>=1.4.1
# torch>=1.7.0
# torchvision>=0.8.1
tqdm>=4.64.0

# Logging -------------------------------------
tensorboard>=2.4.1
# clearml
# comet

# Plotting ------------------------------------
pandas>=1.1.4
seaborn>=0.11.0

# Export --------------------------------------
# coremltools>=6.0  # CoreML export
# onnx>=1.12.0  # ONNX export
# onnx-simplifier>=0.4.1  # ONNX simplifier
# nvidia-pyindex  # TensorRT export
# nvidia-tensorrt  # TensorRT export
# scikit-learn==0.19.2  # CoreML quantization
# tensorflow>=2.4.1  # TF exports (-cpu, -aarch64, -macos)
# tensorflowjs>=3.9.0  # TF.js export
# openvino-dev  # OpenVINO export

# Extras --------------------------------------
ipython  # interactive notebook
psutil  # system utilization
thop>=0.1.1  # FLOPs computation
# albumentations>=1.0.3
# pycocotools>=2.0.6  # COCO mAP
# roboflow

# HUB -----------------------------------------
GitPython>=3.1.24

创建requirements.txt并安装

pip install -r  requirements.txt

到pytorch官网使用pip命令安装torch

pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu117

pip list一下,如果torch后面不显示cu,那就表明装的是cpu版本,卸载torch,重新运行上面命令安装torch,再装多一次就是带cuda的torch了

torch                   1.13.1+cu117
torchaudio              0.13.1+cu117
torchvision             0.14.1+cu117

训练过程

指定device=0参数是,报错

TypeError: replace expected at least 2 arguments, got 1

定位到错行,并注释报错的行

v = v.replace(" ", "").replace('')  # handle device=[0, 1, 2, 3]

你可能感兴趣的:(python,pytorch,开发语言)