stylegan2 icon indicating copy to clipboard operation
stylegan2 copied to clipboard

unable to create dataset

Open torakoneko opened this issue 4 years ago • 3 comments

i'm attempting to create a dataset from images that are 320x448 (5x7 res-log2 = 6) but when i attempt to run the dataset tool with !python /content/stylegan2/dataset_tool.py create_from_images_raw --res_log2=6 ./dataset/CADGAN_320_448 '/content/CADGAN_320_448' i get this error

Loading images from "/content/CADGAN_320_448" detected 7114 images ... Shuffle the images... Creating dataset "./dataset/CADGAN_320_448" Added 0 images. Traceback (most recent call last): File "/content/stylegan2/dataset_tool.py", line 950, in <module> execute_cmdline(sys.argv) File "/content/stylegan2/dataset_tool.py", line 944, in execute_cmdline func(**vars(args)) File "/content/stylegan2/dataset_tool.py", line 710, in create_from_images_raw tfr.create_tfr_writer(img.shape) File "/content/stylegan2/dataset_tool.py", line 96, in create_tfr_writer assert self.shape[1] % (2 ** self.res_log2) == 0 AssertionError

i assume this has something to do with the size of the images, but i'm kind of at a loss otherwise.

torakoneko avatar Apr 27 '20 07:04 torakoneko

Hi, for creating image from raw, there is assumption that all images in source folder have been resized to the desired size. You may try to print the name and dimension of the image to find out the problematic piece. (sometimes there are hidden image files in the folder). Or you may try to add some resize logic.

skyflynil avatar Apr 28 '20 22:04 skyflynil

Hi, for creating image from raw, there is assumption that all images in source folder have been resized to the desired size. You may try to print the name and dimension of the image to find out the problematic piece. (sometimes there are hidden image files in the folder). Or you may try to add some resize logic.

All the files are 320x448 according to my computer. How would I check for hidden files? I have the "show hidden files" thing checked in explorer on my computer and there's no extra files showing. I'm not great at python, sorry...

torakoneko avatar Apr 30 '20 21:04 torakoneko

Hi, for creating image from raw, there is assumption that all images in source folder have been resized to the desired size. You may try to print the name and dimension of the image to find out the problematic piece. (sometimes there are hidden image files in the folder). Or you may try to add some resize logic.

All the files are 320x448 according to my computer. How would I check for hidden files? I have the "show hidden files" thing checked in explorer on my computer and there's no extra files showing. I'm not great at python, sorry...

Resizing all the images in the form 2^n * 2^n of width and height worked for me. Images must be square and should have same width and height.

Here the code to resize all the images in 512*512 shape. 2^9

from PIL import Image
import os, sys
import glob

for filename in glob.iglob('../path_to_my_dataset' + '/*.jpg', recursive=True):
    print(filename)
    im = Image.open(filename)
    imResize = im.resize((512,512), Image.ANTIALIAS)
    imResize.save(filename , 'JPEG', quality=90)

Hope it helps.

@torakoneko

Sadam1195 avatar Sep 27 '20 10:09 Sadam1195