(limit=None)
| 57 | |
| 58 | |
| 59 | def get_celeb(limit=None): |
| 60 | if not os.path.exists('../large_files'): |
| 61 | os.mkdir('../large_files') |
| 62 | |
| 63 | # eventual place where our final data will reside |
| 64 | if not os.path.exists('../large_files/img_align_celeba-cropped'): |
| 65 | |
| 66 | # check for original data |
| 67 | if not os.path.exists('../large_files/img_align_celeba'): |
| 68 | # download the file and place it here |
| 69 | if not os.path.exists('../large_files/img_align_celeba.zip'): |
| 70 | print("Downloading img_align_celeba.zip...") |
| 71 | download_file( |
| 72 | '0B7EVK8r0v71pZjFTYXZWM3FlRnM', |
| 73 | '../large_files/img_align_celeba.zip' |
| 74 | ) |
| 75 | |
| 76 | # unzip the file |
| 77 | print("Extracting img_align_celeba.zip...") |
| 78 | with zipfile.ZipFile('../large_files/img_align_celeba.zip') as zf: |
| 79 | zip_dir = zf.namelist()[0] |
| 80 | zf.extractall('../large_files') |
| 81 | |
| 82 | |
| 83 | # load in the original images |
| 84 | filenames = glob("../large_files/img_align_celeba/*.jpg") |
| 85 | N = len(filenames) |
| 86 | print("Found %d files!" % N) |
| 87 | |
| 88 | |
| 89 | # crop the images to 64x64 |
| 90 | os.mkdir('../large_files/img_align_celeba-cropped') |
| 91 | print("Cropping images, please wait...") |
| 92 | |
| 93 | for i in range(N): |
| 94 | crop_and_resave(filenames[i], '../large_files/img_align_celeba-cropped') |
| 95 | if i % 1000 == 0: |
| 96 | print("%d/%d" % (i, N)) |
| 97 | |
| 98 | |
| 99 | # make sure to return the cropped version |
| 100 | filenames = glob("../large_files/img_align_celeba-cropped/*.jpg") |
| 101 | return filenames |
| 102 | |
| 103 | |
| 104 | def crop_and_resave(inputfile, outputdir): |
nothing calls this directly
no test coverage detected