Created
April 9, 2020 06:01
-
-
Save ryul99/31e8b31366885e4e6781f6f91f34f88a to your computer and use it in GitHub Desktop.
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
import cv2 | |
import glob | |
import os | |
import tqdm | |
from itertools import islice | |
from multiprocessing import Pool | |
from pathlib import Path | |
path = r'D:\Google Drive(SNU)\Study\Dataset\EDVR\Inference\dance_1080_120fs\dance_4k_60fps_downscaled\*.png' | |
img_size = [(1080, 2048,3)] # Width, Height | |
def split_image(_file): | |
if(os.path.isdir(_file)): | |
return | |
img = cv2.imread(_file, cv2.IMREAD_UNCHANGED) | |
try: | |
img.shape | |
except AttributeError: | |
print(_file) | |
if img.shape not in img_size: | |
raise ValueError("image shape (%s) is not in %s" % (img.shape, img_size)) | |
if __name__ == '__main__': | |
num_process = 16 | |
files = glob.glob(path, recursive=True) | |
len_total = len(files) | |
# iter_files = iter(files) | |
# files = [list(islice(iter_files, e)) for e in [len(files) // num_process] * (num_process + 1)] | |
with Pool(processes=num_process) as p: | |
r = list(tqdm.tqdm(p.imap(split_image, files), total=len_total)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment