Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

discard unusable images #13

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Update prepare_data.py
sidphbot authored Jul 27, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit cb291dac3ff960fcc66cf559abc9551756df932c
20 changes: 12 additions & 8 deletions prepare_data.py
Original file line number Diff line number Diff line change
@@ -33,9 +33,12 @@ def resize_multiple(

def resize_worker(img_file, sizes, resample):
i, file = img_file
img = Image.open(file)
img = img.convert("RGB")
out = resize_multiple(img, sizes=sizes, resample=resample)
try:
img = Image.open(file)
img = img.convert("RGB")
out = resize_multiple(img, sizes=sizes, resample=resample)
except:
out = []

return i, out

@@ -51,13 +54,14 @@ def prepare(

with multiprocessing.Pool(n_worker) as pool:
for i, imgs in tqdm(pool.imap_unordered(resize_fn, files)):
for size, img in zip(sizes, imgs):
key = f"{size}-{str(i).zfill(5)}".encode("utf-8")
if len(imgs) != 0:
for size, img in zip(sizes, imgs):
key = f"{size}-{str(i).zfill(5)}".encode("utf-8")

with env.begin(write=True) as txn:
txn.put(key, img)
with env.begin(write=True) as txn:
txn.put(key, img)

total += 1
total += 1

with env.begin(write=True) as txn:
txn.put("length".encode("utf-8"), str(total).encode("utf-8"))