Giter VIP home page Giter VIP logo

Comments (5)

Zhangzeyu7 avatar Zhangzeyu7 commented on September 25, 2024

you can try 'amp = True'

from denoising-diffusion-pytorch.

moonnnpie avatar moonnnpie commented on September 25, 2024

you can try 'amp = True'

thanks but i tried and found that the images turns out total green

from denoising-diffusion-pytorch.

nilsleh avatar nilsleh commented on September 25, 2024

I am also currently trying to get some reasonable results for the FFHQ dataset, and also want to try Celeba-HQ.

from denoising_diffusion_pytorch import Unet, GaussianDiffusion, Trainer
from torch.utils.data import DataLoader
from torchvision.datasets import VisionDataset
from torchvision.transforms.functional import pil_to_tensor
from PIL import Image

class FFHQDataset(VisionDataset):
    def __init__(self, root: str):
        super().__init__(root)

        self.fpaths = sorted(glob(root + '/**/*.png', recursive=True))
        assert len(self.fpaths) > 0, "File list is empty. Check the root."

    def __len__(self):
        return len(self.fpaths)

    def __getitem__(self, index: int):
        fpath = self.fpaths[index]
        img = Image.open(fpath).convert('RGB')
        # normalize to [0, 1] range
        img = pil_to_tensor(img) / 255.
        return img


model = Unet(
    dim = 64,
    dim_mults = (1, 2, 4, 8, 16, 32),
    flash_attn = True
)

diffusion = GaussianDiffusion(
    model,
    image_size = 128,
    timesteps = 1000,           # number of steps
    sampling_timesteps=500
)

dataset = FFHQDataset(root="/mnt/SSD2/nils/ocean_bench_exps/diffusion/data/ffhq/thumbnails128x128")
dataloader = DataLoader(dataset, batch_size = 32, shuffle = True, pin_memory = True, num_workers = 12)

trainer = Trainer(
    diffusion,
    'path/to/your/images',
    train_lr = 8e-5,
    train_num_steps = 50000,         # total training steps
    gradient_accumulate_every = 2,    # gradient accumulation steps
    ema_decay = 0.995,                # exponential moving average decay
    amp = False,
    num_samples=16,
    save_and_sample_every=10000,
    dl = dataloader,
)

trainer.train()

I gave the trainer a dataloader argument, because I wanted control over different dataloaders and their configurations, so effectively, just replaced the dataset and dl code block to just take the dl argument from the Trainer. The following are some samples, loss is around 0.02-0.03.

It was mentioned here that amp=False helps, but I have tried both and there is no significant change.

Screenshot from 2024-03-22 12-56-48

Overall I would also expect better results, so I am wondering if people have experience and suggestions?

Edit:
Training for longer seems to improve results a bit (300,000 training steps)
sample-30

from denoising-diffusion-pytorch.

nilsleh avatar nilsleh commented on September 25, 2024

These are results on the CelebHQ datset:

sample-29

from denoising-diffusion-pytorch.

szh404 avatar szh404 commented on September 25, 2024

you can try 'amp = True'

thanks but i tried and found that the images turns out total green

Have you solved this problem? I meet this problem recently.

from denoising-diffusion-pytorch.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.