Add random crop to preprocessor
Prereq for the new dataset. I'd like to keep the preprocessor dependencies to a minimum, so no torchvision transforms.Compose/FiveCrop/etc.
This commit is contained in:
+12
-2
@@ -24,13 +24,23 @@ def process(fname, folder, resolution):
|
||||
return
|
||||
img = Image.open(src)
|
||||
img = img.convert('RGB')
|
||||
img = img.resize((resolution,resolution), Image.LANCZOS)
|
||||
target = (resolution, resolution)
|
||||
if min(img.height, img.width) < 256:
|
||||
return
|
||||
|
||||
if img.width > img.height:
|
||||
target = (int(img.width/img.height*resolution), resolution)
|
||||
elif img.height > img.width:
|
||||
target = (resolution, int(img.height/img.width*resolution))
|
||||
img = img.resize(target, Image.LANCZOS)
|
||||
img = img.crop([0,0,resolution,resolution])
|
||||
img.save(out)
|
||||
|
||||
def thread(queue, pbar, folder, resolution):
|
||||
while not queue.empty():
|
||||
fname = queue.get()
|
||||
process(fname, folder, resolution)
|
||||
try: process(fname, folder, resolution)
|
||||
except: pass
|
||||
queue.task_done()
|
||||
pbar.update()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user