          for name, output_name in zip(self._names, output_names):
              if name.startswith("mask"):
                  loss_func = self._loss_dict[self._config["mask_loss_function"]]
              else:
                  if (self._config["loss_function"] in self._uses_l2_reg
                          and self._config["l2_reg_term"] != 0):
                      loss_funcs = [selected_loss, self._loss_dict["mse"]]
                      loss_weights = [1.0, self._config["l2_reg_term"] / 100.0]
                  else:
                      loss_funcs = [selected_loss]
                      loss_weights = [1.0]
  
                  if self._config["penalized_mask_loss"]:
                      loss_funcs = [losses.PenalizedLoss(loss) for loss in loss_funcs]
  
                  loss_func = losses.LossWrapper(loss_functions=list(zip(loss_funcs, loss_weights)))
  
              logger.debug("%s: (output_name: '%s', function: %s)", name, output_name, loss_func)
              self._funcs[output_name] = loss_func
          logger.debug("functions: %s", self._funcs)
  
 
</s> remove         selected_loss = self._loss_dict[self._config["loss_function"]]
 </s> add         mask_channels = self._get_mask_channels()
        face_loss = self._loss_dict[self._config["loss_function"]]
 </s> remove         loss_functions: list
            A list of either a tuple of (:class:`keras.losses.Loss`, scalar weight) or just a
            :class:`keras.losses.Loss` function. If just the loss function is passed, then the
            weight is assumed to be 1.0 """
        for loss_func in loss_functions:
            if isinstance(loss_func, tuple):
                assert len(loss_func) == 2, "Tuple loss functions should contain 2 items"
                assert isinstance(loss_func[1], float), "weight should be a float"
                func, weight = loss_func
            else:
                func = loss_func
                weight = 1.0
            self._loss_functions.append(compile_utils.LossesContainer(func))
            self._loss_weights.append(weight)
        logger.debug("Compiled losses: (functions: %s, weights: %s",
                     self._loss_functions, self._loss_weights)
 </s> add         function: :class:`keras.losses.Loss`
            The loss function to add to the loss chain
        weight: float, optional
            The weighting to apply to the loss function. Default: `1.0`
        mask_channel: int, optional
            The channel in the `y_true` image that the mask exists in. Set to `-1` if there is no
            mask for the given loss function. Default: `-1`
        """
        logger.debug("Adding loss: (function: %s, weight: %s, mask_channel: %s)",
                     function, weight, mask_channel)
        self._loss_functions.append(compile_utils.LossesContainer(function))
        self._loss_weights.append(weight)
        self._mask_channels.append(mask_channel) </s> remove         loss_functions: list
            A list of either a tuple of (:class:`keras.losses.Loss`, scalar weight) or just a
            :class:`keras.losses.Loss` function. If just the loss function is passed, then the
            weight is assumed to be 1.0 """
        for loss_func in loss_functions:
            if isinstance(loss_func, tuple):
                assert len(loss_func) == 2, "Tuple loss functions should contain 2 items"
                assert isinstance(loss_func[1], float), "weight should be a float"
                func, weight = loss_func
            else:
                func = loss_func
                weight = 1.0
            self._loss_functions.append(func)
            self._loss_weights.append(weight)
        logger.debug("Compiled losses: (functions: %s, weights: %s",
                     self._loss_functions, self._loss_weights)
 </s> add         function: :class:`keras.losses.Loss`
            The loss function to add to the loss chain
        weight: float, optional
            The weighting to apply to the loss function. Default: `1.0`
        mask_channel: int, optional
            The channel in the `y_true` image that the mask exists in. Set to `-1` if there is no
            mask for the given loss function. Default: `-1`
        """
        logger.debug("Adding loss: (function: %s, weight: %s, mask_channel: %s)",
                     function, weight, mask_channel)
        self._loss_functions.append(function)
        self._loss_weights.append(weight)
        self._mask_channels.append(mask_channel) </s> remove         logger.trace("masks shape: %s", masks.shape)
        batch = np.concatenate((batch, masks), axis=-1)
 </s> add         Returns
        -------
        :class:`numpy.ndarray`
            The batch with masks applied to the final channels
        """
        logger.trace("Input batch shape: %s, side: %s", batch.shape, side)
        size = batch.shape[1]
        for key in ("masks", "eyes", "mouths"):
            item = self._masks[key]
            if item is None and key != "masks":
                continue
            if item is None and key == "masks":
                logger.trace("Creating dummy masks. side: %s", side)
                masks = np.ones_like(batch[..., :1], dtype=batch.dtype)
            else:
                logger.trace("Obtaining masks for batch. (key: %s side: %s)", key, side)
                masks = np.array([self._get_mask(item[side][filename], size)
                                  for filename, face in zip(filenames, batch)], dtype=batch.dtype)
                masks = self._resize_masks(size, masks)

            logger.trace("masks: (key: %s, shape: %s)", key, masks.shape)
            batch = np.concatenate((batch, masks), axis=-1) </s> remove                                       for mask in masks])[..., None]
 </s> add                                       for mask in masks])
                if add_masks.ndim == 3:
                    add_masks = add_masks[..., None]
                loss_func = losses.LossWrapper()
                loss_func.add_loss(face_loss, mask_channel=mask_channels[0])
                self._add_l2_regularization_term(loss_func, mask_channels[0])

                mask_channel = 1
                for multiplier in ("eye_multiplier", "mouth_multiplier"):
                    if self._config[multiplier] > 1:
                        loss_func.add_loss(face_loss,
                                           weight=self._config[multiplier] * 1.0,
                                           mask_channel=mask_channels[mask_channel])
                        self._add_l2_regularization_term(loss_func, mask_channel)
                    mask_channel += 1
          for name, output_name in zip(self._names, output_names):
              if name.startswith("mask"):
                  loss_func = self._loss_dict[self._config["mask_loss_function"]]
              else:
                loss_func = losses.LossWrapper()
                loss_func.add_loss(face_loss, mask_channel=mask_channels[0])
                self._add_l2_regularization_term(loss_func, mask_channels[0])

                mask_channel = 1
                for multiplier in ("eye_multiplier", "mouth_multiplier"):
                    if self._config[multiplier] > 1:
                        loss_func.add_loss(face_loss,
                                           weight=self._config[multiplier] * 1.0,
                                           mask_channel=mask_channels[mask_channel])
                        self._add_l2_regularization_term(loss_func, mask_channel)
                    mask_channel += 1
                loss_func = losses.LossWrapper()
                loss_func.add_loss(face_loss, mask_channel=mask_channels[0])
                self._add_l2_regularization_term(loss_func, mask_channels[0])

                mask_channel = 1
                for multiplier in ("eye_multiplier", "mouth_multiplier"):
                    if self._config[multiplier] > 1:
                        loss_func.add_loss(face_loss,
                                           weight=self._config[multiplier] * 1.0,
                                           mask_channel=mask_channels[mask_channel])
                        self._add_l2_regularization_term(loss_func, mask_channel)
                    mask_channel += 1
                loss_func = losses.LossWrapper()
                loss_func.add_loss(face_loss, mask_channel=mask_channels[0])
                self._add_l2_regularization_term(loss_func, mask_channels[0])

                mask_channel = 1
                for multiplier in ("eye_multiplier", "mouth_multiplier"):
                    if self._config[multiplier] > 1:
                        loss_func.add_loss(face_loss,
                                           weight=self._config[multiplier] * 1.0,
                                           mask_channel=mask_channels[mask_channel])
                        self._add_l2_regularization_term(loss_func, mask_channel)
                    mask_channel += 1
                loss_func = losses.LossWrapper()
                loss_func.add_loss(face_loss, mask_channel=mask_channels[0])
                self._add_l2_regularization_term(loss_func, mask_channels[0])

                mask_channel = 1
                for multiplier in ("eye_multiplier", "mouth_multiplier"):
                    if self._config[multiplier] > 1:
                        loss_func.add_loss(face_loss,
                                           weight=self._config[multiplier] * 1.0,
                                           mask_channel=mask_channels[mask_channel])
                        self._add_l2_regularization_term(loss_func, mask_channel)
                    mask_channel += 1
                loss_func = losses.LossWrapper()
                loss_func.add_loss(face_loss, mask_channel=mask_channels[0])
                self._add_l2_regularization_term(loss_func, mask_channels[0])

                mask_channel = 1
                for multiplier in ("eye_multiplier", "mouth_multiplier"):
                    if self._config[multiplier] > 1:
                        loss_func.add_loss(face_loss,
                                           weight=self._config[multiplier] * 1.0,
                                           mask_channel=mask_channels[mask_channel])
                        self._add_l2_regularization_term(loss_func, mask_channel)
                    mask_channel += 1
                loss_func = losses.LossWrapper()
                loss_func.add_loss(face_loss, mask_channel=mask_channels[0])
                self._add_l2_regularization_term(loss_func, mask_channels[0])

                mask_channel = 1
                for multiplier in ("eye_multiplier", "mouth_multiplier"):
                    if self._config[multiplier] > 1:
                        loss_func.add_loss(face_loss,
                                           weight=self._config[multiplier] * 1.0,
                                           mask_channel=mask_channels[mask_channel])
                        self._add_l2_regularization_term(loss_func, mask_channel)
                    mask_channel += 1
                loss_func = losses.LossWrapper()
                loss_func.add_loss(face_loss, mask_channel=mask_channels[0])
                self._add_l2_regularization_term(loss_func, mask_channels[0])

                mask_channel = 1
                for multiplier in ("eye_multiplier", "mouth_multiplier"):
                    if self._config[multiplier] > 1:
                        loss_func.add_loss(face_loss,
                                           weight=self._config[multiplier] * 1.0,
                                           mask_channel=mask_channels[mask_channel])
                        self._add_l2_regularization_term(loss_func, mask_channel)
                    mask_channel += 1
                loss_func = losses.LossWrapper()
                loss_func.add_loss(face_loss, mask_channel=mask_channels[0])
                self._add_l2_regularization_term(loss_func, mask_channels[0])

                mask_channel = 1
                for multiplier in ("eye_multiplier", "mouth_multiplier"):
                    if self._config[multiplier] > 1:
                        loss_func.add_loss(face_loss,
                                           weight=self._config[multiplier] * 1.0,
                                           mask_channel=mask_channels[mask_channel])
                        self._add_l2_regularization_term(loss_func, mask_channel)
                    mask_channel += 1
                loss_func = losses.LossWrapper()
                loss_func.add_loss(face_loss, mask_channel=mask_channels[0])
                self._add_l2_regularization_term(loss_func, mask_channels[0])

                mask_channel = 1
                for multiplier in ("eye_multiplier", "mouth_multiplier"):
                    if self._config[multiplier] > 1:
                        loss_func.add_loss(face_loss,
                                           weight=self._config[multiplier] * 1.0,
                                           mask_channel=mask_channels[mask_channel])
                        self._add_l2_regularization_term(loss_func, mask_channel)
                    mask_channel += 1
                loss_func = losses.LossWrapper()
                loss_func.add_loss(face_loss, mask_channel=mask_channels[0])
                self._add_l2_regularization_term(loss_func, mask_channels[0])

                mask_channel = 1
                for multiplier in ("eye_multiplier", "mouth_multiplier"):
                    if self._config[multiplier] > 1:
                        loss_func.add_loss(face_loss,
                                           weight=self._config[multiplier] * 1.0,
                                           mask_channel=mask_channels[mask_channel])
                        self._add_l2_regularization_term(loss_func, mask_channel)
                    mask_channel += 1
                loss_func = losses.LossWrapper()
                loss_func.add_loss(face_loss, mask_channel=mask_channels[0])
                self._add_l2_regularization_term(loss_func, mask_channels[0])

                mask_channel = 1
                for multiplier in ("eye_multiplier", "mouth_multiplier"):
                    if self._config[multiplier] > 1:
                        loss_func.add_loss(face_loss,
                                           weight=self._config[multiplier] * 1.0,
                                           mask_channel=mask_channels[mask_channel])
                        self._add_l2_regularization_term(loss_func, mask_channel)
                    mask_channel += 1
                loss_func = losses.LossWrapper()
                loss_func.add_loss(face_loss, mask_channel=mask_channels[0])
                self._add_l2_regularization_term(loss_func, mask_channels[0])

                mask_channel = 1
                for multiplier in ("eye_multiplier", "mouth_multiplier"):
                    if self._config[multiplier] > 1:
                        loss_func.add_loss(face_loss,
                                           weight=self._config[multiplier] * 1.0,
                                           mask_channel=mask_channels[mask_channel])
                        self._add_l2_regularization_term(loss_func, mask_channel)
                    mask_channel += 1
  
              logger.debug("%s: (output_name: '%s', function: %s)", name, output_name, loss_func)
              self._funcs[output_name] = loss_func
          logger.debug("functions: %s", self._funcs)
  
keep keep keep keep replace replace replace replace replace replace replace replace replace replace replace replace keep keep keep keep keep
 Add Mouth and Eye Priority to Loss options (#1054)

* Priority Training for Mouth and Eyes - Tensorflow

* Use chosen loss function for area multipliers

* loss multipliers for AMD

* Fix mask multipliers for plaid and roll PenalizedMaskLoss into LossWrapper

* losses_tf: roll PenalizedMaskLoss into LossWrapper 
plugins/train/model/_base.py