WongKinYiu / ScaledYOLOv4

Scaled-YOLOv4: Scaling Cross Stage Partial Network
GNU General Public License v3.0
2.02k stars 575 forks source link

get error when running test.py #31

Open Actor12 opened 3 years ago

Actor12 commented 3 years ago

:~/myProjects/ScaledYOLOv4-yolov4-large# python test.py --img 896 --conf 0.001 --batch 1 --device 0 --data data/coco.yaml --weights weights/yolov4-p5.pt

Namespace(augment=False, batch_size=1, conf_thres=0.001, data='data/coco.yaml', device='0', img_size=896, iou_thres=0.65, merge=False, save_json=True, save_txt=False, single_cls=False, task='val', verbose=False, weights=['weights/yolov4-p5.pt']) Using CUDA device0 _CudaDeviceProperties(name='Tesla V100-PCIE-16GB', total_memory=16130MB)

/root/.local/lib/python3.7/site-packages/torch/serialization.py:453: SourceChangeWarning: source code of class 'models.yolo.Model' has changed. you can retrieve the original source code by accessing the object's source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert the changes. warnings.warn(msg, SourceChangeWarning) /root/.local/lib/python3.7/site-packages/torch/serialization.py:453: SourceChangeWarning: source code of class 'torch.nn.modules.container.Sequential' has changed. you can retrieve the original source code by accessing the object's source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert the changes. warnings.warn(msg, SourceChangeWarning) /root/.local/lib/python3.7/site-packages/torch/serialization.py:453: SourceChangeWarning: source code of class 'torch.nn.modules.conv.Conv2d' has changed. you can retrieve the original source code by accessing theobject's source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert the changes. warnings.warn(msg, SourceChangeWarning) /root/.local/lib/python3.7/site-packages/torch/serialization.py:453: SourceChangeWarning: source code of class 'torch.nn.modules.batchnorm.SyncBatchNorm' has changed. you can retrieve the original source code by accessing the object's source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert the changes. warnings.warn(msg, SourceChangeWarning) /root/.local/lib/python3.7/site-packages/torch/serialization.py:453: SourceChangeWarning: source code of class 'torch.nn.modules.container.ModuleList' has changed. you can retrieve the original source code by accessing the object's source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert the changes. warnings.warn(msg, SourceChangeWarning) Fusing layers... Model Summary: 331 layers, 7.07943e+07 parameters, 6.81919e+07 gradients Traceback (most recent call last): File "test.py", line 278, in opt.verbose) File "test.py", line 74, in test _ = model(img.half() if half else img) if device.type != 'cpu' else None # run once File "/root/.local/lib/python3.7/site-packages/torch/nn/modules/module.py", line 547, in call result = self.forward(*input, kwargs) File "/root/myProjects/ScaledYOLOv4-yolov4-large/models/yolo.py", line 109, in forward return self.forward_once(x, profile) # single-scale inference, train File "/root/myProjects/ScaledYOLOv4-yolov4-large/models/yolo.py", line 129, in forward_once x = m(x) # run File "/root/.local/lib/python3.7/site-packages/torch/nn/modules/module.py", line 547, in call result = self.forward(*input, *kwargs) File "/root/myProjects/ScaledYOLOv4-yolov4-large/models/common.py", line 66, in forward return self.cv4(self.act(self.bn(torch.cat((y1, y2), dim=1)))) File "/root/.local/lib/python3.7/site-packages/torch/nn/modules/module.py", line 547, in call result = self.forward(input, kwargs) File "/root/.local/lib/python3.7/site-packages/torch/nn/modules/batchnorm.py", line 430, in forward raise AttributeError('SyncBatchNorm is only supported within torch.nn.parallel.DistributedDataParallel') AttributeError: SyncBatchNorm is only supported within torch.nn.parallel.DistributedDataParallel root@wufei-jupyter-nchkw:~/myProjects/ScaledYOLOv4-yolov4-large# python test.py --img 896 --conf 0.001 --batch 8 --device 0 --data coco.yaml --weights weights/yolov4-p5.pt Namespace(augment=False, batch_size=8, conf_thres=0.001, data='./data/coco.yaml', device='0', img_size=896, iou_thres=0.65, merge=False, save_json=True, save_txt=False, single_cls=False, task='val', verbose=False,weights=['weights/yolov4-p5.pt']) Using CUDA device0 _CudaDeviceProperties(name='Tesla V100-PCIE-16GB', total_memory=16130MB)

