Skip to content

Commit

Permalink
Backwards compatibility fixes for Keras <=2.15 (#2273)
Browse files Browse the repository at this point in the history
* Add fixes for backwards compatibility for versions <2.15

* Bump version number for presets to version 2

* Port over RetinaNet custom metric fix

* Bump DeepLabV3Plus preset version after re-upload
  • Loading branch information
nkovela1 committed Jan 4, 2024
1 parent 540472d commit 15a787e
Show file tree
Hide file tree
Showing 19 changed files with 125 additions and 84 deletions.
14 changes: 14 additions & 0 deletions keras_cv/models/backbones/backbone.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ class Backbone(keras.Model):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._pyramid_level_inputs = {}
self._functional_layer_ids = set(
id(layer) for layer in self._flatten_layers()
)

def __dir__(self):
# Temporary fixes for weight saving. This mimics the following PR for
# older version of Keras: https://github.com/keras-team/keras/pull/18982
def filter_fn(attr):
try:
return id(getattr(self, attr)) not in self._functional_layer_ids
except:
return True

return filter(filter_fn, super().__dir__())

def get_config(self):
# Don't chain to super here. The default `get_config()` for functional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"official_name": "CSPDarkNet",
"path": "csp_darknet",
},
"kaggle_handle": "kaggle://keras/cspdarknet/csp_darknet_tiny/1",
"kaggle_handle": "kaggle://keras/cspdarknet/csp_darknet_tiny/2",
},
"csp_darknet_s": {
"metadata": {
Expand All @@ -39,7 +39,7 @@
"official_name": "CSPDarkNet",
"path": "csp_darknet",
},
"kaggle_handle": "kaggle://keras/cspdarknet/csp_darknet_s/1",
"kaggle_handle": "kaggle://keras/cspdarknet/csp_darknet_s/2",
},
"csp_darknet_m": {
"metadata": {
Expand All @@ -52,7 +52,7 @@
"official_name": "CSPDarkNet",
"path": "csp_darknet",
},
"kaggle_handle": "kaggle://keras/cspdarknet/csp_darknet_m/1",
"kaggle_handle": "kaggle://keras/cspdarknet/csp_darknet_m/2",
},
"csp_darknet_l": {
"metadata": {
Expand All @@ -65,7 +65,7 @@
"official_name": "CSPDarkNet",
"path": "csp_darknet",
},
"kaggle_handle": "kaggle://keras/cspdarknet/csp_darknet_l/1",
"kaggle_handle": "kaggle://keras/cspdarknet/csp_darknet_l/2",
},
"csp_darknet_xl": {
"metadata": {
Expand All @@ -78,7 +78,7 @@
"official_name": "CSPDarkNet",
"path": "csp_darknet",
},
"kaggle_handle": "kaggle://keras/cspdarknet/csp_darknet_xl/1",
"kaggle_handle": "kaggle://keras/cspdarknet/csp_darknet_xl/2",
},
}

Expand All @@ -95,7 +95,7 @@
"official_name": "CSPDarkNet",
"path": "csp_darknet",
},
"kaggle_handle": "kaggle://keras/cspdarknet/csp_darknet_tiny_imagenet/1", # noqa: E501
"kaggle_handle": "kaggle://keras/cspdarknet/csp_darknet_tiny_imagenet/2", # noqa: E501
},
"csp_darknet_l_imagenet": {
"metadata": {
Expand All @@ -109,7 +109,7 @@
"official_name": "CSPDarkNet",
"path": "csp_darknet",
},
"kaggle_handle": "kaggle://keras/cspdarknet/csp_darknet_l_imagenet/1",
"kaggle_handle": "kaggle://keras/cspdarknet/csp_darknet_l_imagenet/2",
},
}

Expand Down
12 changes: 6 additions & 6 deletions keras_cv/models/backbones/densenet/densenet_backbone_presets.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@
"metadata": {
"description": "DenseNet model with 121 layers.",
},
"kaggle_handle": "kaggle://keras/densenet/densenet121/1",
"kaggle_handle": "kaggle://keras/densenet/densenet121/2",
},
"densenet169": {
"metadata": {
"description": "DenseNet model with 169 layers.",
},
"kaggle_handle": "kaggle://keras/densenet/densenet169/1",
"kaggle_handle": "kaggle://keras/densenet/densenet169/2",
},
"densenet201": {
"metadata": {
"description": "DenseNet model with 201 layers.",
},
"kaggle_handle": "kaggle://keras/densenet/densenet201/1",
"kaggle_handle": "kaggle://keras/densenet/densenet201/2",
},
}

Expand All @@ -42,7 +42,7 @@
"classification task."
),
},
"kaggle_handle": "kaggle://keras/densenet/densenet121_imagenet/1",
"kaggle_handle": "kaggle://keras/densenet/densenet121_imagenet/2",
},
"densenet169_imagenet": {
"metadata": {
Expand All @@ -51,7 +51,7 @@
"classification task."
),
},
"kaggle_handle": "kaggle://keras/densenet/densenet169_imagenet/1",
"kaggle_handle": "kaggle://keras/densenet/densenet169_imagenet/2",
},
"densenet201_imagenet": {
"metadata": {
Expand All @@ -60,7 +60,7 @@
"classification task."
),
},
"kaggle_handle": "kaggle://keras/densenet/densenet201_imagenet/1",
"kaggle_handle": "kaggle://keras/densenet/densenet201_imagenet/2",
},
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"official_name": "EfficientNetV2",
"path": "efficientnetv2",
},
"kaggle_handle": "kaggle://keras/efficientnetv2/efficientnetv2_s/1",
"kaggle_handle": "kaggle://keras/efficientnetv2/efficientnetv2_s/2",
},
"efficientnetv2_m": {
"metadata": {
Expand All @@ -35,7 +35,7 @@
"official_name": "EfficientNetV2",
"path": "efficientnetv2",
},
"kaggle_handle": "kaggle://keras/efficientnetv2/efficientnetv2_m/1",
"kaggle_handle": "kaggle://keras/efficientnetv2/efficientnetv2_m/2",
},
"efficientnetv2_l": {
"metadata": {
Expand All @@ -47,7 +47,7 @@
"official_name": "EfficientNetV2",
"path": "efficientnetv2",
},
"kaggle_handle": "kaggle://keras/efficientnetv2/efficientnetv2_l/1",
"kaggle_handle": "kaggle://keras/efficientnetv2/efficientnetv2_l/2",
},
"efficientnetv2_b0": {
"metadata": {
Expand All @@ -60,7 +60,7 @@
"official_name": "EfficientNetV2",
"path": "efficientnetv2",
},
"kaggle_handle": "kaggle://keras/efficientnetv2/efficientnetv2_b0/1",
"kaggle_handle": "kaggle://keras/efficientnetv2/efficientnetv2_b0/2",
},
"efficientnetv2_b1": {
"metadata": {
Expand All @@ -73,7 +73,7 @@
"official_name": "EfficientNetV2",
"path": "efficientnetv2",
},
"kaggle_handle": "kaggle://keras/efficientnetv2/efficientnetv2_b1/1",
"kaggle_handle": "kaggle://keras/efficientnetv2/efficientnetv2_b1/2",
},
"efficientnetv2_b2": {
"metadata": {
Expand All @@ -86,7 +86,7 @@
"official_name": "EfficientNetV2",
"path": "efficientnetv2",
},
"kaggle_handle": "kaggle://keras/efficientnetv2/efficientnetv2_b2/1",
"kaggle_handle": "kaggle://keras/efficientnetv2/efficientnetv2_b2/2",
},
"efficientnetv2_b3": {
"metadata": {
Expand All @@ -99,7 +99,7 @@
"official_name": "EfficientNetV2",
"path": "efficientnetv2",
},
"kaggle_handle": "kaggle://keras/efficientnetv2/efficientnetv2_b3/1",
"kaggle_handle": "kaggle://keras/efficientnetv2/efficientnetv2_b3/2",
},
}

Expand All @@ -117,7 +117,7 @@
"official_name": "EfficientNetV2",
"path": "efficientnetv2",
},
"kaggle_handle": "kaggle://keras/efficientnetv2/efficientnetv2_s_imagenet/1", # noqa: E501
"kaggle_handle": "kaggle://keras/efficientnetv2/efficientnetv2_s_imagenet/2", # noqa: E501
},
"efficientnetv2_b0_imagenet": {
"metadata": {
Expand All @@ -134,7 +134,7 @@
"official_name": "EfficientNetV2",
"path": "efficientnetv2",
},
"kaggle_handle": "kaggle://keras/efficientnetv2/efficientnetv2_b0_imagenet/1", # noqa: E501
"kaggle_handle": "kaggle://keras/efficientnetv2/efficientnetv2_b0_imagenet/2", # noqa: E501
},
"efficientnetv2_b1_imagenet": {
"metadata": {
Expand All @@ -151,7 +151,7 @@
"official_name": "EfficientNetV2",
"path": "efficientnetv2",
},
"kaggle_handle": "kaggle://keras/efficientnetv2/efficientnetv2_b1_imagenet/1", # noqa: E501
"kaggle_handle": "kaggle://keras/efficientnetv2/efficientnetv2_b1_imagenet/2", # noqa: E501
},
"efficientnetv2_b2_imagenet": {
"metadata": {
Expand All @@ -168,7 +168,7 @@
"official_name": "EfficientNetV2",
"path": "efficientnetv2",
},
"kaggle_handle": "kaggle://keras/efficientnetv2/efficientnetv2_b2_imagenet/1", # noqa: E501
"kaggle_handle": "kaggle://keras/efficientnetv2/efficientnetv2_b2_imagenet/2", # noqa: E501
},
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"official_name": "MiT",
"path": "mit",
},
"kaggle_handle": "kaggle://keras/mit/mit_b0/1",
"kaggle_handle": "kaggle://keras/mit/mit_b0/2",
},
"mit_b1": {
"metadata": {
Expand All @@ -34,7 +34,7 @@
"official_name": "MiT",
"path": "mit",
},
"kaggle_handle": "kaggle://keras/mit/mit_b1/1",
"kaggle_handle": "kaggle://keras/mit/mit_b1/2",
},
"mit_b2": {
"metadata": {
Expand All @@ -45,7 +45,7 @@
"official_name": "MiT",
"path": "mit",
},
"kaggle_handle": "kaggle://keras/mit/mit_b2/1",
"kaggle_handle": "kaggle://keras/mit/mit_b2/2",
},
"mit_b3": {
"metadata": {
Expand All @@ -56,7 +56,7 @@
"official_name": "MiT",
"path": "mit",
},
"kaggle_handle": "kaggle://keras/mit/mit_b3/1",
"kaggle_handle": "kaggle://keras/mit/mit_b3/2",
},
"mit_b4": {
"metadata": {
Expand All @@ -67,7 +67,7 @@
"official_name": "MiT",
"path": "mit",
},
"kaggle_handle": "kaggle://keras/mit/mit_b4/1",
"kaggle_handle": "kaggle://keras/mit/mit_b4/2",
},
"mit_b5": {
"metadata": {
Expand All @@ -78,7 +78,7 @@
"official_name": "MiT",
"path": "mit",
},
"kaggle_handle": "kaggle://keras/mit/mit_b5/1",
"kaggle_handle": "kaggle://keras/mit/mit_b5/2",
},
}

