Exemple #1
0
    def prepare_logs(self, losses, input_images, output_images):
        """Return a log dictionary with all insteresting data to log.

        Args:
            losses (dict): A dictionary containing all important losses and skalars to log. 
            input_images (numpy.ndarray, torch.Tensor): Input images to log.
            output_images (numpy.ndarray, torch.Tensor): Output images to log.

        Returns:
            dict: A dictionary containing scalars and images in a Numpy formats.  
        """
        logs = {"images": {}, "scalars": {**losses}}
        # input images
        input_img = pt2np(input_images)
        logs["images"].update({"batch_input": input_img})
        # output images
        output_img = pt2np(output_images)
        logs["images"].update({"batch_output": output_img})
        # log only max three images separately
        max_num = 3 if self.config["batch_size"] > 3 else self.config[
            "batch_size"]
        for i in range(max_num):
            logs["images"].update(
                {"input_" + str(i): np.expand_dims(input_img[i], 0)})
            logs["images"].update(
                {"output_" + str(i): np.expand_dims(output_img[i], 0)})

        logs = convert_logs2numpy(logs)
        return logs
Exemple #2
0
 def prepare_logs(self, losses, predictions):
     """Return a log dictionary with all instersting data to log."""
     # create a dictionary to log with all interesting variables
     logs = {"images": {}, "scalars": {**losses}}
     # generated images
     output_img = pt2np(predictions)
     logs["images"].update({"batch_output": output_img})
     # log only max three images separately
     max_num = 3 if self.config["batch_size"] > 3 else self.config[
         "batch_size"]
     for i in range(max_num):
         logs["images"].update(
             {"output_" + str(i): np.expand_dims(output_img[i], 0)})
     # convert to numpy
     logs = convert_logs2numpy(logs)
     return logs
Exemple #3
0
 def prepare_logs(self, losses, inputs, predictions):
     """Return a log dictionary with all instersting data to log."""
     # create a dictionary to log with all interesting variables
     logs = {"images": {}, "scalars": {**losses}}
     ############
     ## images ##
     ############
     # input images
     real_A_img = pt2np(inputs[0])
     real_B_img = pt2np(inputs[1])
     logs["images"].update({"batch_input_sketch": real_A_img})
     logs["images"].update({"batch_input_face": real_B_img})
     # fake images
     fake_A_img = pt2np(predictions[1])
     fake_B_img = pt2np(predictions[0])
     logs["images"].update({"batch_fake_sketch": fake_A_img})
     logs["images"].update({"batch_fake_face": fake_B_img})
     # reconstructed images
     rec_A_img = pt2np(self.model.output['rec_A'])
     rec_B_img = pt2np(self.model.output['rec_B'])
     logs["images"].update({"batch_rec_sketch": rec_A_img})
     logs["images"].update({"batch_rec_face": rec_B_img})
     # log only max three images separately
     max_num = 3 if self.config["batch_size"] > 3 else self.config[
         "batch_size"]
     for i in range(max_num):
         logs["images"].update(
             {"input_sketch_" + str(i): np.expand_dims(real_A_img[i], 0)})
         logs["images"].update(
             {"input_face_" + str(i): np.expand_dims(real_B_img[i], 0)})
         logs["images"].update(
             {"fake_sketch_" + str(i): np.expand_dims(fake_A_img[i], 0)})
         logs["images"].update(
             {"fake_face_" + str(i): np.expand_dims(fake_B_img[i], 0)})
         logs["images"].update(
             {"rec_sketch_" + str(i): np.expand_dims(rec_A_img[i], 0)})
         logs["images"].update(
             {"rec_face_" + str(i): np.expand_dims(rec_B_img[i], 0)})
     # convert to numpy
     logs = convert_logs2numpy(logs)
     return logs
Exemple #4
0
    def prepare_logs(self, losses, inputs, predictions):
        """Return a log dictionary with all insteresting data to log.
        Args:
            losses (dict): A dictionary containing all important losses and skalars to log. 
            inputs (numpy.ndarray, torch.Tensor): Input images to log.
            predictions (numpy.ndarray, torch.Tensor): Output images to log.
        Returns:
            dict: A dictionary containing scalars and images in a Numpy formats.  
        """
        logs = {"images": {}, "scalars": {**losses}}
        # input images
        real_A_img = pt2np(inputs[0])
        real_B_img = pt2np(inputs[1])
        logs["images"].update({"batch_input_sketch": real_A_img})
        logs["images"].update({"batch_input_face": real_B_img})
        # fake images
        fake_A_img = pt2np(predictions[1])
        fake_B_img = pt2np(predictions[0])
        logs["images"].update({"batch_fake_sketch": fake_A_img})
        logs["images"].update({"batch_fake_face": fake_B_img})
        # reconstruction images
        rec_A_img = pt2np(self.model.output['rec_A'])
        rec_B_img = pt2np(self.model.output['rec_B'])
        logs["images"].update({"batch_rec_sketch": rec_A_img})
        logs["images"].update({"batch_rec_face": rec_B_img})
        # log only max three images separately
        max_num = 3 if self.batch_size > 3 else self.batch_size
        for i in range(max_num):
            logs["images"].update(
                {"input_sketch_" + str(i): np.expand_dims(real_A_img[i], 0)})
            logs["images"].update(
                {"input_face_" + str(i): np.expand_dims(real_B_img[i], 0)})
            logs["images"].update(
                {"fake_sketch_" + str(i): np.expand_dims(fake_A_img[i], 0)})
            logs["images"].update(
                {"fake_face_" + str(i): np.expand_dims(fake_B_img[i], 0)})

        logs = convert_logs2numpy(logs)
        return logs