在没有指定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]