[Python] Error loading Pytorch model checkpoint: _pickle.UnpicklingError: invalid load key,...

Discussão em 'Python' iniciado por Stack, Dezembro 9, 2024.

  1. Stack

    Stack Membro Participativo

    I'm trying to load the weights of a Pytorch model but getting this error: _pickle.UnpicklingError: invalid load key, '\x1f'.

    Here is the weights loading code:

    import os
    import torch
    import numpy as np
    # from data_loader import VideoDataset
    import timm

    device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
    print('Device being used:', device)

    mname = os.path.join('./CDF2_0.pth')
    checkpoints = torch.load(mname, map_location=device)
    print("Checkpoint loaded successfully.")
    model = timm.create_model('legacy_xception', pretrained=True, num_classes=2).to(device)
    model.load_state_dict(checkpoints['state_dict'])
    model.eval()



    I have tried with different Pytorch versions. I have tried to inspect the weights by changing the extension to .zip and opening with archive manager but can't fix the issue. Here is a public link to the weights .pth file, I'm trying to load. Any help is highly appreciated!

    Continue reading...

Compartilhe esta Página