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

Two fixes for image resizing in preprocessing #1927

Merged
Merged
Show file tree
Hide file tree
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
16 changes: 16 additions & 0 deletions keras_hub/src/models/preprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,22 @@ def image_converter(self):
def image_converter(self, value):
self._image_converter = value

@property
def image_size(self):
"""Shortcut to get/set the image size of the image converter."""
if self.image_converter is None:
return None
return self.image_converter.image_size

@image_size.setter
def image_size(self, value):
if self.image_converter is None:
raise ValueError(
"Cannot set `image_size` on preprocessor if `image_converter` "
" is `None`."
)
self.image_converter.image_size = value

def get_config(self):
config = super().get_config()
if self.tokenizer:
Expand Down
7 changes: 5 additions & 2 deletions keras_hub/src/models/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def summary(

def highlight_number(x):
if x is None:
f"[color(45)]{x}[/]"
return f"[color(45)]{x}[/]"
return f"[color(34)]{x:,}[/]" # Format number with commas.

def highlight_symbol(x):
Expand Down Expand Up @@ -339,7 +339,10 @@ def add_layer(layer, info):
add_layer(layer, info)
elif isinstance(layer, ImageConverter):
info = "Image size: "
info += highlight_shape(layer.image_size)
image_size = layer.image_size
if image_size is None:
image_size = (None, None)
info += highlight_shape(image_size)
add_layer(layer, info)
elif isinstance(layer, AudioConverter):
info = "Audio shape: "
Expand Down
Loading