Skip to content

Commit

Permalink
update resize youtube to new ver
Browse files Browse the repository at this point in the history
  • Loading branch information
hkchengrex committed Jul 27, 2022
1 parent 0ccdab0 commit f32d786
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions scripts/resize_youtube.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

new_min_size = 480

def resize_vid_jpeg(vid_name):
def resize_vid_jpeg(inputs):
vid_name, folder_path, out_path = inputs

vid_path = path.join(folder_path, vid_name)
vid_out_path = path.join(out_path, 'JPEGImages', vid_name)
os.makedirs(vid_out_path, exist_ok=True)
Expand All @@ -23,7 +25,9 @@ def resize_vid_jpeg(vid_name):
lr_im = hr_im.resize((int(w*ratio), int(h*ratio)), Image.BICUBIC)
lr_im.save(path.join(vid_out_path, im_name))

def resize_vid_anno(vid_name):
def resize_vid_anno(inputs):
vid_name, folder_path, out_path = inputs

vid_path = path.join(folder_path, vid_name)
vid_out_path = path.join(out_path, 'Annotations', vid_name)
os.makedirs(vid_out_path, exist_ok=True)
Expand All @@ -38,30 +42,36 @@ def resize_vid_anno(vid_name):
lr_im.save(path.join(vid_out_path, im_name))


if __name__ == '__main__':
in_path = sys.argv[1]
out_path = sys.argv[2]

def resize_all(in_path, out_path):
for folder in os.listdir(in_path):

if folder not in ['JPEGImages', 'Annotations']:
continue
folder_path = path.join(in_path, folder)
videos = os.listdir(folder_path)

videos = [(v, folder_path, out_path) for v in videos]

if folder == 'JPEGImages':
print('Processing images')
os.makedirs(path.join(out_path, 'JPEGImages'), exist_ok=True)

pool = Pool(processes=16)
pool = Pool(processes=8)
for _ in progressbar(pool.imap_unordered(resize_vid_jpeg, videos), max_value=len(videos)):
pass
else:
print('Processing annotations')
os.makedirs(path.join(out_path, 'Annotations'), exist_ok=True)

pool = Pool(processes=16)
pool = Pool(processes=8)
for _ in progressbar(pool.imap_unordered(resize_vid_anno, videos), max_value=len(videos)):
pass


if __name__ == '__main__':
in_path = sys.argv[1]
out_path = sys.argv[2]

resize_all(in_path, out_path)

print('Done.')

0 comments on commit f32d786

Please sign in to comment.