code: def gan_loss_from_func(
      loss_gen: callable,  # A loss function for the generator. Evaluates generator output images and target real images
      loss_crit: callable,  # A loss function for the critic. Evaluates predictions of real and fake images.
      weights_gen: None
      | MutableSequence
      | tuple = None,  # Weights for the generator and critic loss function
  ):
      "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.0, 1.0))
          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
  
imports: from __future__ import annotations
  from ..basics import *
  from .all import *
label_desc: Use image node_id 11 for calling a global function with example usage: gan_loss_from_func(loss_gen, loss_crit, weights_gen) and returns: _loss_G,  _loss_C, unknown, unknown