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

fix: upload failure due to non-rgb image #335

Merged
merged 6 commits into from
Aug 27, 2024
Merged
Changes from all commits
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
4 changes: 3 additions & 1 deletion nomic/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1409,9 +1409,10 @@ def _add_blobs(
# TODO: add support for other modalities
images = []
for uuid, blob in tqdm(zip(ids, blobs), total=len(ids), desc="Loading images"):
if isinstance(blob, str) and os.path.exists(blob):
if (isinstance(blob, str) or isinstance(blob, Path)) and os.path.exists(blob):
# Auto resize to max 512x512
image = Image.open(blob)
image = image.convert("RGB")
if image.height > 512 or image.width > 512:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The resizing logic should maintain the aspect ratio. Consider using image.thumbnail((512, 512), Image.ANTIALIAS) to resize while maintaining the aspect ratio.

image = image.resize((512, 512))
buffered = BytesIO()
Expand All @@ -1420,6 +1421,7 @@ def _add_blobs(
elif isinstance(blob, bytes):
images.append((uuid, blob))
elif isinstance(blob, Image.Image):
blob = blob.convert("RGB") # type: ignore
if blob.height > 512 or blob.width > 512:
blob = blob.resize((512, 512))
buffered = BytesIO()
Expand Down