PyTorch-VAE icon indicating copy to clipboard operation
PyTorch-VAE copied to clipboard

Problems when using custom dataset

Open denisb411 opened this issue 1 year ago • 8 comments

Hello,

I tried to code a custom dataset class for training but the images generated on samples and reconstruction are all messed.

To code the dataset class I was inspired by the Oxford Pets dataset class that was commented on dataset.py file, and it's looking like that:

# Add your custom dataset class here
class MyDataset(Dataset):
    def __init__(self, 
                 data_path: str, 
                 split: str,
                 transform: Callable,
                **kwargs):
        self.data_dir = Path(data_path)    
        self.transforms = transform
        imgs = sorted([f for f in self.data_dir.iterdir() if f.suffix == '.jpg'])

        self.imgs = imgs[:int(len(imgs) * 0.75)] if split == "train" else imgs[int(len(imgs) * 0.75):]

    def __len__(self):
        return len(self.imgs)
    
    def __getitem__(self, idx):
        img = default_loader(self.imgs[idx])
        
        if self.transforms is not None:
            img = self.transforms(img)
        

The samples generated: image

The reconstruction: image

In order to debug, I used the following code, and it seems that the images are fine:

        DEBUG_DIR = './debug'
        shutil.rmtree(DEBUG_DIR, ignore_errors=True)
        os.makedirs(DEBUG_DIR, exist_ok=True)
        for i, img in enumerate(self.val_dataset):
            img = img[0]
            img = img.permute(1, 2, 0)
            img = (img * 255).numpy().astype(np.uint8)
            img = Image.fromarray(img)
            img.save(os.path.join(DEBUG_DIR, uuid.uuid4().hex + '.jpg'))

            if i == 10:
                break

image

Can someone give me a light about what I am missing?

denisb411 avatar Nov 13 '23 17:11 denisb411

Any solution about this?

bserranoanton avatar Apr 03 '24 12:04 bserranoanton

Any solution about this?

May I ask if you have resolved it? I have also encountered the same problem. Can you communicate with me

kuailexiaohunzi avatar Apr 25 '24 01:04 kuailexiaohunzi

Hi @denisb411 , Hi all! @denisb411 I think your post misses a few thinks, notably the change you have to perform on the run.py file, and the config file you use. I mean, I assume you just run the run.py file?

@kuailexiaohunzi Maybe you should open a dedicated issue with details on what issues you encoutered :)

P.S: Seeing the last updates on this repo, I sadly think it is not maintained anymore :(

MisterBourbaki avatar Apr 25 '24 07:04 MisterBourbaki

Hi @denisb411 , Hi all! @denisb411 I think your post misses a few thinks, notably the change you have to perform on the run.py file, and the config file you use. I mean, I assume you just run the run.py file?

@kuailexiaohunzi Maybe you should open a dedicated issue with details on what issues you encoutered :)

P.S: Seeing the last updates on this repo, I sadly think it is not maintained anymore :(

My current problem is that I want to use VAE to test on my own dataset, but the results are not satisfactory. The image below is my reconstructed image. recons_VanillaVAE_Epoch_0 I modified the hyperparameters in the configuration file, but the effect was minimal. I am not sure if it is because my dataset does not have attribute files. How do you think this problem should be solved? Can we exchange ideas

kuailexiaohunzi avatar Apr 25 '24 08:04 kuailexiaohunzi

I am sorry but could you be more precise? The best way would be to open a dedicated Issue, as your problems may not be the same as @denisb411 . Provide as much information as you can (where the data are, what they are, what Python file did you run, is it after training...). Then I may be able to help you :)

MisterBourbaki avatar Apr 25 '24 08:04 MisterBourbaki

I am sorry but could you be more precise? The best way would be to open a dedicated Issue, as your problems may not be the same as @denisb411 . Provide as much information as you can (where the data are, what they are, what Python file did you run, is it after training...). Then I may be able to help you :)

I have opened a special question and I hope to receive your help. If you need to provide any information, please feel free to contact me. Thank you

kuailexiaohunzi avatar Apr 25 '24 08:04 kuailexiaohunzi

Any solution about this?

May I ask if you have resolved it? I have also encountered the same problem. Can you communicate with me

Yes, I had to change dimensions in order to have a larger patch size. For instance, in models/vanilla_vae.py imagen imagen imagen

bserranoanton avatar Apr 26 '24 07:04 bserranoanton

change di

I have also modified these parameters before, but they did not solve my problem. Thank you for your reply

kuailexiaohunzi avatar Apr 26 '24 07:04 kuailexiaohunzi