https-deeplearning-ai / gans-public Goto Github PK
View Code? Open in Web Editor NEWCourse notebooks for GANs specializations
License: MIT License
Course notebooks for GANs specializations
License: MIT License
Hello,
thank you for providing these nice GAN implementations!
I was wondering whether the labels for the discriminator loss in SRGAN are swapped? At the moment it looks like the following:
from torchvision.models import vgg19
class Loss(nn.Module):
...
def adv_loss(self, x, is_real):
target = torch.zeros_like(x) if is_real else torch.ones_like(x)
return F.binary_cross_entropy_with_logits(x, target)
def forward(self, generator, discriminator, hr_real, lr_real):
''' Performs forward pass and returns total losses for G and D '''
hr_fake = generator(lr_real)
fake_preds_for_g = discriminator(hr_fake)
fake_preds_for_d = discriminator(hr_fake.detach())
real_preds_for_d = discriminator(hr_real.detach())
g_loss = (
0.001 * self.adv_loss(fake_preds_for_g, False) + \
0.006 * self.vgg_loss(hr_real, hr_fake) + \
self.img_loss(hr_real, hr_fake)
)
d_loss = 0.5 * (
self.adv_loss(real_preds_for_d, True) + \
self.adv_loss(fake_preds_for_d, False)
)
return g_loss, d_loss, hr_fake
Shouldn't it be the other way round for the discriminator loss as you want ones
for the real_preds
and zeros
for the fake_preds
?
d_loss = 0.5 * (
self.adv_loss(real_preds_for_d, False) + \
self.adv_loss(fake_preds_for_d, True)
)
Or maybe change the adv_loss
function so that is_real
corresponds to ones
:
def adv_loss(self, x, is_real):
target = torch.ones_like(x) if is_real else torch.zeros_like(x)
return F.binary_cross_entropy_with_logits(x, target)
and then g_loss
to:
g_loss = (
0.001 * self.adv_loss(fake_preds_for_g, True) + \
0.006 * self.vgg_loss(hr_real, hr_fake) + \
self.img_loss(hr_real, hr_fake)
)
But maybe I also get it wrong.
Best,
Christoph
In the 'Checkpoint' part of the notebook, a model named 'stylegan-256px.pt' is supposed to be downloaded from a google drive link. If you examine the contents of the downloaded file, the contents are HTML code. Within this HTML code, you can find a link to download the actual model, but if you don't download the actual model, issues will arise later in the code. For me, I had an issue stating "invalid load key, '<'." when running the code under the "Fine-tuning StyleGAN on Anime Faces" header before I realized the model was an HTML file instead of a model.
These items are not accessible:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.