Beispiel #1
0
    def _log_fn(self, context: GANEncoderContext):
        """
        Log output of the generator to Tensorboard.

        Logs G(E(x)).

        Args:
            context (:py:class:`ashpy.contexts.gan.GanEncoderContext`): current context.

        """
        if context.log_eval_mode == LogEvalMode.TEST:
            generator_of_encoder = context.generator_model(
                context.encoder_model(context.encoder_inputs, training=False),
                training=False,
            )
        elif context.log_eval_mode == LogEvalMode.TRAIN:
            generator_of_encoder = context.generator_of_encoder
        else:
            raise ValueError("Invalid LogEvalMode")

        # Tensorboard 2.0 does not support float images in [-1, 1]
        # Only in [0,1]
        if generator_of_encoder.dtype == tf.float32:
            # The hypothesis is that image are in [-1,1] how to check?
            generator_of_encoder = (generator_of_encoder + 1.0) / 2

        log("generator_of_encoder", generator_of_encoder, context.global_step)
Beispiel #2
0
    def _log_fn(context: ClassifierContext) -> None:
        """
        Log output of the image and label to Tensorboard.

        Args:
            context: current context

        """
        input_tensor = context.current_batch[0]
        out_label = context.current_batch[1]

        log("input_x", input_tensor, context.global_step)
        log("input_y", out_label, context.global_step)
Beispiel #3
0
    def _log_fn(self, context: GANContext) -> None:
        """
        Log output of the generator to Tensorboard.

        Args:
            context (:py:class:`ashpy.contexts.gan.GANContext`): current context.

        """
        if context.log_eval_mode == LogEvalMode.TEST:
            out = context.generator_model(context.generator_inputs,
                                          training=False)
        elif context.log_eval_mode == LogEvalMode.TRAIN:
            out = context.fake_samples
        else:
            raise ValueError("Invalid LogEvalMode")

        # tensorboard 2.0 does not support float images in [-1, 1]
        # only in [0,1]
        if out.dtype == tf.float32:
            # The hypothesis is that image are in [-1,1] how to check?
            out = (out + 1.0) / 2

        log("generator", out, context.global_step)