使用mmrotate时的bug:“batch_size=0”

在没有指定gpu的时候,会出现以下这个错误

if device.type == “cpu”:
^^^^^^^^^^^
AttributeError: ‘int’ object has no attribute ‘type’

但是指定了之后,又会出现以下这个batch_size=0

    raise ValueError(f"batch_size should be a positive integer value, but got batch_size={batch_size}")
ValueError: batch_size should be a positive integer value, but got batch_size=0

解决方法参考:MMrotate 训练报错(‘int‘ object has no attribute ‘type‘)-优快云博客

解决方法:

在D:\Anaconda\envs\mmrotate3\Lib\site-packages\mmcv\parallel_functions.py中做如下修改

1.在头文件中 +from packaging import version

2.定位到Scatter类,替换stream

       # streams = [_get_stream(device) for device in target_gpus]   这个是原来的版本,注释掉,替换如下:
        if version.parse(torch.__version__) >= version.parse('2.1.0'):
            streams = [_get_stream(torch.device("cuda", device)) for device in target_gpus]
        else:
            streams = [_get_stream(device) for device in target_gpus]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值