From 7aa01b103425952ce1cdc6015199a6a065b9e2da Mon Sep 17 00:00:00 2001 From: divyashreepathihalli Date: Mon, 19 Aug 2024 21:20:40 +0000 Subject: [PATCH 1/4] update input_image_shape -> image_shape --- .../src/models/csp_darknet/csp_darknet_backbone.py | 10 +++++----- .../models/csp_darknet/csp_darknet_backbone_test.py | 2 +- .../models/csp_darknet/csp_darknet_image_classifier.py | 2 +- .../csp_darknet/csp_darknet_image_classifier_test.py | 2 +- keras_nlp/src/models/densenet/densenet_backbone.py | 10 +++++----- .../src/models/densenet/densenet_backbone_test.py | 2 +- .../src/models/densenet/densenet_image_classifier.py | 2 +- .../models/densenet/densenet_image_classifier_test.py | 2 +- keras_nlp/src/models/resnet/resnet_backbone.py | 10 +++++----- keras_nlp/src/models/resnet/resnet_backbone_test.py | 4 ++-- .../src/models/resnet/resnet_image_classifier_test.py | 2 +- keras_nlp/src/models/vgg/vgg_backbone.py | 10 +++++----- keras_nlp/src/models/vgg/vgg_backbone_test.py | 2 +- keras_nlp/src/models/vgg/vgg_image_classifier_test.py | 2 +- 14 files changed, 31 insertions(+), 31 deletions(-) diff --git a/keras_nlp/src/models/csp_darknet/csp_darknet_backbone.py b/keras_nlp/src/models/csp_darknet/csp_darknet_backbone.py index 2745f61d01..607c6895ba 100644 --- a/keras_nlp/src/models/csp_darknet/csp_darknet_backbone.py +++ b/keras_nlp/src/models/csp_darknet/csp_darknet_backbone.py @@ -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: @@ -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 === @@ -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) @@ -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() @@ -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 diff --git a/keras_nlp/src/models/csp_darknet/csp_darknet_backbone_test.py b/keras_nlp/src/models/csp_darknet/csp_darknet_backbone_test.py index aaad4fe515..857e06039d 100644 --- a/keras_nlp/src/models/csp_darknet/csp_darknet_backbone_test.py +++ b/keras_nlp/src/models/csp_darknet/csp_darknet_backbone_test.py @@ -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") diff --git a/keras_nlp/src/models/csp_darknet/csp_darknet_image_classifier.py b/keras_nlp/src/models/csp_darknet/csp_darknet_image_classifier.py index 6b013bdcc0..09a7022122 100644 --- a/keras_nlp/src/models/csp_darknet/csp_darknet_image_classifier.py +++ b/keras_nlp/src/models/csp_darknet/csp_darknet_image_classifier.py @@ -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, diff --git a/keras_nlp/src/models/csp_darknet/csp_darknet_image_classifier_test.py b/keras_nlp/src/models/csp_darknet/csp_darknet_image_classifier_test.py index a07bb017a3..33261c25b6 100644 --- a/keras_nlp/src/models/csp_darknet/csp_darknet_image_classifier_test.py +++ b/keras_nlp/src/models/csp_darknet/csp_darknet_image_classifier_test.py @@ -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, diff --git a/keras_nlp/src/models/densenet/densenet_backbone.py b/keras_nlp/src/models/densenet/densenet_backbone.py index 8456fbcee6..60a5b28849 100644 --- a/keras_nlp/src/models/densenet/densenet_backbone.py +++ b/keras_nlp/src/models/densenet/densenet_backbone.py @@ -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, @@ -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: @@ -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() @@ -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 diff --git a/keras_nlp/src/models/densenet/densenet_backbone_test.py b/keras_nlp/src/models/densenet/densenet_backbone_test.py index f0f8dac875..63f358035c 100644 --- a/keras_nlp/src/models/densenet/densenet_backbone_test.py +++ b/keras_nlp/src/models/densenet/densenet_backbone_test.py @@ -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") diff --git a/keras_nlp/src/models/densenet/densenet_image_classifier.py b/keras_nlp/src/models/densenet/densenet_image_classifier.py index 395e8f754d..130904be70 100644 --- a/keras_nlp/src/models/densenet/densenet_image_classifier.py +++ b/keras_nlp/src/models/densenet/densenet_image_classifier.py @@ -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, diff --git a/keras_nlp/src/models/densenet/densenet_image_classifier_test.py b/keras_nlp/src/models/densenet/densenet_image_classifier_test.py index 60d77d489c..439a60008d 100644 --- a/keras_nlp/src/models/densenet/densenet_image_classifier_test.py +++ b/keras_nlp/src/models/densenet/densenet_image_classifier_test.py @@ -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, diff --git a/keras_nlp/src/models/resnet/resnet_backbone.py b/keras_nlp/src/models/resnet/resnet_backbone.py index 0f4d7c139a..31698e0a1c 100644 --- a/keras_nlp/src/models/resnet/resnet_backbone.py +++ b/keras_nlp/src/models/resnet/resnet_backbone.py @@ -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"`. @@ -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, @@ -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( @@ -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 @@ -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, } ) diff --git a/keras_nlp/src/models/resnet/resnet_backbone_test.py b/keras_nlp/src/models/resnet/resnet_backbone_test.py index 6d3f774559..a6a30362cd 100644 --- a/keras_nlp/src/models/resnet/resnet_backbone_test.py +++ b/keras_nlp/src/models/resnet/resnet_backbone_test.py @@ -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 @@ -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( diff --git a/keras_nlp/src/models/resnet/resnet_image_classifier_test.py b/keras_nlp/src/models/resnet/resnet_image_classifier_test.py index f3f63a14a1..893ec42487 100644 --- a/keras_nlp/src/models/resnet/resnet_image_classifier_test.py +++ b/keras_nlp/src/models/resnet/resnet_image_classifier_test.py @@ -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", ) diff --git a/keras_nlp/src/models/vgg/vgg_backbone.py b/keras_nlp/src/models/vgg/vgg_backbone.py index 497381c0fc..1b55fb1f7b 100644 --- a/keras_nlp/src/models/vgg/vgg_backbone.py +++ b/keras_nlp/src/models/vgg/vgg_backbone.py @@ -36,7 +36,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 @@ -74,13 +74,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: @@ -107,7 +107,7 @@ 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): @@ -115,7 +115,7 @@ def get_config(self): "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, } diff --git a/keras_nlp/src/models/vgg/vgg_backbone_test.py b/keras_nlp/src/models/vgg/vgg_backbone_test.py index 05ed33ba0f..d5521ca92d 100644 --- a/keras_nlp/src/models/vgg/vgg_backbone_test.py +++ b/keras_nlp/src/models/vgg/vgg_backbone_test.py @@ -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", } diff --git a/keras_nlp/src/models/vgg/vgg_image_classifier_test.py b/keras_nlp/src/models/vgg/vgg_image_classifier_test.py index 4a2573e496..20d855cb66 100644 --- a/keras_nlp/src/models/vgg/vgg_image_classifier_test.py +++ b/keras_nlp/src/models/vgg/vgg_image_classifier_test.py @@ -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", ) From 914c96e20c91946b35663a6a33aadb193583b25a Mon Sep 17 00:00:00 2001 From: divyashreepathihalli Date: Mon, 19 Aug 2024 21:24:27 +0000 Subject: [PATCH 2/4] update docstring example --- keras_nlp/src/models/vgg/vgg_backbone.py | 2 +- keras_nlp/src/models/vgg/vgg_image_classifier.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/keras_nlp/src/models/vgg/vgg_backbone.py b/keras_nlp/src/models/vgg/vgg_backbone.py index 1b55fb1f7b..55c4066a76 100644 --- a/keras_nlp/src/models/vgg/vgg_backbone.py +++ b/keras_nlp/src/models/vgg/vgg_backbone.py @@ -61,7 +61,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", ) diff --git a/keras_nlp/src/models/vgg/vgg_image_classifier.py b/keras_nlp/src/models/vgg/vgg_image_classifier.py index a26fbfbc30..d849586ed8 100644 --- a/keras_nlp/src/models/vgg/vgg_image_classifier.py +++ b/keras_nlp/src/models/vgg/vgg_image_classifier.py @@ -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", ) From 6ddcf35801b6a9fefb638f185b5804608df5679f Mon Sep 17 00:00:00 2001 From: divyashreepathihalli Date: Tue, 20 Aug 2024 23:59:01 +0000 Subject: [PATCH 3/4] code reformat --- keras_nlp/src/models/vgg/vgg_backbone.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/keras_nlp/src/models/vgg/vgg_backbone.py b/keras_nlp/src/models/vgg/vgg_backbone.py index 55c4066a76..b215261fed 100644 --- a/keras_nlp/src/models/vgg/vgg_backbone.py +++ b/keras_nlp/src/models/vgg/vgg_backbone.py @@ -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]( From db46f3b13fe15d7116103ee0ff2d9041a8140051 Mon Sep 17 00:00:00 2001 From: divyashreepathihalli Date: Wed, 21 Aug 2024 04:18:38 +0000 Subject: [PATCH 4/4] update tests --- keras_nlp/src/tests/test_case.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/keras_nlp/src/tests/test_case.py b/keras_nlp/src/tests/test_case.py index 9a94d6357f..8e63bc19d9 100644 --- a/keras_nlp/src/tests/test_case.py +++ b/keras_nlp/src/tests/test_case.py @@ -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,