Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get error when running test.py #31

Open
Actor12 opened this issue Nov 20, 2020 · 5 comments
Open

get error when running test.py #31

Actor12 opened this issue Nov 20, 2020 · 5 comments

Comments

@Actor12
Copy link

Actor12 commented Nov 20, 2020

:~/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

@Actor12 Actor12 changed the title get a error when running test.py get error when running test.py Nov 20, 2020
@WongKinYiu
Copy link
Owner

把SyncBatchNorm轉回BatchNorm可以解決

@lx120
Copy link

lx120 commented Nov 25, 2020

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

@Actor12
Copy link
Author

Actor12 commented Nov 25, 2020

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
Copy link

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

@larsoncs
Copy link

larsoncs commented Mar 16, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants