junyanz / pytorch-CycleGAN-and-pix2pix

Image-to-Image Translation in PyTorch
Other
22.8k stars 6.29k forks source link

The real_A image becomes the splicing of A and B domain images #1559

Closed Ivvvvvvvvvvy closed 1 year ago

Ivvvvvvvvvvy commented 1 year ago

hi, I'm using the cycleGAN model for street view image (.jpg) to mel-spectrogram (.npy, range 0 to 1) conversion.So, I created the trainA folder to store jpg, and the trainB folder to store npy files .

So I changed the way of data loading, the code is as follows, but there is a problem, in some epochs, the generated real_A image becomes a mosaic of mel pictures and street view images, but in some epochs it is normal, do you know why will it be like this

def __getitem__(self, index):
        A_path = self.A_paths[index % self.A_size]  # make sure index is within then range
        if self.opt.serial_batches:   # make sure index is within then range
            index_B = index % self.B_size
        else:   # randomize the index for domain B to avoid fixed pairs.
            index_B = random.randint(0, self.B_size - 1)
        B_path = self.B_paths[index_B]
        A_img = Image.open(A_path).convert('RGB')
        B_img = np.load(B_path)
        # apply image transformation
        A = self.transform_A(A_img)
        B = torch.from_numpy(B_img).to(torch.float32).unsqueeze(0)
        return {'A': A, 'B': B, 'A_paths': A_path, 'B_paths': B_path}

normal image: epoch001_real_A

error image: epoch002_real_A

taesungp commented 1 year ago

I am not exactly how you visualize this, but one issue could be that you are doing B_img = np.load(B_path) followed by B = torch.from_numpy(B_img).to(torch.float32).unsqueeze(0). The resulting tensor may not be of BCHW shape.

Ivvvvvvvvvvy commented 1 year ago

I am not exactly how you visualize this, but one issue could be that you are doing followed by . The resulting tensor may not be of BCHW shape.B_img = np.load(B_path)``B = torch.from_numpy(B_img).to(torch.float32).unsqueeze(0)

Thank you very much for your answer! I'll give it a try!!