Expand All @@ -92,7 +92,7 @@
"official_name": "MiT",
"path": "mit",
},
"kaggle_handle": "kaggle://keras/mit/mit_b0_imagenet/1",
"kaggle_handle": "kaggle://keras/mit/mit_b0_imagenet/2",
},
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"official_name": "MobileNetV3",
"path": "mobilenetv3",
},
"kaggle_handle": "kaggle://keras/mobilenetv3/mobilenet_v3_small/1",
"kaggle_handle": "kaggle://keras/mobilenetv3/mobilenet_v3_small/2",
},
"mobilenet_v3_large": {
"metadata": {
Expand All @@ -38,7 +38,7 @@
"official_name": "MobileNetV3",
"path": "mobilenetv3",
},
"kaggle_handle": "kaggle://keras/mobilenetv3/mobilenet_v3_large/1",
"kaggle_handle": "kaggle://keras/mobilenetv3/mobilenet_v3_large/2",
},
}

Expand All @@ -55,7 +55,7 @@
"official_name": "MobileNetV3",
"path": "mobilenetv3",
},
"kaggle_handle": "kaggle://keras/mobilenetv3/mobilenet_v3_large_imagenet/1", # noqa: E501
"kaggle_handle": "kaggle://keras/mobilenetv3/mobilenet_v3_large_imagenet/2", # noqa: E501
},
"mobilenet_v3_small_imagenet": {
"metadata": {
Expand All @@ -69,7 +69,7 @@
"official_name": "MobileNetV3",
"path": "mobilenetv3",
},
"kaggle_handle": "kaggle://keras/mobilenetv3/mobilenet_v3_small_imagenet/1", # noqa: E501
"kaggle_handle": "kaggle://keras/mobilenetv3/mobilenet_v3_small_imagenet/2", # noqa: E501
},
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"official_name": "ResNetV1",
"path": "resnet_v1",
},
"kaggle_handle": "kaggle://keras/resnetv1/resnet18/1",
"kaggle_handle": "kaggle://keras/resnetv1/resnet18/2",
},
"resnet34": {
"metadata": {
Expand All @@ -38,7 +38,7 @@
"official_name": "ResNetV1",
"path": "resnet_v1",
},
"kaggle_handle": "kaggle://keras/resnetv1/resnet34/1",
"kaggle_handle": "kaggle://keras/resnetv1/resnet34/2",
},
"resnet50": {
"metadata": {
Expand All @@ -51,7 +51,7 @@
"official_name": "ResNetV1",
"path": "resnet_v1",
},
"kaggle_handle": "kaggle://keras/resnetv1/resnet50/1",
"kaggle_handle": "kaggle://keras/resnetv1/resnet50/2",
},
"resnet101": {
"metadata": {
Expand All @@ -64,7 +64,7 @@
"official_name": "ResNetV1",
"path": "resnet_v1",
},
"kaggle_handle": "kaggle://keras/resnetv1/resnet101/1",
"kaggle_handle": "kaggle://keras/resnetv1/resnet101/2",
},
"resnet152": {
"metadata": {
Expand All @@ -77,7 +77,7 @@
"official_name": "ResNetV1",
"path": "resnet_v1",
},
"kaggle_handle": "kaggle://keras/resnetv1/resnet152/1",
"kaggle_handle": "kaggle://keras/resnetv1/resnet152/2",
},
}

Expand All @@ -94,7 +94,7 @@
"official_name": "ResNetV1",
"path": "resnet_v1",
},
"kaggle_handle": "kaggle://keras/resnetv1/resnet50_imagenet/1",
"kaggle_handle": "kaggle://keras/resnetv1/resnet50_imagenet/2",
},
}

Expand Down
Loading

0 comments on commit 15a787e

Please sign in to comment.