微调 Yolov8 时如何修复“TypeError: code() argument 13 must be str, not int”

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

我正在使用自定义数据集微调 Yolov8。该错误总是发生在第一个纪元之后。这意味着模型训练了一段时间,但在完成第一个 epoch 后,会弹出错误。这是我的代码:

model = YOLO("YOLOv8n.pt",task="detect")
model.train(data="config.yaml", epochs=5,optimizer="Adam")

config.yaml:

train: /Users/nuntea/Computer Vision/Football Field Detection/aug_data/Train/images
val: /Users/nuntea/Computer Vision/Football Field Detection/aug_data/Validation/images

names:
     0 : Referee
     1 : Player
     2 : GoalKeeper
     3 : Ball

有错误的训练日志(已截断):

Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
 1/5         0G      2.409       2.63       2.16         44        640: 1

Class     Images  Instances      Box(P          R      mAP50  m
 all        900       4527   4.44e-05     0.0032   2.42e-05   7.84e-06

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[54], line 2
      1 model = YOLO("YOLOv8n.pt",task="detect")
----> 2 model.train(data="config.yaml", epochs=5,optimizer="Adam")

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/ultralytics/engine/model.py:338, in Model.train(self, trainer, **kwargs)
    336     self.model = self.trainer.model
    337 self.trainer.hub_session = self.session  # attach optional HUB session
--> 338 self.trainer.train()
    339 # Update model and cfg after training
    340 if RANK in (-1, 0):

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/ultralytics/engine/trainer.py:385, in BaseTrainer._do_train(self, world_size)
    383     # Save model
    384     if self.args.save or (epoch + 1 == self.epochs):
--> 385         self.save_model()
    386         self.run_callbacks('on_model_save')
    388 tnow = time.time()

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/cloudpickle/__init__.py:7
      3 import sys
      4 import pickle
----> 7 from cloudpickle.cloudpickle import *
      8 if sys.version_info[:2] >= (3, 8):
      9     from cloudpickle.cloudpickle_fast import CloudPickler, dumps, dump

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/cloudpickle/cloudpickle.py:361
    342         else:
    343             return types.CodeType(
    344                 co.co_argcount,
    345                 co.co_kwonlyargcount,
   (...)
    358                 (),
    359             )
--> 361 _cell_set_template_code = _make_cell_set_template_code()
    364 def cell_set(cell, value):
    365     """Set the value of a closure cell.
    366     """

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/cloudpickle/cloudpickle.py:324, in _make_cell_set_template_code()
    322 else:
    323     if hasattr(types.CodeType, "co_posonlyargcount"):  # pragma: no branch
--> 324         return types.CodeType(
    325             co.co_argcount,
    326             co.co_posonlyargcount,  # Python3.8 with PEP570
    327             co.co_kwonlyargcount,
    328             co.co_nlocals,
    329             co.co_stacksize,
    330             co.co_flags,
    331             co.co_code,
    332             co.co_consts,
    333             co.co_names,
    334             co.co_varnames,
    335             co.co_filename,
    336             co.co_name,
    337             co.co_firstlineno,
    338             co.co_lnotab,
    339             co.co_cellvars,  # this is the trickery
    340             (),
    341         )
    342     else:
    343         return types.CodeType(
    344             co.co_argcount,
    345             co.co_kwonlyargcount,
   (...)
    358             (),
    359         )

TypeError: code() argument 13 must be str, not int

我一直在尝试改变不同类型的参数输入方式,例如使用 config.yaml 来参数化优化器等。

python pytorch computer-vision yolo yolov8
1个回答
0
投票

可能是错误的,但是你的配置不需要像刺一样吗?尝试:

train: '/Users/nuntea/Computer Vision/Football Field Detection/aug_data/Train/images'
val: '/Users/nuntea/Computer Vision/Football Field Detection/aug_data/Validation/images'

names:
     0 : 'Referee'
     1 : 'Player'
     2 : 'GoalKeeper'
     3 : 'Ball'
© www.soinside.com 2019 - 2024. All rights reserved.