I’m trying to run the lab assignment code where we load the pretrained models, I’m doing it on my local machine, here is the code provided by the lab assignment:
import torch
gen = Generator(z_dim).to(device)
gen_dict = torch.load(“pretrained_celeba.pth”, map_location=torch.device(device))[“gen”]
gen.load_state_dict(gen_dict)
gen.eval()
n_classes = 40
classifier = Classifier(n_classes=n_classes).to(device)
class_dict = torch.load(“pretrained_classifier.pth”, map_location=torch.device(device))[“classifier”]
classifier.load_state_dict(class_dict)
classifier.eval()
print(“Loaded the models!”)
opt = torch.optim.Adam(classifier.parameters(), lr=0.01)
But when I run this code, I get the following error:
RuntimeError Traceback (most recent call last)
in <cell line: 2>()
1 gen = Generator(z_dim).to(device)
----> 2 gen_dict = torch.load(“/content/pretrained_celeba.pth”, map_location=torch.device(device))[“gen”]
3 gen.load_state_dict(gen_dict)
4 gen.eval()
5
1 frames
/usr/local/lib/python3.10/dist-packages/torch/serialization.py in _legacy_load(f, map_location, pickle_module, **pickle_load_args)
1262 assert key in deserialized_objects
1263 typed_storage = deserialized_objects[key]
→ 1264 typed_storage._untyped_storage._set_from_file(
1265 f, offset, f_should_read_directly,
1266 torch._utils._element_size(typed_storage.dtype))
RuntimeError: unexpected EOF, expected 731304 more bytes. The file might be corrupted.