question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

both files appear corrupted

See original GitHub issue

I’ve tried to use any of the pkl files you have uploaded, but they all appear corrupted. I tried both as a model and as a weights file:

import torch
import torch.nn as nn

model = torch.load("resnet50_ft_weight.pkl")
print(model)
import torch
import torch.nn as nn
import torchvision.models as models

model = models.resnet50()
model.load_state_dict(torch.load("resnet50_ft_weight.pkl"))
print(model)

The output is:

RuntimeError: Invalid magic number; corrupt file?

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:10
  • Comments:6

github_iconTop GitHub Comments

11reactions
RunOrVeithcommented, Feb 14, 2019

This works:

def resnet50(weights_path=None, **kwargs):
    """Constructs a ResNet-50 model.
    """
    model = ResNet(Bottleneck, [3, 4, 6, 3], **kwargs)
    if weights_path:
        import pickle
        with open(weights_path, 'rb') as f:
            obj = f.read()
        weights = {key: torch.from_numpy(arr) for key, arr in pickle.loads(obj, encoding='latin1').items()}
        model.load_state_dict(weights)
    return model

model = resnet50("/path/to/weights.pkl", num_classes=8631)  # Pretrained weights fc layer has 8631 outputs
10reactions
schudovcommented, Jan 7, 2019

try this:

import pickle with open(‘senet50_ft_weight.pkl’, ‘rb’) as f: obj = f.read() weights = pickle.loads(obj, encoding=‘latin1’)

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Fix Corrupted Files - Lifewire
If you're desperate to fix the file and recover your information, try a file repair utility. There are both free and paid tools,...
Read more >
What Does It Mean When Your File Is Corrupt?
A file typically becomes corrupted when a problem occurs during saving. If your computer loses power or crashes as you save a file,...
Read more >
What Is A Corrupted File And How To Fix It? - Techslang
Corrupted files are computer files that become unusable or inoperable. Want to know how to fix them like a pro?
Read more >
Corrupted Windows Files: What They Are and How to Fix Them
A corrupted file is one that is damaged, and does not perform properly. This can apply to any type of file, from program...
Read more >
What Are Corrupted Windows Files and How to Fix Them
A corrupted file is simply a file that is damaged and not performing as it should. This can happen to any type of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found