Skip to content

Commit

Permalink
fix: upload failure due to non-rgb image (#335)
Browse files Browse the repository at this point in the history
* fix: upload failure due to non-rgb image

* fix: convert if image already in case

* fix: path exists, type ignore

* style: lint

* fix: typing

* fix: im not sure
  • Loading branch information
zanussbaum authored Aug 27, 2024
1 parent f474849 commit 3358a0e
Showing 1 changed file with 3 additions and 1 deletion.
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:
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

0 comments on commit 3358a0e

Please sign in to comment.