def __init__(self, input_tensor, losses, input_range=(<NUM_LIT:0>, <NUM_LIT:255>), wrt_tensor=None, norm_grads=True):
self.input_tensor = input_tensor<EOL>self.input_range = input_range<EOL>self.loss_names = []<EOL>self.loss_functions = []<EOL>self.wrt_tensor = self.input_tensor if wrt_tensor is None else wrt_tensor<EOL>if self.input_tensor is self.wrt_tensor:<EOL><INDENT>self.wrt_tensor_is_input_tensor = True<EOL>self.wrt_tensor = K.identity(self.wrt_tensor)<EOL><DEDENT>else:<EOL><INDENT>self.wrt_tensor_is_input_tensor = False<EOL><DEDENT>overall_loss = None<EOL>for loss, weight in losses:<EOL><INDENT>if weight != <NUM_LIT:0>:<EOL><INDENT>loss_fn = weight * loss.build_loss()<EOL>overall_loss = loss_fn if overall_loss is None else overall_loss + loss_fn<EOL>self.loss_names.append(loss.name)<EOL>self.loss_functions.append(loss_fn)<EOL><DEDENT><DEDENT>if self.wrt_tensor_is_input_tensor:<EOL><INDENT>grads = K.gradients(overall_loss, self.input_tensor)[<NUM_LIT:0>]<EOL><DEDENT>else:<EOL><INDENT>grads = K.gradients(overall_loss, self.wrt_tensor)[<NUM_LIT:0>]<EOL><DEDENT>if norm_grads:<EOL><INDENT>grads = K.l2_normalize(grads)<EOL><DEDENT>self.compute_fn = K.function([self.input_tensor, K.learning_phase()],<EOL>self.loss_functions + [overall_loss, grads, self.wrt_tensor])<EOL>
Creates an optimizer that minimizes weighted loss function.

        Args:
            input_tensor: An input tensor of shape: `(samples, channels, image_dims...)` if `image_data_format=
                channels_first` or `(samples, image_dims..., channels)` if `image_data_format=channels_last`.
            losses: List of ([Loss](vis.losses#Loss), weight) tuples.
            input_range: Specifies the input range as a `(min, max)` tuple. This is used to rescale the
                final optimized input to the given range. (Default value=(0, 255))
            wrt_tensor: Short for, with respect to. This instructs the optimizer that the aggregate loss from `losses`
                should be minimized with respect to `wrt_tensor`.
                `wrt_tensor` can be any tensor that is part of the model graph. Default value is set to None
                which means that loss will simply be minimized with respect to `input_tensor`.
            norm_grads: True to normalize gradients. Normalization avoids very small or large gradients and ensures
                a smooth gradient gradient descent process. If you want the actual gradient
                (for example, visualizing attention), set this to false.