import glob import os from os import path as osp from PIL import Image # print(len(sorted(glob.glob('GT_sub/*')))) # raise NotImplementedError with open('meta_info_DFO.txt', 'w') as f: for idx, img_path in enumerate(sorted(glob.glob('GT_sub/*'))): filename = osp.basename(img_path) # img = Image.open(img_path) # lazy load # width, height = img.size # mode = img.mode # if mode == 'RGB': # n_channel = 3 # elif mode == 'L': # n_channel = 1 # else: # raise ValueError(f'Unsupported mode {mode}.') info = f'{filename} (480,480,3)' print(idx + 1, info) f.write(f'{info}\n')