improved-diffusion
improved-diffusion copied to clipboard
How to use .npz file
After sampling, a .npz file is being created. Please let me know - how to handle that and how to create images out of it so that I can see what samples are being created?
You may have worked this out by now, but .npz files are created by the Numpy library and can be loaded using np.load. The data inside is stored in a dictionary-like structure, and you can access it using keys. In this case the keys will be arr_0 and arr_1, where the first contains a list of images and the second contains labels (if class conditioning was used).
You can check what keys are saved within a .npz file with list(data.keys()).
Here's an example of how to load and visualize the samples using Matplotlib:
import numpy as np # Import numpy
import matplotlib.pyplot as plt # Import matplotlib
samples_path = "tmp/samples_4x128x128x3.npz" # Path to the samples .npz file
# Load the .npz file
data = np.load(samples_path)
# Access images and labels
images = data.get('arr_0')
labels = data.get('arr_1')
# Visualize the samples
fig, axes = plt.subplots(nrows=1, ncols=4, figsize=(12, 6))
for i, ax in enumerate(axes.flatten()):
ax.imshow(images[i])
if labels is not None:
ax.set_title(labels[i])
ax.set_axis_off()
plt.tight_layout()
plt.show()
In this example I've set the number of columns to four because that's how many samples I generated but you can increase the number of rows and columns to display more samples.