Exemplo n.º 1
0
    def __setup_loss(self, loss):
        import pro_gan_pytorch.Losses as losses

        if isinstance(loss, str):
            loss = loss.lower()  # lowercase the string
            if loss == "wgan":
                loss = losses.WGAN_GP(self.device, self.dis, self.drift, use_gp=False)
                # note if you use just wgan, you will have to use weight clipping
                # in order to prevent gradient exploding

            elif loss == "wgan-gp":
                loss = losses.WGAN_GP(self.device, self.dis, self.drift, use_gp=True)

            elif loss == "lsgan":
                loss = losses.LSGAN(self.device, self.dis)

            elif loss == "lsgan-with-sigmoid":
                loss = losses.LSGAN_SIGMOID(self.device, self.dis)

            else:
                raise ValueError("Unknown loss function requested")

        elif not isinstance(loss, losses.GANLoss):
            raise ValueError("loss is neither an instance of GANLoss nor a string")

        return loss
Exemplo n.º 2
0
 def __setup_loss(self, loss):
     import pro_gan_pytorch.Losses as losses
     if isinstance(loss, str):
         loss = loss.lower()  # lowercase the string
         if loss == "wgan":
             loss = losses.WGAN_GP(self.dis, self.drift, use_gp=False)
             # note if you use just wgan, you will have to use weight clipping
             # in order to prevent gradient exploding
             # check the optimize_discriminator method where this has been
             # taken care of.
         elif loss == "wgan-gp":
             loss = losses.WGAN_GP(self.dis, self.drift, use_gp=True)
         elif loss == "standard-gan":
             loss = losses.StandardGAN(self.dis)
         elif loss == "lsgan":
             loss = losses.LSGAN(self.dis)
         elif loss == "lsgan-with-sigmoid":
             loss = losses.LSGAN_SIGMOID(self.dis)
         elif loss == "hinge":
             loss = losses.HingeGAN(self.dis)
         elif loss == "relativistic-hinge":
             loss = losses.RelativisticAverageHingeGAN(self.dis)
         else:
             raise ValueError("Unknown loss function requested")
     elif not isinstance(loss, losses.GANLoss):
         raise ValueError(
             "loss is neither an instance of GANLoss nor a string")
     return loss