improved-diffusion icon indicating copy to clipboard operation
improved-diffusion copied to clipboard

How to train gray pictures?

Open WathomeBo opened this issue 2 years ago • 2 comments

When the image_dataset loads pictures, it will automatically convert the pictrue to rgb. However, i just want to keep the original type

WathomeBo avatar Dec 24 '23 06:12 WathomeBo

To train the model for 1 channel, you need to go to the image_datasets.py file and comment out line 97: arr = np.array(pil_image.convert("RGB")). This line forces the input channel to be RGB.

Then add this 2 lines after the line you commented: arr = np.array(pil_image) arr = arr.reshape((self.resolution, self.resolution, 1))

tobi-ore avatar Jan 11 '24 20:01 tobi-ore

I made the following changes, and it worked:

In image_datasets.py,

# arr = np.array(pil_image.convert("RGB")) # commenting this line
arr = np.array(pil_image) # add this line
arr = arr.reshape((arr.shape[0], arr.shape[1], 1)) # add this line

In script_util.py, change the in_channels and out_channels variables being sent to UNetModel. Specifically:

return UNetModel(
    in_channels=1,
    model_channels=num_channels,
    out_channels=(1 if not learn_sigma else 2),

Saumya-Gupta-26 avatar Feb 01 '24 22:02 Saumya-Gupta-26