Skip to content

update input_image_shape -> image_shape #1785

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

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
10 changes: 5 additions & 5 deletions keras_nlp/src/models/csp_darknet/csp_darknet_backbone.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class CSPDarkNetBackbone(Backbone):
Use `"depthwise_block"` for depthwise conv block
`"basic_block"` for basic conv block.
Defaults to "basic_block".
input_image_shape: tuple. The input shape without the batch size.
image_shape: tuple. The input shape without the batch size.
Defaults to `(None, None, 3)`.

Examples:
Expand Down Expand Up @@ -67,7 +67,7 @@ def __init__(
stackwise_depth,
include_rescaling,
block_type="basic_block",
input_image_shape=(224, 224, 3),
image_shape=(224, 224, 3),
**kwargs,
):
# === Functional Model ===
Expand All @@ -78,7 +78,7 @@ def __init__(
)
base_channels = stackwise_num_filters[0] // 2

image_input = layers.Input(shape=input_image_shape)
image_input = layers.Input(shape=image_shape)
x = image_input
if include_rescaling:
x = layers.Rescaling(scale=1 / 255.0)(x)
Expand Down Expand Up @@ -119,7 +119,7 @@ def __init__(
self.stackwise_depth = stackwise_depth
self.include_rescaling = include_rescaling
self.block_type = block_type
self.input_image_shape = input_image_shape
self.image_shape = image_shape

def get_config(self):
config = super().get_config()
Expand All @@ -129,7 +129,7 @@ def get_config(self):
"stackwise_depth": self.stackwise_depth,
"include_rescaling": self.include_rescaling,
"block_type": self.block_type,
"input_image_shape": self.input_image_shape,
"image_shape": self.image_shape,
}
)
return config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def setUp(self):
"stackwise_depth": [1, 3, 3, 1],
"include_rescaling": False,
"block_type": "basic_block",
"input_image_shape": (224, 224, 3),
"image_shape": (224, 224, 3),
}
self.input_data = np.ones((2, 224, 224, 3), dtype="float32")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class CSPDarkNetImageClassifier(ImageClassifier):
stackwise_depth=[3, 9, 9, 3],
include_rescaling=False,
block_type="basic_block",
input_image_shape = (224, 224, 3),
image_shape = (224, 224, 3),
)
classifier = keras_nlp.models.CSPDarkNetImageClassifier(
backbone=backbone,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def setUp(self):
stackwise_depth=[1, 3, 3, 1],
include_rescaling=False,
block_type="basic_block",
input_image_shape=(16, 16, 3),
image_shape=(16, 16, 3),
)
self.init_kwargs = {
"backbone": self.backbone,
Expand Down
10 changes: 5 additions & 5 deletions keras_nlp/src/models/densenet/densenet_backbone.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class DenseNetBackbone(Backbone):
include_rescaling: bool, whether to rescale the inputs. If set
to `True`, inputs will be passed through a `Rescaling(1/255.0)`
layer. Defaults to `True`.
input_image_shape: optional shape tuple, defaults to (224, 224, 3).
image_shape: optional shape tuple, defaults to (224, 224, 3).
compression_ratio: float, compression rate at transition layers,
defaults to 0.5.
growth_rate: int, number of filters added by each dense block,
Expand All @@ -62,13 +62,13 @@ def __init__(
self,
stackwise_num_repeats,
include_rescaling=True,
input_image_shape=(224, 224, 3),
image_shape=(224, 224, 3),
compression_ratio=0.5,
growth_rate=32,
**kwargs,
):
# === Functional Model ===
image_input = keras.layers.Input(shape=input_image_shape)
image_input = keras.layers.Input(shape=image_shape)

x = image_input
if include_rescaling:
Expand Down Expand Up @@ -116,7 +116,7 @@ def __init__(
self.include_rescaling = include_rescaling
self.compression_ratio = compression_ratio
self.growth_rate = growth_rate
self.input_image_shape = input_image_shape
self.image_shape = image_shape

def get_config(self):
config = super().get_config()
Expand All @@ -126,7 +126,7 @@ def get_config(self):
"include_rescaling": self.include_rescaling,
"compression_ratio": self.compression_ratio,
"growth_rate": self.growth_rate,
"input_image_shape": self.input_image_shape,
"image_shape": self.image_shape,
}
)
return config
Expand Down
2 changes: 1 addition & 1 deletion keras_nlp/src/models/densenet/densenet_backbone_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def setUp(self):
"include_rescaling": True,
"compression_ratio": 0.5,
"growth_rate": 32,
"input_image_shape": (224, 224, 3),
"image_shape": (224, 224, 3),
}
self.input_data = np.ones((2, 224, 224, 3), dtype="float32")

Expand Down
2 changes: 1 addition & 1 deletion keras_nlp/src/models/densenet/densenet_image_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class DenseNetImageClassifier(ImageClassifier):
stackwise_depth=[3, 9, 9, 3],
include_rescaling=False,
block_type="basic_block",
input_image_shape = (224, 224, 3),
image_shape = (224, 224, 3),
)
classifier = keras_nlp.models.DenseNetImageClassifier(
backbone=backbone,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def setUp(self):
include_rescaling=True,
compression_ratio=0.5,
growth_rate=32,
input_image_shape=(224, 224, 3),
image_shape=(224, 224, 3),
)
self.init_kwargs = {
"backbone": self.backbone,
Expand Down
10 changes: 5 additions & 5 deletions keras_nlp/src/models/resnet/resnet_backbone.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class ResNetBackbone(FeaturePyramidBackbone):
include_rescaling: boolean. If `True`, rescale the input using
`Rescaling` and `Normalization` layers. If `False`, do nothing.
Defaults to `True`.
input_image_shape: tuple. The input shape without the batch size.
image_shape: tuple. The input shape without the batch size.
Defaults to `(None, None, 3)`.
pooling: `None` or str. Pooling mode for feature extraction. Defaults
to `"avg"`.
Expand Down Expand Up @@ -107,7 +107,7 @@ def __init__(
block_type,
use_pre_activation=False,
include_rescaling=True,
input_image_shape=(None, None, 3),
image_shape=(None, None, 3),
pooling="avg",
data_format=None,
dtype=None,
Expand Down Expand Up @@ -139,7 +139,7 @@ def __init__(
num_stacks = len(stackwise_num_filters)

# === Functional Model ===
image_input = layers.Input(shape=input_image_shape)
image_input = layers.Input(shape=image_shape)
if include_rescaling:
x = layers.Rescaling(scale=1 / 255.0, dtype=dtype)(image_input)
x = layers.Normalization(
Expand Down Expand Up @@ -254,7 +254,7 @@ def __init__(
self.block_type = block_type
self.use_pre_activation = use_pre_activation
self.include_rescaling = include_rescaling
self.input_image_shape = input_image_shape
self.image_shape = image_shape
self.pooling = pooling
self.pyramid_outputs = pyramid_outputs

Expand All @@ -268,7 +268,7 @@ def get_config(self):
"block_type": self.block_type,
"use_pre_activation": self.use_pre_activation,
"include_rescaling": self.include_rescaling,
"input_image_shape": self.input_image_shape,
"image_shape": self.image_shape,
"pooling": self.pooling,
}
)
Expand Down
4 changes: 2 additions & 2 deletions keras_nlp/src/models/resnet/resnet_backbone_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def setUp(self):
"stackwise_num_filters": [64, 64, 64],
"stackwise_num_blocks": [2, 2, 2],
"stackwise_num_strides": [1, 2, 2],
"input_image_shape": (None, None, 3),
"image_shape": (None, None, 3),
"pooling": "avg",
}
self.input_size = 64
Expand Down Expand Up @@ -84,7 +84,7 @@ def test_saved_model(self, use_pre_activation, block_type):
{
"block_type": block_type,
"use_pre_activation": use_pre_activation,
"input_image_shape": (None, None, 3),
"image_shape": (None, None, 3),
}
)
self.run_model_saving_test(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def setUp(self):
stackwise_num_strides=[1, 2, 2],
block_type="basic_block",
use_pre_activation=True,
input_image_shape=(16, 16, 3),
image_shape=(16, 16, 3),
include_rescaling=False,
pooling="avg",
)
Expand Down
15 changes: 7 additions & 8 deletions keras_nlp/src/models/vgg/vgg_backbone.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@

@keras_nlp_export("keras_nlp.models.VGGBackbone")
class VGGBackbone(Backbone):
"""
This class represents Keras Backbone of VGG model.
"""This class represents Keras Backbone of VGG model.

This class implements a VGG backbone as described in [Very Deep
Convolutional Networks for Large-Scale Image Recognition](
Expand All @@ -36,7 +35,7 @@ class VGGBackbone(Backbone):
64, 128, 256, 512, 512].
include_rescaling: bool, whether to rescale the inputs. If set to
True, inputs will be passed through a `Rescaling(1/255.0)` layer.
input_shape: tuple, optional shape tuple, defaults to (224, 224, 3).
image_shape: tuple, optional shape tuple, defaults to (224, 224, 3).
pooling: bool, Optional pooling mode for feature extraction
when `include_top` is `False`.
- `None` means that the output of the model will be
Expand All @@ -61,7 +60,7 @@ class VGGBackbone(Backbone):
model = keras_nlp.models.VGGBackbone(
stackwise_num_repeats = [2, 2, 3, 3, 3],
stackwise_num_filters = [64, 128, 256, 512, 512],
input_shape = (224, 224, 3),
image_shape = (224, 224, 3),
include_rescaling = False,
pooling = "avg",
)
Expand All @@ -74,13 +73,13 @@ def __init__(
stackwise_num_repeats,
stackwise_num_filters,
include_rescaling,
input_image_shape=(224, 224, 3),
image_shape=(224, 224, 3),
pooling="avg",
**kwargs,
):

# === Functional Model ===
img_input = keras.layers.Input(shape=input_image_shape)
img_input = keras.layers.Input(shape=image_shape)
x = img_input

if include_rescaling:
Expand All @@ -107,15 +106,15 @@ def __init__(
self.stackwise_num_repeats = stackwise_num_repeats
self.stackwise_num_filters = stackwise_num_filters
self.include_rescaling = include_rescaling
self.input_image_shape = input_image_shape
self.image_shape = image_shape
self.pooling = pooling

def get_config(self):
return {
"stackwise_num_repeats": self.stackwise_num_repeats,
"stackwise_num_filters": self.stackwise_num_filters,
"include_rescaling": self.include_rescaling,
"input_image_shape": self.input_image_shape,
"image_shape": self.image_shape,
"pooling": self.pooling,
}

Expand Down
2 changes: 1 addition & 1 deletion keras_nlp/src/models/vgg/vgg_backbone_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def setUp(self):
self.init_kwargs = {
"stackwise_num_repeats": [2, 3, 3],
"stackwise_num_filters": [8, 64, 64],
"input_image_shape": (16, 16, 3),
"image_shape": (16, 16, 3),
"include_rescaling": False,
"pooling": "avg",
}
Expand Down
2 changes: 1 addition & 1 deletion keras_nlp/src/models/vgg/vgg_image_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class VGGImageClassifier(ImageClassifier):
backbone = keras_nlp.models.VGGBackbone(
stackwise_num_repeats = [2, 2, 3, 3, 3],
stackwise_num_filters = [64, 128, 256, 512, 512],
input_shape = (224, 224, 3),
image_shape = (224, 224, 3),
include_rescaling = False,
pooling = "avg",
)
Expand Down
2 changes: 1 addition & 1 deletion keras_nlp/src/models/vgg/vgg_image_classifier_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def setUp(self):
self.backbone = VGGBackbone(
stackwise_num_repeats=[2, 4, 4],
stackwise_num_filters=[2, 16, 16],
input_image_shape=(4, 4, 3),
image_shape=(4, 4, 3),
include_rescaling=False,
pooling="max",
)
Expand Down
6 changes: 3 additions & 3 deletions keras_nlp/src/tests/test_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,10 +501,10 @@ def run_vision_backbone_test(
input_data = ops.transpose(input_data, axes=(2, 0, 1))
elif len(input_data_shape) == 4:
input_data = ops.transpose(input_data, axes=(0, 3, 1, 2))
if "input_image_shape" in init_kwargs:
if "image_shape" in init_kwargs:
init_kwargs = init_kwargs.copy()
init_kwargs["input_image_shape"] = tuple(
reversed(init_kwargs["input_image_shape"])
init_kwargs["image_shape"] = tuple(
reversed(init_kwargs["image_shape"])
)
self.run_backbone_test(
cls=cls,
Expand Down
Loading