/root/.local/lib/python3.7/site-packages/torch/serialization.py:453: SourceChangeWarning: source code of class 'models.yolo.Model' has changed. you can retrieve the original source code by accessing the object's source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert the changes. warnings.warn(msg, SourceChangeWarning) /root/.local/lib/python3.7/site-packages/torch/serialization.py:453: SourceChangeWarning: source code of class 'torch.nn.modules.container.Sequential' has changed. you can retrieve the original source code by accessing the object's source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert the changes. warnings.warn(msg, SourceChangeWarning) /root/.local/lib/python3.7/site-packages/torch/serialization.py:453: SourceChangeWarning: source code of class 'torch.nn.modules.conv.Conv2d' has changed. you can retrieve the original source code by accessing theobject's source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert the changes. warnings.warn(msg, SourceChangeWarning) /root/.local/lib/python3.7/site-packages/torch/serialization.py:453: SourceChangeWarning: source code of class 'torch.nn.modules.batchnorm.SyncBatchNorm' has changed. you can retrieve the original source code by accessing the object's source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert the changes. warnings.warn(msg, SourceChangeWarning) /root/.local/lib/python3.7/site-packages/torch/serialization.py:453: SourceChangeWarning: source code of class 'torch.nn.modules.container.ModuleList' has changed. you can retrieve the original source code by accessing the object's source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert the changes. warnings.warn(msg, SourceChangeWarning) Fusing layers... Model Summary: 331 layers, 7.07943e+07 parameters, 6.81919e+07 gradients Traceback (most recent call last): File "test.py", line 278, in opt.verbose) File "test.py", line 74, in test _ = model(img.half() if half else img) if device.type != 'cpu' else None # run once File "/root/.local/lib/python3.7/site-packages/torch/nn/modules/module.py", line 547, in call result = self.forward(*input, kwargs) File "/root/myProjects/ScaledYOLOv4-yolov4-large/models/yolo.py", line 109, in forward return self.forward_once(x, profile) # single-scale inference, train File "/root/myProjects/ScaledYOLOv4-yolov4-large/models/yolo.py", line 129, in forward_once x = m(x) # run File "/root/.local/lib/python3.7/site-packages/torch/nn/modules/module.py", line 547, in call result = self.forward(*input, *kwargs) File "/root/myProjects/ScaledYOLOv4-yolov4-large/models/common.py", line 66, in forward return self.cv4(self.act(self.bn(torch.cat((y1, y2), dim=1)))) File "/root/.local/lib/python3.7/site-packages/torch/nn/modules/module.py", line 547, in call result = self.forward(input, kwargs) File "/root/.local/lib/python3.7/site-packages/torch/nn/modules/batchnorm.py", line 430, in forward raise AttributeError('SyncBatchNorm is only supported within torch.nn.parallel.DistributedDataParallel') AttributeError: SyncBatchNorm is only supported within torch.nn.parallel.DistributedDataParallel

WongKinYiu commented 3 years ago

把SyncBatchNorm轉回BatchNorm可以解決

lx120 commented 3 years ago

I am confused : How to convert SyncBatchNorm to BatchNorm. Could you please tie codes, THKs

Actor12 commented 3 years ago

I am confused : How to convert SyncBatchNorm to BatchNorm. Could you please tie codes, THKs

I changed the pytorch version and solved it, torch==1.3 && torchvision==0.4.2

larsoncs commented 3 years ago

@WongKinYiu ,"把SyncBatchNorm轉回BatchNorm可以解決", but the common.py use BatchNorm2d, not use SyncBatchNorm,how to convert SyncBatchNorm to BatchNorm? thx

larsoncs commented 3 years ago

i use cpu to run test.py ,get this error:

Traceback (most recent call last): File "test.py", line 281, in opt.verbose) File "test.py", line 99, in test inf_out, train_out = model(img, augment=augment) # inference and training outputs File "/D/lib/python3.7/site-packages/torch/nn/modules/module.py", line 727, in _call_impl result = self.forward(*input, kwargs) File "/data/home//odetect/yolov4/models/yolo.py", line 109, in forward return self.forward_once(x, profile) # single-scale inference, train File "/data/home//odetect/yolov4/models/yolo.py", line 129, in forward_once x = m(x) # run File "/D/lib/python3.7/site-packages/torch/nn/modules/module.py", line 727, in _call_impl result = self.forward(*input, *kwargs) File "/data/home//odetect/yolov4/models/common.py", line 66, in forward return self.cv4(self.act(self.bn(torch.cat((y1, y2), dim=1)))) File "/D/lib/python3.7/site-packages/torch/nn/modules/module.py", line 727, in _call_impl result = self.forward(input, kwargs) File "/D/lib/python3.7/site-packages/torch/nn/modules/batchnorm.py", line 477, in forward raise ValueError('SyncBatchNorm expected input tensor to be on GPU') ValueError: SyncBatchNorm expected input tensor to be on GPU