Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use .npz file #150

Open
priyamp23 opened this issue Dec 5, 2024 · 1 comment
Open

How to use .npz file #150

priyamp23 opened this issue Dec 5, 2024 · 1 comment

Comments

@priyamp23
Copy link

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?

@isaacjones99
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants