Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autoencoders code: NameError: name 'img_bad' is not defined. How to fix? #841

Closed
ghost opened this issue Mar 18, 2023 · 2 comments
Closed

Comments

@ghost
Copy link

ghost commented Mar 18, 2023

Hi!

When I'm trying to run the code 10-autoencoder.ipynb I get an error in the second to last cell, which is:

# Inpaint with Telea and Navier-Stokes methods

dst_TELEA = list()
dst_NS = list()

for i in range(3, 7):
    corrupted_img = ((img_bad.data.cpu()[i].view(28, 28) / 4 + 0.5) * 255).byte().numpy()
    mask = 2 - noise.cpu()[i].view(28, 28).byte().numpy()
    dst_TELEA.append(inpaint(corrupted_img, mask, 3, INPAINT_TELEA))
    dst_NS.append(inpaint(corrupted_img, mask, 3, INPAINT_NS))

tns_TELEA = [torch.from_numpy(d) for d in dst_TELEA]
tns_NS = [torch.from_numpy(d) for d in dst_NS]

TELEA = torch.stack(tns_TELEA).float()
NS = torch.stack(tns_NS).float()

The error saying:

NameError                                 Traceback (most recent call last)
Cell In[24], line 7
      4 dst_NS = list()
      6 for i in range(3, 7):
----> 7     corrupted_img = ((img_bad.data.cpu()[i].view(28, 28) / 4 + 0.5) * 255).byte().numpy()
      8     mask = 2 - noise.cpu()[i].view(28, 28).byte().numpy()
      9     dst_TELEA.append(inpaint(corrupted_img, mask, 3, INPAINT_TELEA))

NameError: name 'img_bad' is not defined

How could I fix this?
Thanks!

@Atcold
Copy link
Owner

Atcold commented Apr 3, 2023

If you read the notebook you'll see at some point:

Comment or un-comment out a few lines of code to seamlessly switch between standard AE and denoising one.

# Train standard or denoising autoencoder (AE)

num_epochs = 20
# do = nn.Dropout()  # comment out for standard AE
for epoch in range(num_epochs):
    for data in dataloader:
        img, _ = data
        img = img.to(device)
        img = img.view(img.size(0), -1)
        # noise = do(torch.ones(img.shape)).to(device)
        # img_bad = (img * noise).to(device)  # comment out for standard AE
        # ===================forward=====================
        output = model(img)  # feed <img> (for std AE) or <img_bad> (for denoising AE)
        loss = criterion(output, img.data)

@Atcold Atcold closed this as completed Apr 3, 2023
@Atcold
Copy link
Owner

Atcold commented Apr 21, 2023

Here you can find a more updated version of the notebook, used in a more recent edition of the course.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant