Skip to content

[draft] excess image resize maintain aspect ratio - #378

Open
mcembalest wants to merge 1 commit into
mainfrom
resize-maintain-aspect-ratio
Open

[draft] excess image resize maintain aspect ratio#378
mcembalest wants to merge 1 commit into
mainfrom
resize-maintain-aspect-ratio

Conversation

@mcembalest

@mcembalest mcembalest commented Mar 7, 2025

Copy link
Copy Markdown
Contributor

Currently images seem to get hard-adjusted to 512,512 if either width or height exceeds 512

image

we have a helper function to resize images while maintaining aspect ratio so this PR re-uses it


Important

Replace hard-coded image resize with resize_pil() to maintain aspect ratio in dataset.py and embed.py.

  • Behavior:
    • Replace hard-coded image resize with resize_pil() in _add_blobs() in dataset.py and image() in embed.py to maintain aspect ratio.
  • Functions:
    • Move resize_pil() from embed.py to utils.py for reuse.
  • Imports:
    • Add resize_pil import to dataset.py and embed.py.

This description was created by Ellipsis for 9aeee9e. It will automatically update as commits are pushed.

Comment thread nomic/utils.py
max_width = 512
max_height = 512
if width > max_width or height > max_height:
downsize_factor = max(width // max_width, height // max_height)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The new helper function resize_pil computes the downsize_factor using integer division (e.g. width // max_width), so for images only slightly above 512 (e.g. 600×700) the factor is 1 and no resizing occurs. Consider computing a floating‑point scale factor (e.g. scale = min(max_width/width, max_height/height)) and then resizing with new dimensions (int(width*scale), int(height*scale)). Also, specify a resampling filter like Image.LANCZOS for better quality.

@mcembalest mcembalest changed the title excess image resize maintain aspect ratio [draft] excess image resize maintain aspect ratio Mar 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant