open-mmlab / mmsegmentation

OpenMMLab Semantic Segmentation Toolbox and Benchmark.
https://mmsegmentation.readthedocs.io/en/main/
Apache License 2.0
7.98k stars 2.57k forks source link

Inference on CPU #292

Closed yashveerjain closed 3 years ago

yashveerjain commented 3 years ago

lib/python3.6/site-packages/torch/nn/modules/batchnorm.py", line 433, in forward raise ValueError('SyncBatchNorm expected input tensor to be on GPU') ValueError: SyncBatchNorm expected input tensor to be on GPU

Getting this error when trying to run the inference script for single image on cpu, libraries used: torch-1.5.1-cpu mmcv_full-cpu

NickChang97 commented 3 years ago

You may try to change the SyncBN to BN in your configfile

VpkPrasanna commented 3 years ago

You may try to change the SyncBN to BN in your configfile

This works perfectly fine for me , Thanks change in this file psenet_r50_fpnf_600e_icdar2015.py Change 'SyncBn' to 'BN',

model = dict( type='PSENet', pretrained='torchvision://resnet50', backbone=dict( type='ResNet', depth=50, num_stages=4, out_indices=(0, 1, 2, 3), frozen_stages=-1, norm_cfg=dict(type='SyncBN', requires_grad=True)

Changed code

model = dict( type='PSENet', pretrained='torchvision://resnet50', backbone=dict( type='ResNet', depth=50, num_stages=4, out_indices=(0, 1, 2, 3), frozen_stages=-1, norm_cfg=dict(type='BN', requires_grad=True)

LShuang7073 commented 2 years ago

where is the file?

LShuang7073 commented 2 years ago

You may try to change the SyncBN to BN in your configfile

This works perfectly fine for me , Thanks change in this file psenet_r50_fpnf_600e_icdar2015.py Change 'SyncBn' to 'BN',

model = dict( type='PSENet', pretrained='torchvision://resnet50', backbone=dict( type='ResNet', depth=50, num_stages=4, out_indices=(0, 1, 2, 3), frozen_stages=-1, norm_cfg=dict(type='SyncBN', requires_grad=True)

Changed code

model = dict( type='PSENet', pretrained='torchvision://resnet50', backbone=dict( type='ResNet', depth=50, num_stages=4, out_indices=(0, 1, 2, 3), frozen_stages=-1, norm_cfg=dict(type='BN', requires_grad=True)

where is the file ?

jgomeher83 commented 2 years ago

where is the file?

can you solved?

ocanevet commented 2 years ago

Hello, on my side, I managed to run on CPU by changing the SyncBN by BN in the configuration:

config = "configs/pspnet/pspnet_r50-d8_512x1024_40k_cityscapes.py"
config = mmcv.Config.fromfile(config)
config["norm_cfg"]["type"] = "BN"
config["model"]["backbone"]["norm_cfg"]["type"] = "BN"
config["model"]["decode_head"]["norm_cfg"]["type"] = "BN"
config["model"]["auxiliary_head"]["norm_cfg"]["type"] = "BN"

model = init_segmentor(config, checkpoint, device=device)

This is only for the configs/pspnet/pspnet_r50-d8_512x1024_40k_cityscapes.py.

I hope this helps.

Ryan9807 commented 2 years ago

Replace all "SyncBN" in pspnet_r50-d8_512x1024_40k_cityscapes.py file with "BN" That's how I solved it you can try.

Caczhtus commented 1 year ago

You may try to change the SyncBN to BN in your configfile

Thanks, it's resolved!

natwille1 commented 1 year ago

I tried to run this network on M1 Mac GPU, but still get this error..

import torch; torch.backends.mps.is_available()

True

ocanevet commented 1 year ago

Hi, could you create a device with:

device = None
if torch.cuda.is_available():
    device = "cuda"
elif torch.backends.mps.is_available():
    device = "mps"
else:
    device = "cpu"

print(f"device {device}")

then the model with:

model = init_segmentor(config, checkpoint, device=device)

and make sure that the model parameters are actually on your MPS device:

x = next(model.parameters())
print(x.device)
natwille1 commented 1 year ago

Thanks for the reply @ocanevet , the parameters are indeed on the MPS device:

image