Skip to content

Possibly incorrect image normalization step in examples/dreambooth/train_dreambooth.py #985

@john-sungjin

Description

@john-sungjin

Describe the bug

I was studying the train_dreambooth.py script (link) and noticed that the DreamBoothDataset performs an image normalization step as one of the transforms (line 260), setting mean to 0.5 and standard deviation to 0.5:

        self.image_transforms = transforms.Compose(
            [
                transforms.Resize(size, interpolation=transforms.InterpolationMode.BILINEAR),
                transforms.CenterCrop(size) if center_crop else transforms.RandomCrop(size),
                transforms.ToTensor(),
                transforms.Normalize([0.5], [0.5]), # <--- this line
            ]
        )

However, this seems to differ from the original Stable Diffusion training implementation, which instead rescales image pixel values from [0, 255] to [0, 1] (link, line 369):

        example["image"] = (image/127.5 - 1.0).astype(np.float32)
        example["LR_image"] = (LR_image/127.5 - 1.0).astype(np.float32)

Is there a reason for the discrepancy? Was wondering if this was intended or a bug - it seems like changing the normalization procedure from the original model would impact fine-tuning performance. Thanks for the help!

Reproduction

No response

Logs

No response

System Info

Latest version

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions