code: def gan_loss_from_func(loss_gen, loss_crit, weights_gen:Tuple[float,float]=None):
      "Define loss functions for a GAN from `loss_gen` and `loss_crit`."
      def _loss_G(fake_pred, output, target, weights_gen=weights_gen):
          ones = fake_pred.new_ones(fake_pred.shape[0])
          weights_gen = ifnone(weights_gen, (1.,1.))
          return weights_gen[0] * loss_crit(fake_pred, ones) + weights_gen[1] * loss_gen(output, target)
  
      def _loss_C(real_pred, fake_pred):
          ones  = real_pred.new_ones (real_pred.shape[0])
          zeros = fake_pred.new_zeros(fake_pred.shape[0])
          return (loss_crit(real_pred, ones) + loss_crit(fake_pred, zeros)) / 2
  
      return _loss_G, _loss_f gan_loss_from_func(loss_gen, loss_crit, weights_gen:Tuple[float,float]=None):
      "Define loss functions for a GAN from `loss_gen` and `loss_crit`."
      def _loss_G(fake_pred, output, target, weights_gen=weights_gen):
          ones = fake_pred.new_ones(fake_pred.shape[0])
          weights_gen = ifnone(weights_gen, (1.,1.))
          return weights_gen[0] * loss_crit(fake_pred, ones) + weights_gen[1] * loss_gen(output, target)
  
      def _loss_C(real_pred, fake_pred):
          ones  = real_pred.new_ones (real_pred.shape[0])
          zeros = fake_pred.new_zeros(fake_pred.shape[0])
          return (loss_crit(real_pred, ones) + loss_crit(fake_pred, zeros)) / 2
  
      return _loss_G, _loss_C
docs: Define loss functions for a GAN from `loss_gen` and `loss_crit`.