-
-
Save metacritical/c47f0bb0f385e68da62d2d520b1643bb to your computer and use it in GitHub Desktop.
Save kandinsky generated images
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# tutorial video link : https://youtu.be/dYt9xJ7dnpU | |
# colab link : https://colab.research.google.com/drive/1xSbu-b-EwYd6GdaFPRVgvXBX_mciZ41e?usp=sharing | |
# repo link : https://github.com/ai-forever/Kandinsky-2 | |
# used repo commit hash : a4354c04d5fbd48851866ef7d84ec444d3d50102 | |
# those who getting cuda error | |
# pip uninstall torch | |
# pip3 install torch==1.13.1 torchvision torchaudio --index-url https://download.pytorch.org/whl/cu117 | |
import os | |
import uuid | |
from PIL import Image | |
# Set the number of iterations | |
num_iterations = 10 | |
for iteration in range(num_iterations): | |
print(f"Generating images for iteration {iteration + 1}/{num_iterations}...") | |
images = model.generate_text2img( | |
"lion, jungle, cartoon, ultra realistic", | |
num_steps=40, | |
batch_size=1, | |
guidance_scale=4, | |
h=768, | |
w=768, | |
sampler='p_sampler', | |
prior_cf_scale=4, | |
prior_steps="5" | |
) | |
# path to the folder where the images will be saved | |
folder_path = 'C:/Kandinsky-2/imgs' | |
# generate a unique identifier | |
guid = uuid.uuid4() | |
# loop through all images in the list | |
for i, image in enumerate(images): | |
# create the file name using the GUID, index, and the image file extension | |
file_name = f"{guid}_{i}.png" | |
# display the image | |
display(image) | |
# save the image to the folder with the GUID and index name | |
file_path = os.path.join(folder_path, file_name) | |
image.save(file_path) | |
remaining_iterations = num_iterations - (iteration + 1) | |
print(f"Completed iteration {iteration + 1}/{num_iterations}. {remaining_iterations} iteration(s) remaining.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment