hzxie / Pix2Vox

The official implementation of "Pix2Vox: Context-aware 3D Reconstruction from Single and Multi-view Images". (Xie et al., ICCV 2019)
https://haozhexie.com/project/pix2vox
MIT License
479 stars 116 forks source link

RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is False #116

Closed ShrutiKumari02 closed 4 weeks ago

ShrutiKumari02 commented 4 weeks ago

error_pix2vox

I am facing issue in runner.py as I am trying to use pretrained model on CPU . I have changed runner.py code accordingly for loading on CPU but still I am facing same error.

Can you please suggest how can this be fixed?

hzxie commented 4 weeks ago

As suggested

If you are running on a CPU-only machine, please use torch.load with map_location=torch.device('cpu') to map your storages to the CPU.

Change

https://github.com/hzxie/Pix2Vox/blob/69e2579f9baab90eac1ec0a24c184d010e9a0fde/core/test.py#L77

to

checkpoint = torch.load(cfg.CONST.WEIGHTS, map_location=torch.device('cpu'))
ShrutiKumari02 commented 4 weeks ago

As suggested

If you are running on a CPU-only machine, please use torch.load with map_location=torch.device('cpu') to map your storages to the CPU.

Change

https://github.com/hzxie/Pix2Vox/blob/69e2579f9baab90eac1ec0a24c184d010e9a0fde/core/test.py#L77

to

checkpoint = torch.load(cfg.CONST.WEIGHTS, map_location=torch.device('cpu'))

I made the changes as suggested now I am getting this runtime error.Kindly suggest how can I fix this?

image

