v5 轻量化过程 错误记录

错误1:AttributeError: 'list' object has no attribute 'shape'

很大程度上时训练的文件用错了,分割去用v5的分割train 不是外面的train

错误2:UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position 237: illegal multibyte sequence

多次遇到该问题,在yolo和train文件中 带有with open 的解释后添加encoding='utf-8'不能解决问题‘

我尝试了train的更该运行成功, 问题还是在train中

错误3:AttributeError: 'FreeTypeFont' object has no attribute 'getsize'

解决:训练一次后无法输出结果,需要将Pillow版本修改为9.5            pip install Pillow==9.5

错误3:推理使用detet的s += f"{n} {names[int(c)]}{'s' * (n > 1)}, "  # add to string KeyError: 4

解决:遇到这种问题基本是你做的实例分割所以推理不匹配,使用官方提供的实力分割推理predict即可

错误4:在yolov5剪枝时候导入会有错误 

from torch_pruning import prune

解决1:办法换新版本路径:

from torch.nn.utils import prune

解决2: 推荐 修改torch_pruning版本 0.2.5最稳定不报错,0.2.4部分设备会有问题

pip install torch_pruning==0.2.5

错误5:剪枝 遇到

TypeError: run() got an unexpected keyword argument 'mask_downsample_ratio'

错误6:

check_requirements 未检索  在utils 下的general下 修改导入
更新了代码后使用:from ultralytics.utils.checks import check_requirements
我未更新yolo代码时候使用的:from ultralytics.yolo.utils.checks import check_requirements

错误7:

File "D:\Code\PycharmProjects\yolov5-prune\utils\general.py", line 462, in check_file
    assert len(files) == 1, f"Multiple files match '{file}', specify exact path: {files}"  # assert unique
AssertionError: Multiple files match

要么让他别检查,要么改为绝对路径

错误8:

torch.cuda.OutOfMemoryError: CUDA out of memory. Tried to allocate 60.00 MiB. GPU 0 has a total capacity of 8.00 GiB of which 4.84 GiB is free. Of the allocated memory 1.99 GiB is allocated by PyTorch, and 66.00 MiB is reserved by PyTorch but unallocated. If reserved but unallocated memory is large try setting PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True to avoid fragmentation.  

显卡太烂显存不足,batch-size 改小点 ,默认16 自己试试那个大小合适

错误9:

TypeError: __init__() got an unexpected keyword argument 'device

首先自我检查步骤;

  1. 检查Profile类定义:首先,你需要查看Profile类在segment/val.py文件中的定义。确认它的构造函数是否接受一个名为device的参数。如果没有,这就是错误发生的原因。

  2. 移除不必要的参数:如果Profile类的构造函数确实不接受device参数,那么在创建Profile实例时不应传递该参数。修改segment/val.py文件中相关的代码行,去掉对Profile构造函数的device参数传递。

然后修改我们可以忽视它的报错

我的报错来自于训练了一次没结果,val文件错 D:\Code\PycharmProjects\yolov5\segment\val.py

找到这个代码:
dt = Profile(device=device), Profile(device=device), Profile(device=device)
    改为: 
dt = Profile(), Profile(), Profile()

第二种情况pytorch版本不匹配,自己去匹配toch和torchvison版本,别太新,但别太老 cu117就差不多

错误

 File "D:\Code\PycharmProjects\yolov5-prune\utils\loss.py", line 203, in build_targets
    gain[2:6] = torch.tensor([shape[3], shape[2], shape[3], shape[2]], device=self.device)  # xyxy gain
IndexError: tuple index out of range

为了解决IndexError: tuple index out of range的问题,我们首先需要确保shape变量能够正确反映预期的维度。从提供的代码中,我们看到shape是通过p[i].shape获得的,其中p[i]代表模型在特定层的输出。理论上,p[i]的形状应该是四维的(例如,[batch_size, channels, height, width]),但出现的错误表明在某些情况下这可能不成立。

直接修改的建议

build_targets函数中,你尝试使用shape[3]shape[2]来获取宽度和高度。出现错误的根本原因是shape变量没有足够的元素(维度)。

要解决这个问题,你需要确保在使用这些索引之前,p[i]确实是一个四维张量。首先,我们来确保shape变量的正确性。

如果p[i]的形状经常不是四维的,这可能表明更深层次的问题,比如模型结构或者数据预处理部分。你可能需要进一步检查模型的每一层的输出,确保它们符合预期。

最后,如果这些修改没有解决问题,或者你在实施这些建议时遇到新的问题,请提供更多的上下文,比如模型定义的部分和数据预处理的代码,这样可以帮助更准确地定位问题所在。

def build_targets(self, p, targets):
    # Build targets for compute_loss(), input targets(image,class,x,y,w,h)
    ...
    for i in range(self.nl):
        anchors, shape = self.anchors[i], p[i].shape
        if len(shape) == 4:  # 确保 p[i] 是四维的 [B, C, H, W]
            gain[2:6] = torch.tensor([shape[3], shape[2], shape[3], shape[2]], device=self.device)  # xyxy gain
        else:
            print(f"Unexpected shape {shape} in layer {i}")
            continue  # 跳过这一层或者采取其他处理方式

        # Match targets to anchors
        ...
 

  • 10
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值