Wakame
Wakame

Reputation: 607

What is the difference of the images with int32 and float32?

Why are the outputs of the image with int32 and float32 different, although the values look similar?

for x in dataset:
    plt.axis("off")
    plt.imshow((x.numpy()*255).astype("int32")[0])
    break

and

for x in dataset:
    plt.axis("off")
    plt.imshow((x.numpy()*255).astype("float32")[0])
    break

In the case of float32, the white color influence become large.

The dataset is celeba, which is downloaded from the code,

#download data into created directory
os.makedirs("celeba_gan", exist_ok=True)
url = "https://drive.google.com/uc?id=1O7m1010EJjLE5QxLZiM9Fpjs7Oj6e684"
output = "celeba_gan/data.zip"
gdown.download(url, output, quiet=True)

with ZipFile("celeba_gan/data.zip", "r") as zipobj:
    zipobj.extractall("celeba_gan")


#dataset
dataset = keras.preprocessing.image_dataset_from_directory("celeba_gan", label_mode=None, image_size=(64, 64), batch_size=32)
dataset = dataset.map(lambda x: x / 255.0)

Upvotes: 1

Views: 391

Answers (1)

Wakame
Wakame

Reputation: 607

I figured out the issue. imshow with RGB data should set [0..1] for floats or [0..255] for integers.

Upvotes: 1

Related Questions