C:\Users\shruti.k\AppData\Local\Programs\Python\Python312\Lib\site-packages\torchvision\models_utils.py:208: UserWarning: The parameter 'pretrained' is deprecated since 0.13 and may be removed in the future, please use 'weights' instead. warnings.warn( C:\Users\shruti.k\AppData\Local\Programs\Python\Python312\Lib\site-packages\torchvision\models_utils.py:223: UserWarning: Arguments other than a weight enum or None for 'weights' are deprecated since 0.13 and may be removed in the future. The current behavior is equivalent to passing weights=VGG16_BN_Weights.IMAGENET1K_V1. You can also use weights=VGG16_BN_Weights.DEFAULT to get the most up-to-date weights. warnings.warn(msg) [INFO] 2024-10-03 17:15:07.533580 Loading weights from C:\Users\shruti.k\Downloads\Pix2Vox-A-ShapeNet.pth ... Traceback (most recent call last): File "C:\Users\shruti.k\Desktop\Pix2Vox\Pix2Vox\runner.py", line 93, in main() File "C:\Users\shruti.k\Desktop\Pix2Vox\Pix2Vox\runner.py", line 77, in main test_net(cfg) File "C:\Users\shruti.k\Desktop\Pix2Vox\Pix2Vox\core\test.py", line 79, in test_net encoder.load_state_dict(checkpoint['encoder_state_dict']) File "C:\Users\shruti.k\AppData\Local\Programs\Python\Python312\Lib\site-packages\torch\nn\modules\module.py", line 2189, in load_state_dict raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format( RuntimeError: Error(s) in loading state_dict for Encoder: Missing key(s) in state_dict: "vgg.0.weight", "vgg.0.bias", "vgg.1.weight", "vgg.1.bias", "vgg.1.running_mean", "vgg.1.running_var", "vgg.3.weight", "vgg.3.bias", "vgg.4.weight", "vgg.4.bias", "vgg.4.running_mean", "vgg.4.running_var", "vgg.7.weight", "vgg.7.bias", "vgg.8.weight", "vgg.8.bias", "vgg.8.running_mean", "vgg.8.running_var", "vgg.10.weight", "vgg.10.bias", "vgg.11.weight", "vgg.11.bias", "vgg.11.running_mean", "vgg.11.running_var", "vgg.14.weight", "vgg.14.bias", "vgg.15.weight", "vgg.15.bias", "vgg.15.running_mean", "vgg.15.running_var", "vgg.17.weight", "vgg.17.bias", "vgg.18.weight", "vgg.18.bias", "vgg.18.running_mean", "vgg.18.running_var", "vgg.20.weight", "vgg.20.bias", "vgg.21.weight", "vgg.21.bias", "vgg.21.running_mean", "vgg.21.running_var", "vgg.24.weight", "vgg.24.bias", "vgg.25.weight", "vgg.25.bias", "vgg.25.running_mean", "vgg.25.running_var", "layer1.0.weight", "layer1.0.bias", "layer1.1.weight", "layer1.1.bias", "layer1.1.running_mean", "layer1.1.running_var", "layer2.0.weight", "layer2.0.bias", "layer2.1.weight", "layer2.1.bias", "layer2.1.running_mean", "layer2.1.running_var", "layer3.0.weight", "layer3.0.bias", "layer3.1.weight", "layer3.1.bias", "layer3.1.running_mean", "layer3.1.running_var". Unexpected key(s) in state_dict: "module.vgg.0.weight", "module.vgg.0.bias", "module.vgg.1.weight", "module.vgg.1.bias", "module.vgg.1.running_mean", "module.vgg.1.running_var", "module.vgg.1.num_batches_tracked", "module.vgg.3.weight", "module.vgg.3.bias", "module.vgg.4.weight", "module.vgg.4.bias", "module.vgg.4.running_mean", "module.vgg.4.running_var", "module.vgg.4.num_batches_tracked", "module.vgg.7.weight", "module.vgg.7.bias", "module.vgg.8.weight", "module.vgg.8.bias", "module.vgg.8.running_mean", "module.vgg.8.running_var", "module.vgg.8.num_batches_tracked", "module.vgg.10.weight", "module.vgg.10.bias", "module.vgg.11.weight", "module.vgg.11.bias", "module.vgg.11.running_mean", "module.vgg.11.running_var", "module.vgg.11.num_batches_tracked", "module.vgg.14.weight", "module.vgg.14.bias", "module.vgg.15.weight", "module.vgg.15.bias", "module.vgg.15.running_mean", "module.vgg.15.running_var", "module.vgg.15.num_batches_tracked", "module.vgg.17.weight", "module.vgg.17.bias", "module.vgg.18.weight", "module.vgg.18.bias", "module.vgg.18.running_mean", "module.vgg.18.running_var", "module.vgg.18.num_batches_tracked", "module.vgg.20.weight", "module.vgg.20.bias", "module.vgg.21.weight", "module.vgg.21.bias", "module.vgg.21.running_mean", "module.vgg.21.running_var", "module.vgg.21.num_batches_tracked", "module.vgg.24.weight", "module.vgg.24.bias", "module.vgg.25.weight", "module.vgg.25.bias", "module.vgg.25.running_mean", "module.vgg.25.running_var", "module.vgg.25.num_batches_tracked", "module.layer1.0.weight", "module.layer1.0.bias", "module.layer1.1.weight", "module.layer1.1.bias", "module.layer1.1.running_mean", "module.layer1.1.running_var", "module.layer1.1.num_batches_tracked", "module.layer2.0.weight", "module.layer2.0.bias", "module.layer2.1.weight", "module.layer2.1.bias", "module.layer2.1.running_mean", "module.layer2.1.running_var", "module.layer2.1.num_batches_tracked", "module.layer3.0.weight", "module.layer3.0.bias", "module.layer3.1.weight", "module.layer3.1.bias", "module.layer3.1.running_mean", "module.layer3.1.running_var", "module.layer3.1.num_batches_tracked". [INFO/MainProcess] process shutting down error_pix2vox

hzxie commented 4 weeks ago

Just remove "module." from the key names. If you don't know how to do it, please ask ChatGPT.