GAN_C1_Week4_ControllableGeneration_unexpected EOF

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”]

n_classes = 40
classifier = Classifier(n_classes=n_classes).to(device)
class_dict = torch.load(“pretrained_classifier.pth”, map_location=torch.device(device))[“classifier”]
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()

1 frames
/usr/local/lib/python3.10/dist-packages/torch/ 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.

1 Like

If you are running things locally, then it requires a number of things:

  1. You need to copy any files that are associated with the assignment correctly and position them in the same folder structure that exists on the course website. Here’s a thread about how to do that.
  2. You need to have all the same versions of the various packages required installed. That’s not such a simple matter and there are no “official” instructions for how to do that. There are just too many possibilities depending on the vagaries of your local environment (e.g. how many versions of Windows are there by this point in time?). Here’s the best we have, which is just a guide to get you started down that road.

But following up on point 2), if you are playing this type of game, then you need to build and/or strengthen your own debugging skills. You can’t reasonably expect us to be your volunteer IT support staff for things that are beyond the scope of the courses here. The first law of debugging is “Believe the Error Message”. That one seems pretty clear, so which file is it talking about? What is wrong with that file? Compare what it looks like on your system to what you see on the online version of the assignment.

1 Like