From a94af373f688290d301fbddac663f9f320c5bee1 Mon Sep 17 00:00:00 2001 From: Smit Lunagariya Date: Tue, 16 Apr 2024 06:41:54 +0000 Subject: [PATCH 1/3] Make Backbone parent classes to allow handling all subclass presets --- keras_cv/models/backbones/backbone.py | 57 ++++------- keras_cv/models/backbones/backbone_presets.py | 3 + .../models/backbones/csp_darknet/__init__.py | 19 ++++ .../csp_darknet/csp_darknet_aliases.py | 67 ------------- .../csp_darknet/csp_darknet_backbone.py | 20 ---- .../models/backbones/densenet/__init__.py | 23 +++++ .../backbones/densenet/densenet_aliases.py | 49 --------- .../backbones/densenet/densenet_backbone.py | 19 ---- .../backbones/efficientnet_lite/__init__.py | 14 +++ .../efficientnet_lite_aliases.py | 56 ----------- .../efficientnet_lite_backbone.py | 10 -- .../backbones/efficientnet_v1/__init__.py | 14 +++ .../efficientnet_v1_aliases.py | 91 ----------------- .../efficientnet_v1_backbone.py | 10 -- .../backbones/efficientnet_v2/__init__.py | 25 +++++ .../efficientnet_v2_aliases.py | 99 ------------------- .../efficientnet_v2_backbone.py | 20 ---- .../backbones/mix_transformer/__init__.py | 19 ++++ .../mix_transformer_aliases.py | 72 -------------- .../mix_transformer_backbone.py | 20 ---- .../models/backbones/mobilenet_v3/__init__.py | 21 ++++ .../mobilenet_v3/mobilenet_v3_aliases.py | 36 +------ .../mobilenet_v3/mobilenet_v3_backbone.py | 20 ---- .../models/backbones/resnet_v1/__init__.py | 19 ++++ .../backbones/resnet_v1/resnet_v1_aliases.py | 63 ------------ .../backbones/resnet_v1/resnet_v1_backbone.py | 20 ---- .../models/backbones/resnet_v2/__init__.py | 19 ++++ .../backbones/resnet_v2/resnet_v2_aliases.py | 65 ------------ .../backbones/resnet_v2/resnet_v2_backbone.py | 20 ---- .../models/backbones/video_swin/__init__.py | 23 +++++ .../video_swin/video_swin_aliases.py | 50 ---------- .../video_swin/video_swin_backbone.py | 19 ---- keras_cv/models/backbones/vit_det/__init__.py | 23 +++++ .../retinanet/retinanet_test.py | 2 +- .../object_detection/yolo_v8/__init__.py | 13 +++ .../yolo_v8/yolo_v8_backbone.py | 18 ---- .../models/object_detection_3d/__init__.py | 10 ++ .../center_pillar_backbone.py | 10 -- .../center_pillar_backbone_presets.py | 9 +- keras_cv/utils/preset_utils.py | 58 ++++++++++- 40 files changed, 330 insertions(+), 895 deletions(-) diff --git a/keras_cv/models/backbones/backbone.py b/keras_cv/models/backbones/backbone.py index 6130945308..83f03dc847 100644 --- a/keras_cv/models/backbones/backbone.py +++ b/keras_cv/models/backbones/backbone.py @@ -15,10 +15,11 @@ from keras_cv.api_export import keras_cv_export from keras_cv.backend import keras -from keras_cv.utils.preset_utils import check_preset_class +from keras_cv.utils.preset_utils import check_config_class +from keras_cv.utils.preset_utils import list_presets +from keras_cv.utils.preset_utils import list_subclasses from keras_cv.utils.preset_utils import load_from_preset from keras_cv.utils.python_utils import classproperty -from keras_cv.utils.python_utils import format_docstring @keras_cv_export("keras_cv.models.Backbone") @@ -64,12 +65,18 @@ def from_config(cls, config): @classproperty def presets(cls): """Dictionary of preset names and configs.""" - return {} + presets = list_presets(cls) + for subclass in list_subclasses(cls): + presets.update(subclass.presets) + return presets @classproperty def presets_with_weights(cls): """Dictionary of preset names and configs that include weights.""" - return {} + presets = list_presets(cls, with_weights=True) + for subclass in list_subclasses(cls): + presets.update(subclass.presets) + return presets @classproperty def presets_without_weights(cls): @@ -109,47 +116,19 @@ def from_preset( load_weights=False, ``` """ - # We support short IDs for official presets, e.g. `"bert_base_en"`. - # Map these to a Kaggle Models handle. - if preset in cls.presets: - preset = cls.presets[preset]["kaggle_handle"] - - check_preset_class(preset, cls) + preset_cls = check_config_class(preset) + if not issubclass(preset_cls, cls): + raise ValueError( + f"Preset has type `{preset_cls.__name__}` which is not a " + f"a subclass of calling class `{cls.__name__}`. Call " + f"`from_preset` directly on `{preset_cls.__name__}` instead." + ) return load_from_preset( preset, load_weights=load_weights, config_overrides=kwargs, ) - def __init_subclass__(cls, **kwargs): - # Use __init_subclass__ to set up a correct docstring for from_preset. - super().__init_subclass__(**kwargs) - - # If the subclass does not define from_preset, assign a wrapper so that - # each class can have a distinct docstring. - if "from_preset" not in cls.__dict__: - - def from_preset(calling_cls, *args, **kwargs): - return super(cls, calling_cls).from_preset(*args, **kwargs) - - cls.from_preset = classmethod(from_preset) - - if not cls.presets: - cls.from_preset.__func__.__doc__ = """Not implemented. - - No presets available for this class. - """ - - # Format and assign the docstring unless the subclass has overridden it. - if cls.from_preset.__doc__ is None: - cls.from_preset.__func__.__doc__ = Backbone.from_preset.__doc__ - format_docstring( - model_name=cls.__name__, - example_preset_name=next(iter(cls.presets_with_weights), ""), - preset_names='", "'.join(cls.presets), - preset_with_weights_names='", "'.join(cls.presets_with_weights), - )(cls.from_preset.__func__) - @property def pyramid_level_inputs(self): """Intermediate model outputs for feature extraction. diff --git a/keras_cv/models/backbones/backbone_presets.py b/keras_cv/models/backbones/backbone_presets.py index b77163aa8f..4bdb5bf9e9 100644 --- a/keras_cv/models/backbones/backbone_presets.py +++ b/keras_cv/models/backbones/backbone_presets.py @@ -31,8 +31,10 @@ from keras_cv.models.backbones.video_swin import video_swin_backbone_presets from keras_cv.models.backbones.vit_det import vit_det_backbone_presets from keras_cv.models.object_detection.yolo_v8 import yolo_v8_backbone_presets +from keras_cv.models.object_detection_3d import center_pillar_backbone_presets backbone_presets_no_weights = { + **center_pillar_backbone_presets.backbone_presets_no_weights, **resnet_v1_backbone_presets.backbone_presets_no_weights, **resnet_v2_backbone_presets.backbone_presets_no_weights, **mobilenet_v3_backbone_presets.backbone_presets_no_weights, @@ -47,6 +49,7 @@ } backbone_presets_with_weights = { + **center_pillar_backbone_presets.backbone_presets_with_weights, **resnet_v1_backbone_presets.backbone_presets_with_weights, **resnet_v2_backbone_presets.backbone_presets_with_weights, **mobilenet_v3_backbone_presets.backbone_presets_with_weights, diff --git a/keras_cv/models/backbones/csp_darknet/__init__.py b/keras_cv/models/backbones/csp_darknet/__init__.py index 3992ffb59a..3326878c56 100644 --- a/keras_cv/models/backbones/csp_darknet/__init__.py +++ b/keras_cv/models/backbones/csp_darknet/__init__.py @@ -11,3 +11,22 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + +from keras_cv.models.backbones.csp_darknet.csp_darknet_backbone_presets import ( + backbone_presets_no_weights, backbone_presets_with_weights, +) +from keras_cv.models.backbones.csp_darknet.csp_darknet_backbone import ( + CSPDarkNetBackbone, +) +from keras_cv.models.backbones.csp_darknet.csp_darknet_aliases import ( + CSPDarkNetTinyBackbone, CSPDarkNetLBackbone, +) +from keras_cv.utils.preset_utils import register_presets, register_preset + +register_presets(backbone_presets_no_weights, (CSPDarkNetBackbone, ), with_weights=False) +register_presets(backbone_presets_with_weights, (CSPDarkNetBackbone, ), with_weights=True) +register_presets(backbone_presets_with_weights, (CSPDarkNetBackbone, ), with_weights=True) +register_preset("csp_darknet_tiny_imagenet", backbone_presets_with_weights["csp_darknet_tiny_imagenet"], + (CSPDarkNetTinyBackbone,), with_weights=True) +register_preset("csp_darknet_l_imagenet", backbone_presets_with_weights["csp_darknet_l_imagenet"], + (CSPDarkNetLBackbone,), with_weights=True) diff --git a/keras_cv/models/backbones/csp_darknet/csp_darknet_aliases.py b/keras_cv/models/backbones/csp_darknet/csp_darknet_aliases.py index 24070abf3b..c3e85ac9a2 100644 --- a/keras_cv/models/backbones/csp_darknet/csp_darknet_aliases.py +++ b/keras_cv/models/backbones/csp_darknet/csp_darknet_aliases.py @@ -12,16 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. -import copy from keras_cv.api_export import keras_cv_export from keras_cv.models.backbones.csp_darknet.csp_darknet_backbone import ( CSPDarkNetBackbone, ) -from keras_cv.models.backbones.csp_darknet.csp_darknet_backbone_presets import ( - backbone_presets, -) -from keras_cv.utils.python_utils import classproperty ALIAS_DOCSTRING = """CSPDarkNetBackbone model with {stackwise_channels} channels and {stackwise_depth} depths. @@ -71,21 +66,6 @@ def __new__( ) return CSPDarkNetBackbone.from_preset("csp_darknet_tiny", **kwargs) - @classproperty - def presets(cls): - """Dictionary of preset names and configurations.""" - return { - "csp_darknet_tiny_imagenet": copy.deepcopy( - backbone_presets["csp_darknet_tiny_imagenet"] - ) - } - - @classproperty - def presets_with_weights(cls): - """Dictionary of preset names and configurations that include - weights.""" - return cls.presets - @keras_cv_export("keras_cv.models.CSPDarkNetSBackbone") class CSPDarkNetSBackbone(CSPDarkNetBackbone): @@ -106,17 +86,6 @@ def __new__( ) return CSPDarkNetBackbone.from_preset("csp_darknet_s", **kwargs) - @classproperty - def presets(cls): - """Dictionary of preset names and configurations.""" - return {} - - @classproperty - def presets_with_weights(cls): - """Dictionary of preset names and configurations that include - weights.""" - return {} - @keras_cv_export("keras_cv.models.CSPDarkNetMBackbone") class CSPDarkNetMBackbone(CSPDarkNetBackbone): @@ -137,17 +106,6 @@ def __new__( ) return CSPDarkNetBackbone.from_preset("csp_darknet_m", **kwargs) - @classproperty - def presets(cls): - """Dictionary of preset names and configurations.""" - return {} - - @classproperty - def presets_with_weights(cls): - """Dictionary of preset names and configurations that include - weights.""" - return {} - @keras_cv_export("keras_cv.models.CSPDarkNetLBackbone") class CSPDarkNetLBackbone(CSPDarkNetBackbone): @@ -168,21 +126,6 @@ def __new__( ) return CSPDarkNetBackbone.from_preset("csp_darknet_l", **kwargs) - @classproperty - def presets(cls): - """Dictionary of preset names and configurations.""" - return { - "csp_darknet_l_imagenet": copy.deepcopy( - backbone_presets["csp_darknet_l_imagenet"] - ) - } - - @classproperty - def presets_with_weights(cls): - """Dictionary of preset names and configurations that include - weights.""" - return cls.presets - @keras_cv_export("keras_cv.models.CSPDarkNetXLBackbone") class CSPDarkNetXLBackbone(CSPDarkNetBackbone): @@ -203,16 +146,6 @@ def __new__( ) return CSPDarkNetBackbone.from_preset("csp_darknet_xl", **kwargs) - @classproperty - def presets(cls): - """Dictionary of preset names and configurations.""" - return {} - - @classproperty - def presets_with_weights(cls): - """Dictionary of preset names and configurations that include - weights.""" - return {} setattr( diff --git a/keras_cv/models/backbones/csp_darknet/csp_darknet_backbone.py b/keras_cv/models/backbones/csp_darknet/csp_darknet_backbone.py index 70fb629eca..28f075406c 100644 --- a/keras_cv/models/backbones/csp_darknet/csp_darknet_backbone.py +++ b/keras_cv/models/backbones/csp_darknet/csp_darknet_backbone.py @@ -13,18 +13,11 @@ # limitations under the License. """CSPDarkNet backbone model. """ -import copy from keras_cv.api_export import keras_cv_export from keras_cv.backend import keras from keras_cv.models import utils from keras_cv.models.backbones.backbone import Backbone -from keras_cv.models.backbones.csp_darknet.csp_darknet_backbone_presets import ( - backbone_presets, -) -from keras_cv.models.backbones.csp_darknet.csp_darknet_backbone_presets import ( - backbone_presets_with_weights, -) from keras_cv.models.backbones.csp_darknet.csp_darknet_utils import ( CrossStagePartial, ) @@ -38,8 +31,6 @@ from keras_cv.models.backbones.csp_darknet.csp_darknet_utils import ( SpatialPyramidPoolingBottleneck, ) -from keras_cv.utils.python_utils import classproperty - @keras_cv_export("keras_cv.models.CSPDarkNetBackbone") class CSPDarkNetBackbone(Backbone): @@ -169,14 +160,3 @@ def get_config(self): } ) return config - - @classproperty - def presets(cls): - """Dictionary of preset names and configurations.""" - return copy.deepcopy(backbone_presets) - - @classproperty - def presets_with_weights(cls): - """Dictionary of preset names and configurations that include - weights.""" - return copy.deepcopy(backbone_presets_with_weights) diff --git a/keras_cv/models/backbones/densenet/__init__.py b/keras_cv/models/backbones/densenet/__init__.py index 3992ffb59a..aeda8288ae 100644 --- a/keras_cv/models/backbones/densenet/__init__.py +++ b/keras_cv/models/backbones/densenet/__init__.py @@ -11,3 +11,26 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + +from keras_cv.models.backbones.densenet.densenet_backbone_presets import ( + backbone_presets_no_weights, +) +from keras_cv.models.backbones.densenet.densenet_backbone_presets import ( + backbone_presets_with_weights, +) +from keras_cv.models.backbones.densenet.densenet_backbone import ( + DenseNetBackbone, +) +from keras_cv.models.backbones.densenet.densenet_aliases import ( + DenseNet121Backbone, DenseNet169Backbone, DenseNet201Backbone +) +from keras_cv.utils.preset_utils import register_presets, register_preset + +register_presets(backbone_presets_no_weights, (DenseNetBackbone, ), with_weights=False) +register_presets(backbone_presets_with_weights, (DenseNetBackbone, ), with_weights=True) +register_preset("densenet121_imagenet", backbone_presets_with_weights["densenet121_imagenet"], + (DenseNet121Backbone,), with_weights=True) +register_preset("densenet169_imagenet", backbone_presets_with_weights["densenet169_imagenet"], + (DenseNet169Backbone,), with_weights=True) +register_preset("densenet201_imagenet", backbone_presets_with_weights["densenet201_imagenet"], + (DenseNet201Backbone,), with_weights=True) diff --git a/keras_cv/models/backbones/densenet/densenet_aliases.py b/keras_cv/models/backbones/densenet/densenet_aliases.py index 6593b100f6..789695ea0e 100644 --- a/keras_cv/models/backbones/densenet/densenet_aliases.py +++ b/keras_cv/models/backbones/densenet/densenet_aliases.py @@ -12,16 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -import copy - from keras_cv.api_export import keras_cv_export from keras_cv.models.backbones.densenet.densenet_backbone import ( DenseNetBackbone, ) -from keras_cv.models.backbones.densenet.densenet_backbone_presets import ( - backbone_presets, -) -from keras_cv.utils.python_utils import classproperty ALIAS_DOCSTRING = """DenseNetBackbone model with {num_layers} layers. @@ -69,21 +63,6 @@ def __new__( ) return DenseNetBackbone.from_preset("densenet121", **kwargs) - @classproperty - def presets(cls): - """Dictionary of preset names and configurations.""" - return { - "densenet121_imagenet": copy.deepcopy( - backbone_presets["densenet121_imagenet"] - ), - } - - @classproperty - def presets_with_weights(cls): - """Dictionary of preset names and configurations that include weights.""" # noqa: E501 - return cls.presets - - @keras_cv_export("keras_cv.models.DenseNet169Backbone") class DenseNet169Backbone(DenseNetBackbone): def __new__( @@ -103,20 +82,6 @@ def __new__( ) return DenseNetBackbone.from_preset("densenet169", **kwargs) - @classproperty - def presets(cls): - """Dictionary of preset names and configurations.""" - return { - "densenet169_imagenet": copy.deepcopy( - backbone_presets["densenet169_imagenet"] - ), - } - - @classproperty - def presets_with_weights(cls): - """Dictionary of preset names and configurations that include weights.""" # noqa: E501 - return cls.presets - @keras_cv_export("keras_cv.models.DenseNet201Backbone") class DenseNet201Backbone(DenseNetBackbone): @@ -137,20 +102,6 @@ def __new__( ) return DenseNetBackbone.from_preset("densenet201", **kwargs) - @classproperty - def presets(cls): - """Dictionary of preset names and configurations.""" - return { - "densenet201_imagenet": copy.deepcopy( - backbone_presets["densenet201_imagenet"] - ), - } - - @classproperty - def presets_with_weights(cls): - """Dictionary of preset names and configurations that include weights.""" # noqa: E501 - return cls.presets - setattr(DenseNet121Backbone, "__doc__", ALIAS_DOCSTRING.format(num_layers=121)) setattr(DenseNet169Backbone, "__doc__", ALIAS_DOCSTRING.format(num_layers=169)) diff --git a/keras_cv/models/backbones/densenet/densenet_backbone.py b/keras_cv/models/backbones/densenet/densenet_backbone.py index 251f3601ec..f382e3f589 100644 --- a/keras_cv/models/backbones/densenet/densenet_backbone.py +++ b/keras_cv/models/backbones/densenet/densenet_backbone.py @@ -19,19 +19,10 @@ - [Based on the Original keras.applications DenseNet](https://github.com/keras-team/keras/blob/master/keras/applications/densenet.py) """ # noqa: E501 -import copy - from keras_cv.api_export import keras_cv_export from keras_cv.backend import keras from keras_cv.models import utils from keras_cv.models.backbones.backbone import Backbone -from keras_cv.models.backbones.densenet.densenet_backbone_presets import ( - backbone_presets, -) -from keras_cv.models.backbones.densenet.densenet_backbone_presets import ( - backbone_presets_with_weights, -) -from keras_cv.utils.python_utils import classproperty BN_AXIS = 3 BN_EPSILON = 1.001e-5 @@ -153,16 +144,6 @@ def get_config(self): ) return config - @classproperty - def presets(cls): - """Dictionary of preset names and configurations.""" - return copy.deepcopy(backbone_presets) - - @classproperty - def presets_with_weights(cls): - """Dictionary of preset names and configurations that include weights.""" # noqa: E501 - return copy.deepcopy(backbone_presets_with_weights) - def apply_dense_block(x, num_repeats, growth_rate, name=None): """A dense block. diff --git a/keras_cv/models/backbones/efficientnet_lite/__init__.py b/keras_cv/models/backbones/efficientnet_lite/__init__.py index 3992ffb59a..b90f74b7df 100644 --- a/keras_cv/models/backbones/efficientnet_lite/__init__.py +++ b/keras_cv/models/backbones/efficientnet_lite/__init__.py @@ -11,3 +11,17 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + +from keras_cv.models.backbones.efficientnet_lite.efficientnet_lite_backbone_presets import ( + backbone_presets_no_weights, +) +from keras_cv.models.backbones.efficientnet_lite.efficientnet_lite_backbone_presets import ( + backbone_presets_with_weights, +) +from keras_cv.models.backbones.efficientnet_lite.efficientnet_lite_backbone import ( + EfficientNetLiteBackbone, +) +from keras_cv.utils.preset_utils import register_presets + +register_presets(backbone_presets_no_weights, (EfficientNetLiteBackbone, ), with_weights=False) +register_presets(backbone_presets_with_weights, (EfficientNetLiteBackbone, ), with_weights=True) diff --git a/keras_cv/models/backbones/efficientnet_lite/efficientnet_lite_aliases.py b/keras_cv/models/backbones/efficientnet_lite/efficientnet_lite_aliases.py index ef654a7a44..4eafdb3258 100644 --- a/keras_cv/models/backbones/efficientnet_lite/efficientnet_lite_aliases.py +++ b/keras_cv/models/backbones/efficientnet_lite/efficientnet_lite_aliases.py @@ -16,7 +16,6 @@ from keras_cv.models.backbones.efficientnet_lite.efficientnet_lite_backbone import ( # noqa: E501 EfficientNetLiteBackbone, ) -from keras_cv.utils.python_utils import classproperty ALIAS_DOCSTRING = """Instantiates the {name} architecture. @@ -63,17 +62,6 @@ def __new__( "efficientnetlite_b0", **kwargs ) - @classproperty - def presets(cls): - """Dictionary of preset names and configurations.""" - return {} - - @classproperty - def presets_with_weights(cls): - """Dictionary of preset names and configurations that include - weights.""" - return {} - @keras_cv_export("keras_cv.models.EfficientNetLiteB1Backbone") class EfficientNetLiteB1Backbone(EfficientNetLiteBackbone): @@ -96,17 +84,6 @@ def __new__( "efficientnetlite_b1", **kwargs ) - @classproperty - def presets(cls): - """Dictionary of preset names and configurations.""" - return {} - - @classproperty - def presets_with_weights(cls): - """Dictionary of preset names and configurations that include - weights.""" - return {} - @keras_cv_export("keras_cv.models.EfficientNetLiteB2Backbone") class EfficientNetLiteB2Backbone(EfficientNetLiteBackbone): @@ -129,16 +106,6 @@ def __new__( "efficientnetlite_b2", **kwargs ) - @classproperty - def presets(cls): - """Dictionary of preset names and configurations.""" - return {} - - @classproperty - def presets_with_weights(cls): - """Dictionary of preset names and configurations that include - weights.""" - return {} @keras_cv_export("keras_cv.models.EfficientNetLiteB3Backbone") @@ -162,17 +129,6 @@ def __new__( "efficientnetlite_b3", **kwargs ) - @classproperty - def presets(cls): - """Dictionary of preset names and configurations.""" - return {} - - @classproperty - def presets_with_weights(cls): - """Dictionary of preset names and configurations that include - weights.""" - return {} - @keras_cv_export("keras_cv.models.EfficientNetLiteB4Backbone") class EfficientNetLiteB4Backbone(EfficientNetLiteBackbone): @@ -195,18 +151,6 @@ def __new__( "efficientnetlite_b4", **kwargs ) - @classproperty - def presets(cls): - """Dictionary of preset names and configurations.""" - return {} - - @classproperty - def presets_with_weights(cls): - """Dictionary of preset names and configurations that include - weights.""" - return {} - - setattr( EfficientNetLiteB0Backbone, "__doc__", diff --git a/keras_cv/models/backbones/efficientnet_lite/efficientnet_lite_backbone.py b/keras_cv/models/backbones/efficientnet_lite/efficientnet_lite_backbone.py index b86e57ce8e..4265ad0157 100644 --- a/keras_cv/models/backbones/efficientnet_lite/efficientnet_lite_backbone.py +++ b/keras_cv/models/backbones/efficientnet_lite/efficientnet_lite_backbone.py @@ -21,17 +21,12 @@ - [Based on the original EfficientNet Lite's](https://github.com/tensorflow/tpu/tree/master/models/official/efficientnet/lite) """ # noqa: E501 -import copy import math from keras_cv.api_export import keras_cv_export from keras_cv.backend import keras from keras_cv.models import utils from keras_cv.models.backbones.backbone import Backbone -from keras_cv.models.backbones.efficientnet_lite.efficientnet_lite_backbone_presets import ( # noqa: E501 - backbone_presets, -) -from keras_cv.utils.python_utils import classproperty BN_AXIS = 3 @@ -247,11 +242,6 @@ def get_config(self): ) return config - @classproperty - def presets(cls): - """Dictionary of preset names and configurations.""" - return copy.deepcopy(backbone_presets) - def conv_kernel_initializer(scale=2.0): return keras.initializers.VarianceScaling( diff --git a/keras_cv/models/backbones/efficientnet_v1/__init__.py b/keras_cv/models/backbones/efficientnet_v1/__init__.py index 3992ffb59a..5f0a53c7ec 100644 --- a/keras_cv/models/backbones/efficientnet_v1/__init__.py +++ b/keras_cv/models/backbones/efficientnet_v1/__init__.py @@ -11,3 +11,17 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + +from keras_cv.models.backbones.efficientnet_v1.efficientnet_v1_backbone_presets import ( + backbone_presets_no_weights, +) +from keras_cv.models.backbones.efficientnet_v1.efficientnet_v1_backbone_presets import ( + backbone_presets_with_weights, +) +from keras_cv.models.backbones.efficientnet_v1.efficientnet_v1_backbone import ( + EfficientNetV1Backbone, +) +from keras_cv.utils.preset_utils import register_presets + +register_presets(backbone_presets_no_weights, (EfficientNetV1Backbone, ), with_weights=False) +register_presets(backbone_presets_with_weights, (EfficientNetV1Backbone, ), with_weights=True) diff --git a/keras_cv/models/backbones/efficientnet_v1/efficientnet_v1_aliases.py b/keras_cv/models/backbones/efficientnet_v1/efficientnet_v1_aliases.py index 6fe6e230c4..0bf86d6b9a 100644 --- a/keras_cv/models/backbones/efficientnet_v1/efficientnet_v1_aliases.py +++ b/keras_cv/models/backbones/efficientnet_v1/efficientnet_v1_aliases.py @@ -16,7 +16,6 @@ from keras_cv.models.backbones.efficientnet_v1.efficientnet_v1_backbone import ( EfficientNetV1Backbone, ) -from keras_cv.utils.python_utils import classproperty ALIAS_DOCSTRING = """Instantiates the {name} architecture. @@ -53,17 +52,6 @@ def __new__( ) return EfficientNetV1Backbone.from_preset("efficientnetv1_b0", **kwargs) - @classproperty - def presets(cls): - """Dictionary of preset names and configurations.""" - return {} - - @classproperty - def presets_with_weights(cls): - """Dictionary of preset names and configurations that include - weights.""" - return {} - @keras_cv_export("keras_cv.models.EfficientNetV1B1Backbone") class EfficientNetV1B1Backbone(EfficientNetV1Backbone): @@ -84,17 +72,6 @@ def __new__( ) return EfficientNetV1Backbone.from_preset("efficientnetv1_b1", **kwargs) - @classproperty - def presets(cls): - """Dictionary of preset names and configurations.""" - return {} - - @classproperty - def presets_with_weights(cls): - """Dictionary of preset names and configurations that include - weights.""" - return {} - @keras_cv_export("keras_cv.models.EfficientNetV1B2Backbone") class EfficientNetV1B2Backbone(EfficientNetV1Backbone): @@ -115,17 +92,6 @@ def __new__( ) return EfficientNetV1Backbone.from_preset("efficientnetv1_b2", **kwargs) - @classproperty - def presets(cls): - """Dictionary of preset names and configurations.""" - return {} - - @classproperty - def presets_with_weights(cls): - """Dictionary of preset names and configurations that include - weights.""" - return {} - @keras_cv_export("keras_cv.models.EfficientNetV1B3Backbone") class EfficientNetV1B3Backbone(EfficientNetV1Backbone): @@ -146,18 +112,6 @@ def __new__( ) return EfficientNetV1Backbone.from_preset("efficientnetv1_b3", **kwargs) - @classproperty - def presets(cls): - """Dictionary of preset names and configurations.""" - return {} - - @classproperty - def presets_with_weights(cls): - """Dictionary of preset names and configurations that include - weights.""" - return {} - - @keras_cv_export("keras_cv.models.EfficientNetV1B4Backbone") class EfficientNetV1B4Backbone(EfficientNetV1Backbone): def __new__( @@ -177,18 +131,6 @@ def __new__( ) return EfficientNetV1Backbone.from_preset("efficientnetv1_b4", **kwargs) - @classproperty - def presets(cls): - """Dictionary of preset names and configurations.""" - return {} - - @classproperty - def presets_with_weights(cls): - """Dictionary of preset names and configurations that include - weights.""" - return {} - - @keras_cv_export("keras_cv.models.EfficientNetV1B5Backbone") class EfficientNetV1B5Backbone(EfficientNetV1Backbone): def __new__( @@ -208,17 +150,6 @@ def __new__( ) return EfficientNetV1Backbone.from_preset("efficientnetv1_b5", **kwargs) - @classproperty - def presets(cls): - """Dictionary of preset names and configurations.""" - return {} - - @classproperty - def presets_with_weights(cls): - """Dictionary of preset names and configurations that include - weights.""" - return {} - @keras_cv_export("keras_cv.models.EfficientNetV1B6Backbone") class EfficientNetV1B6Backbone(EfficientNetV1Backbone): @@ -239,17 +170,6 @@ def __new__( ) return EfficientNetV1Backbone.from_preset("efficientnetv1_b6", **kwargs) - @classproperty - def presets(cls): - """Dictionary of preset names and configurations.""" - return {} - - @classproperty - def presets_with_weights(cls): - """Dictionary of preset names and configurations that include - weights.""" - return {} - @keras_cv_export("keras_cv.models.EfficientNetV1B7Backbone") class EfficientNetV1B7Backbone(EfficientNetV1Backbone): @@ -270,17 +190,6 @@ def __new__( ) return EfficientNetV1Backbone.from_preset("efficientnetv1_b7", **kwargs) - @classproperty - def presets(cls): - """Dictionary of preset names and configurations.""" - return {} - - @classproperty - def presets_with_weights(cls): - """Dictionary of preset names and configurations that include - weights.""" - return {} - setattr( EfficientNetV1B0Backbone, diff --git a/keras_cv/models/backbones/efficientnet_v1/efficientnet_v1_backbone.py b/keras_cv/models/backbones/efficientnet_v1/efficientnet_v1_backbone.py index 2ff9e66ac7..25a2108c05 100644 --- a/keras_cv/models/backbones/efficientnet_v1/efficientnet_v1_backbone.py +++ b/keras_cv/models/backbones/efficientnet_v1/efficientnet_v1_backbone.py @@ -11,17 +11,12 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -import copy import math from keras_cv.api_export import keras_cv_export from keras_cv.backend import keras from keras_cv.models import utils from keras_cv.models.backbones.backbone import Backbone -from keras_cv.models.backbones.efficientnet_v1.efficientnet_v1_backbone_presets import ( # noqa: E501 - backbone_presets, -) -from keras_cv.utils.python_utils import classproperty @keras_cv_export("keras_cv.models.EfficientNetV1Backbone") @@ -284,11 +279,6 @@ def get_config(self): ) return config - @classproperty - def presets(cls): - """Dictionary of preset names and configurations.""" - return copy.deepcopy(backbone_presets) - def conv_kernel_initializer(scale=2.0): return keras.initializers.VarianceScaling( diff --git a/keras_cv/models/backbones/efficientnet_v2/__init__.py b/keras_cv/models/backbones/efficientnet_v2/__init__.py index 3992ffb59a..5c7750d78f 100644 --- a/keras_cv/models/backbones/efficientnet_v2/__init__.py +++ b/keras_cv/models/backbones/efficientnet_v2/__init__.py @@ -11,3 +11,28 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + +from keras_cv.models.backbones.efficientnet_v2.efficientnet_v2_backbone_presets import ( + backbone_presets_no_weights, +) +from keras_cv.models.backbones.efficientnet_v2.efficientnet_v2_backbone_presets import ( + backbone_presets_with_weights, +) +from keras_cv.models.backbones.efficientnet_v2.efficientnet_v2_backbone import ( + EfficientNetV2Backbone, +) +from keras_cv.models.backbones.efficientnet_v2.efficientnet_v2_aliases import ( + EfficientNetV2SBackbone, EfficientNetV2B0Backbone, EfficientNetV2B1Backbone, EfficientNetV2B2Backbone, +) +from keras_cv.utils.preset_utils import register_presets, register_preset + +register_presets(backbone_presets_no_weights, (EfficientNetV2Backbone, ), with_weights=False) +register_presets(backbone_presets_with_weights, (EfficientNetV2Backbone, ), with_weights=True) +register_preset("efficientnetv2_s_imagenet", backbone_presets_with_weights["efficientnetv2_s_imagenet"], + (EfficientNetV2SBackbone,), with_weights=True) +register_preset("efficientnetv2_b0_imagenet", backbone_presets_with_weights["efficientnetv2_b0_imagenet"], + (EfficientNetV2B0Backbone,), with_weights=True) +register_preset("efficientnetv2_b1_imagenet", backbone_presets_with_weights["efficientnetv2_b1_imagenet"], + (EfficientNetV2B1Backbone,), with_weights=True) +register_preset("efficientnetv2_b2_imagenet", backbone_presets_with_weights["efficientnetv2_b2_imagenet"], + (EfficientNetV2B2Backbone,), with_weights=True) diff --git a/keras_cv/models/backbones/efficientnet_v2/efficientnet_v2_aliases.py b/keras_cv/models/backbones/efficientnet_v2/efficientnet_v2_aliases.py index f338874982..713c82d599 100644 --- a/keras_cv/models/backbones/efficientnet_v2/efficientnet_v2_aliases.py +++ b/keras_cv/models/backbones/efficientnet_v2/efficientnet_v2_aliases.py @@ -11,16 +11,10 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -import copy - from keras_cv.api_export import keras_cv_export from keras_cv.models.backbones.efficientnet_v2.efficientnet_v2_backbone import ( EfficientNetV2Backbone, ) -from keras_cv.models.backbones.efficientnet_v2.efficientnet_v2_backbone_presets import ( # noqa: E501 - backbone_presets, -) -from keras_cv.utils.python_utils import classproperty ALIAS_DOCSTRING = """Instantiates the {name} architecture. @@ -57,21 +51,6 @@ def __new__( ) return EfficientNetV2Backbone.from_preset("efficientnetv2_s", **kwargs) - @classproperty - def presets(cls): - """Dictionary of preset names and configurations.""" - return { - "efficientnetv2_s_imagenet": copy.deepcopy( - backbone_presets["efficientnetv2_s_imagenet"] - ), - } - - @classproperty - def presets_with_weights(cls): - """Dictionary of preset names and configurations that include - weights.""" - return cls.presets - @keras_cv_export("keras_cv.models.EfficientNetV2MBackbone") class EfficientNetV2MBackbone(EfficientNetV2Backbone): @@ -92,17 +71,6 @@ def __new__( ) return EfficientNetV2Backbone.from_preset("efficientnetv2_m", **kwargs) - @classproperty - def presets(cls): - """Dictionary of preset names and configurations.""" - return {} - - @classproperty - def presets_with_weights(cls): - """Dictionary of preset names and configurations that include - weights.""" - return {} - @keras_cv_export("keras_cv.models.EfficientNetV2LBackbone") class EfficientNetV2LBackbone(EfficientNetV2Backbone): @@ -123,18 +91,6 @@ def __new__( ) return EfficientNetV2Backbone.from_preset("efficientnetv2_l", **kwargs) - @classproperty - def presets(cls): - """Dictionary of preset names and configurations.""" - return {} - - @classproperty - def presets_with_weights(cls): - """Dictionary of preset names and configurations that include - weights.""" - return {} - - @keras_cv_export("keras_cv.models.EfficientNetV2B0Backbone") class EfficientNetV2B0Backbone(EfficientNetV2Backbone): def __new__( @@ -154,21 +110,6 @@ def __new__( ) return EfficientNetV2Backbone.from_preset("efficientnetv2_b0", **kwargs) - @classproperty - def presets(cls): - """Dictionary of preset names and configurations.""" - return { - "efficientnetv2_b0_imagenet": copy.deepcopy( - backbone_presets["efficientnetv2_b0_imagenet"] - ), - } - - @classproperty - def presets_with_weights(cls): - """Dictionary of preset names and configurations that include - weights.""" - return cls.presets - @keras_cv_export("keras_cv.models.EfficientNetV2B1Backbone") class EfficientNetV2B1Backbone(EfficientNetV2Backbone): @@ -189,21 +130,6 @@ def __new__( ) return EfficientNetV2Backbone.from_preset("efficientnetv2_b1", **kwargs) - @classproperty - def presets(cls): - """Dictionary of preset names and configurations.""" - return { - "efficientnetv2_b1_imagenet": copy.deepcopy( - backbone_presets["efficientnetv2_b1_imagenet"] - ), - } - - @classproperty - def presets_with_weights(cls): - """Dictionary of preset names and configurations that include - weights.""" - return cls.presets - @keras_cv_export("keras_cv.models.EfficientNetV2B2Backbone") class EfficientNetV2B2Backbone(EfficientNetV2Backbone): @@ -224,21 +150,6 @@ def __new__( ) return EfficientNetV2Backbone.from_preset("efficientnetv2_b2", **kwargs) - @classproperty - def presets(cls): - """Dictionary of preset names and configurations.""" - return { - "efficientnetv2_b2_imagenet": copy.deepcopy( - backbone_presets["efficientnetv2_b2_imagenet"] - ), - } - - @classproperty - def presets_with_weights(cls): - """Dictionary of preset names and configurations that include - weights.""" - return cls.presets - @keras_cv_export("keras_cv.models.EfficientNetV2B3Backbone") class EfficientNetV2B3Backbone(EfficientNetV2Backbone): @@ -259,16 +170,6 @@ def __new__( ) return EfficientNetV2Backbone.from_preset("efficientnetv2_b3", **kwargs) - @classproperty - def presets(cls): - """Dictionary of preset names and configurations.""" - return {} - - @classproperty - def presets_with_weights(cls): - """Dictionary of preset names and configurations that include - weights.""" - return {} setattr( diff --git a/keras_cv/models/backbones/efficientnet_v2/efficientnet_v2_backbone.py b/keras_cv/models/backbones/efficientnet_v2/efficientnet_v2_backbone.py index 1160184789..6cfe30809a 100644 --- a/keras_cv/models/backbones/efficientnet_v2/efficientnet_v2_backbone.py +++ b/keras_cv/models/backbones/efficientnet_v2/efficientnet_v2_backbone.py @@ -11,7 +11,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -import copy import math from keras_cv.api_export import keras_cv_export @@ -20,14 +19,6 @@ from keras_cv.layers import MBConvBlock from keras_cv.models import utils from keras_cv.models.backbones.backbone import Backbone -from keras_cv.models.backbones.efficientnet_v2.efficientnet_v2_backbone_presets import ( # noqa: E501 - backbone_presets, -) -from keras_cv.models.backbones.efficientnet_v2.efficientnet_v2_backbone_presets import ( # noqa: E501 - backbone_presets_with_weights, -) -from keras_cv.utils.python_utils import classproperty - @keras_cv_export("keras_cv.models.EfficientNetV2Backbone") class EfficientNetV2Backbone(Backbone): @@ -296,17 +287,6 @@ def get_config(self): ) return config - @classproperty - def presets(cls): - """Dictionary of preset names and configurations.""" - return copy.deepcopy(backbone_presets) - - @classproperty - def presets_with_weights(cls): - """Dictionary of preset names and configurations that include - weights.""" - return copy.deepcopy(backbone_presets_with_weights) - def conv_kernel_initializer(scale=2.0): return keras.initializers.VarianceScaling( diff --git a/keras_cv/models/backbones/mix_transformer/__init__.py b/keras_cv/models/backbones/mix_transformer/__init__.py index 3992ffb59a..3cc12a1763 100644 --- a/keras_cv/models/backbones/mix_transformer/__init__.py +++ b/keras_cv/models/backbones/mix_transformer/__init__.py @@ -11,3 +11,22 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + +from keras_cv.models.backbones.mix_transformer.mix_transformer_backbone_presets import ( + backbone_presets_no_weights, +) +from keras_cv.models.backbones.mix_transformer.mix_transformer_backbone_presets import ( + backbone_presets_with_weights, +) +from keras_cv.models.backbones.mix_transformer.mix_transformer_backbone import ( + MiTBackbone, +) +from keras_cv.models.backbones.mix_transformer.mix_transformer_aliases import ( + MiTB0Backbone, +) +from keras_cv.utils.preset_utils import register_presets, register_preset + +register_presets(backbone_presets_no_weights, (MiTBackbone, ), with_weights=False) +register_presets(backbone_presets_with_weights, (MiTBackbone, ), with_weights=True) +register_preset("mit_b0_imagenet", backbone_presets_with_weights["mit_b0_imagenet"], + (MiTB0Backbone,), with_weights=True) \ No newline at end of file diff --git a/keras_cv/models/backbones/mix_transformer/mix_transformer_aliases.py b/keras_cv/models/backbones/mix_transformer/mix_transformer_aliases.py index 65b88e7e1e..a1fb04a751 100644 --- a/keras_cv/models/backbones/mix_transformer/mix_transformer_aliases.py +++ b/keras_cv/models/backbones/mix_transformer/mix_transformer_aliases.py @@ -12,16 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -import copy - from keras_cv.api_export import keras_cv_export from keras_cv.models.backbones.mix_transformer.mix_transformer_backbone import ( MiTBackbone, ) -from keras_cv.models.backbones.mix_transformer.mix_transformer_backbone_presets import ( # noqa: E501 - backbone_presets, -) -from keras_cv.utils.python_utils import classproperty ALIAS_DOCSTRING = """MiT model. @@ -66,20 +60,6 @@ def __new__( ) return MiTBackbone.from_preset("mit_b0", **kwargs) - @classproperty - def presets(cls): - """Dictionary of preset names and configurations.""" - return { - "mit_b0_imagenet": copy.deepcopy( - backbone_presets["mit_b0_imagenet"] - ), - } - - @classproperty - def presets_with_weights(cls): - """Dictionary of preset names and configurations that include - weights.""" - return cls.presets @keras_cv_export("keras_cv.models.MiTB1Backbone") @@ -101,17 +81,6 @@ def __new__( ) return MiTBackbone.from_preset("mit_b1", **kwargs) - @classproperty - def presets(cls): - """Dictionary of preset names and configurations.""" - return {} - - @classproperty - def presets_with_weights(cls): - """Dictionary of preset names and configurations.""" - return {} - - @keras_cv_export("keras_cv.models.MiTB2Backbone") class MiTB2Backbone(MiTBackbone): def __new__( @@ -131,15 +100,6 @@ def __new__( ) return MiTBackbone.from_preset("mit_b2", **kwargs) - @classproperty - def presets(cls): - """Dictionary of preset names and configurations.""" - return {} - - @classproperty - def presets_with_weights(cls): - """Dictionary of preset names and configurations.""" - return {} @keras_cv_export("keras_cv.models.MiTB3Backbone") @@ -160,18 +120,6 @@ def __new__( } ) return MiTBackbone.from_preset("mit_b3", **kwargs) - - @classproperty - def presets(cls): - """Dictionary of preset names and configurations.""" - return {} - - @classproperty - def presets_with_weights(cls): - """Dictionary of preset names and configurations.""" - return {} - - @keras_cv_export("keras_cv.models.MiTB4Backbone") class MiTB4Backbone(MiTBackbone): def __new__( @@ -191,16 +139,6 @@ def __new__( ) return MiTBackbone.from_preset("mit_b4", **kwargs) - @classproperty - def presets(cls): - """Dictionary of preset names and configurations.""" - return {} - - @classproperty - def presets_with_weights(cls): - """Dictionary of preset names and configurations.""" - return {} - @keras_cv_export("keras_cv.models.MiTB5Backbone") class MiTB5Backbone(MiTBackbone): @@ -221,16 +159,6 @@ def __new__( ) return MiTBackbone.from_preset("mit_b5", **kwargs) - @classproperty - def presets(cls): - """Dictionary of preset names and configurations.""" - return {} - - @classproperty - def presets_with_weights(cls): - """Dictionary of preset names and configurations.""" - return {} - setattr( MiTB0Backbone, diff --git a/keras_cv/models/backbones/mix_transformer/mix_transformer_backbone.py b/keras_cv/models/backbones/mix_transformer/mix_transformer_backbone.py index 28efc48fc5..bb1ff9e43e 100644 --- a/keras_cv/models/backbones/mix_transformer/mix_transformer_backbone.py +++ b/keras_cv/models/backbones/mix_transformer/mix_transformer_backbone.py @@ -21,8 +21,6 @@ - [Inspired by @sithu31296's reimplementation](https://github.com/sithu31296/semantic-segmentation/blob/main/semseg/models/backbones/mit.py) """ # noqa: E501 -import copy - import numpy as np from keras_cv import layers as cv_layers @@ -31,13 +29,6 @@ from keras_cv.backend import ops from keras_cv.models import utils from keras_cv.models.backbones.backbone import Backbone -from keras_cv.models.backbones.mix_transformer.mix_transformer_backbone_presets import ( # noqa: E501 - backbone_presets, -) -from keras_cv.models.backbones.mix_transformer.mix_transformer_backbone_presets import ( # noqa: E501 - backbone_presets_with_weights, -) -from keras_cv.utils.python_utils import classproperty @keras_cv_export("keras_cv.models.MiTBackbone") @@ -175,14 +166,3 @@ def get_config(self): } ) return config - - @classproperty - def presets(cls): - """Dictionary of preset names and configurations.""" - return copy.deepcopy(backbone_presets) - - @classproperty - def presets_with_weights(cls): - """Dictionary of preset names and configurations that include - weights.""" - return copy.deepcopy(backbone_presets_with_weights) diff --git a/keras_cv/models/backbones/mobilenet_v3/__init__.py b/keras_cv/models/backbones/mobilenet_v3/__init__.py index 3992ffb59a..7b5618046b 100644 --- a/keras_cv/models/backbones/mobilenet_v3/__init__.py +++ b/keras_cv/models/backbones/mobilenet_v3/__init__.py @@ -11,3 +11,24 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + +from keras_cv.models.backbones.mobilenet_v3.mobilenet_v3_backbone_presets import ( + backbone_presets_no_weights, +) +from keras_cv.models.backbones.mobilenet_v3.mobilenet_v3_backbone_presets import ( + backbone_presets_with_weights, +) +from keras_cv.models.backbones.mobilenet_v3.mobilenet_v3_backbone import ( + MobileNetV3Backbone, +) +from keras_cv.models.backbones.mobilenet_v3.mobilenet_v3_aliases import ( + MobileNetV3SmallBackbone, MobileNetV3LargeBackbone +) +from keras_cv.utils.preset_utils import register_presets, register_preset + +register_presets(backbone_presets_no_weights, (MobileNetV3Backbone, ), with_weights=False) +register_presets(backbone_presets_with_weights, (MobileNetV3Backbone, ), with_weights=True) +register_preset("mobilenet_v3_small_imagenet", backbone_presets_with_weights["mobilenet_v3_small_imagenet"], + (MobileNetV3SmallBackbone, ), with_weights=True) +register_preset("mobilenet_v3_large_imagenet", backbone_presets_with_weights["mobilenet_v3_large_imagenet"], + (MobileNetV3LargeBackbone, ), with_weights=True) \ No newline at end of file diff --git a/keras_cv/models/backbones/mobilenet_v3/mobilenet_v3_aliases.py b/keras_cv/models/backbones/mobilenet_v3/mobilenet_v3_aliases.py index 752c088528..f28ea67d5e 100644 --- a/keras_cv/models/backbones/mobilenet_v3/mobilenet_v3_aliases.py +++ b/keras_cv/models/backbones/mobilenet_v3/mobilenet_v3_aliases.py @@ -12,16 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. -import copy - from keras_cv.api_export import keras_cv_export from keras_cv.models.backbones.mobilenet_v3.mobilenet_v3_backbone import ( MobileNetV3Backbone, ) -from keras_cv.models.backbones.mobilenet_v3.mobilenet_v3_backbone_presets import ( # noqa: E501 - backbone_presets, -) -from keras_cv.utils.python_utils import classproperty + ALIAS_DOCSTRING = """MobileNetV3Backbone model with {num_layers} layers. @@ -70,20 +65,6 @@ def __new__( ) return MobileNetV3Backbone.from_preset("mobilenet_v3_small", **kwargs) - @classproperty - def presets(cls): - """Dictionary of preset names and configurations.""" - return { - "mobilenet_v3_small_imagenet": copy.deepcopy( - backbone_presets["mobilenet_v3_small_imagenet"] - ), - } - - @classproperty - def presets_with_weights(cls): - """Dictionary of preset names and configurations.""" - return cls.presets - @keras_cv_export("keras_cv.models.MobileNetV3LargeBackbone") class MobileNetV3LargeBackbone(MobileNetV3Backbone): @@ -104,21 +85,6 @@ def __new__( ) return MobileNetV3Backbone.from_preset("mobilenet_v3_large", **kwargs) - @classproperty - def presets(cls): - """Dictionary of preset names and configurations.""" - return { - "mobilenet_v3_large_imagenet": copy.deepcopy( - backbone_presets["mobilenet_v3_large_imagenet"] - ), - } - - @classproperty - def presets_with_weights(cls): - """Dictionary of preset names and configurations that include - weights.""" - return cls.presets - setattr( MobileNetV3LargeBackbone, diff --git a/keras_cv/models/backbones/mobilenet_v3/mobilenet_v3_backbone.py b/keras_cv/models/backbones/mobilenet_v3/mobilenet_v3_backbone.py index 547fa57864..9c63ff844d 100644 --- a/keras_cv/models/backbones/mobilenet_v3/mobilenet_v3_backbone.py +++ b/keras_cv/models/backbones/mobilenet_v3/mobilenet_v3_backbone.py @@ -20,20 +20,11 @@ - [Based on the original keras.applications MobileNetv3](https://github.com/keras-team/keras/blob/master/keras/applications/mobilenet_v3.py) """ # noqa: E501 -import copy - from keras_cv import layers as cv_layers from keras_cv.api_export import keras_cv_export from keras_cv.backend import keras from keras_cv.models import utils from keras_cv.models.backbones.backbone import Backbone -from keras_cv.models.backbones.mobilenet_v3.mobilenet_v3_backbone_presets import ( # noqa: E501 - backbone_presets, -) -from keras_cv.models.backbones.mobilenet_v3.mobilenet_v3_backbone_presets import ( # noqa: E501 - backbone_presets_with_weights, -) -from keras_cv.utils.python_utils import classproperty CHANNEL_AXIS = -1 BN_EPSILON = 1e-3 @@ -198,17 +189,6 @@ def get_config(self): ) return config - @classproperty - def presets(cls): - """Dictionary of preset names and configurations.""" - return copy.deepcopy(backbone_presets) - - @classproperty - def presets_with_weights(cls): - """Dictionary of preset names and configurations that include - weights.""" - return copy.deepcopy(backbone_presets_with_weights) - class HardSigmoidActivation(keras.layers.Layer): def __init__(self): diff --git a/keras_cv/models/backbones/resnet_v1/__init__.py b/keras_cv/models/backbones/resnet_v1/__init__.py index 3992ffb59a..6aa3951fba 100644 --- a/keras_cv/models/backbones/resnet_v1/__init__.py +++ b/keras_cv/models/backbones/resnet_v1/__init__.py @@ -11,3 +11,22 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + +from keras_cv.models.backbones.resnet_v1.resnet_v1_backbone_presets import ( + backbone_presets_no_weights, +) +from keras_cv.models.backbones.resnet_v1.resnet_v1_backbone_presets import ( + backbone_presets_with_weights, +) +from keras_cv.models.backbones.resnet_v1.resnet_v1_backbone import ( + ResNetBackbone, +) +from keras_cv.models.backbones.resnet_v1.resnet_v1_aliases import ( + ResNet50Backbone, +) +from keras_cv.utils.preset_utils import register_presets, register_preset + +register_presets(backbone_presets_no_weights, (ResNetBackbone, ), with_weights=False) +register_presets(backbone_presets_with_weights, (ResNetBackbone, ), with_weights=True) +register_preset("resnet50_imagenet", backbone_presets_with_weights["resnet50_imagenet"], + (ResNet50Backbone,), with_weights=True) diff --git a/keras_cv/models/backbones/resnet_v1/resnet_v1_aliases.py b/keras_cv/models/backbones/resnet_v1/resnet_v1_aliases.py index 052b399306..70c54c0ac7 100644 --- a/keras_cv/models/backbones/resnet_v1/resnet_v1_aliases.py +++ b/keras_cv/models/backbones/resnet_v1/resnet_v1_aliases.py @@ -12,16 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -import copy - from keras_cv.api_export import keras_cv_export from keras_cv.models.backbones.resnet_v1.resnet_v1_backbone import ( ResNetBackbone, ) -from keras_cv.models.backbones.resnet_v1.resnet_v1_backbone_presets import ( - backbone_presets, -) -from keras_cv.utils.python_utils import classproperty ALIAS_DOCSTRING = """ResNetBackbone (V1) model with {num_layers} layers. @@ -75,17 +69,6 @@ def __new__( ) return ResNetBackbone.from_preset("resnet18", **kwargs) - @classproperty - def presets(cls): - """Dictionary of preset names and configurations.""" - return {} - - @classproperty - def presets_with_weights(cls): - """Dictionary of preset names and configurations that include - weights.""" - return {} - @keras_cv_export("keras_cv.models.ResNet34Backbone") class ResNet34Backbone(ResNetBackbone): @@ -106,17 +89,6 @@ def __new__( ) return ResNetBackbone.from_preset("resnet34", **kwargs) - @classproperty - def presets(cls): - """Dictionary of preset names and configurations.""" - return {} - - @classproperty - def presets_with_weights(cls): - """Dictionary of preset names and configurations that include - weights.""" - return {} - @keras_cv_export("keras_cv.models.ResNet50Backbone") class ResNet50Backbone(ResNetBackbone): @@ -137,20 +109,6 @@ def __new__( ) return ResNetBackbone.from_preset("resnet50", **kwargs) - @classproperty - def presets(cls): - """Dictionary of preset names and configurations.""" - return { - "resnet50_imagenet": copy.deepcopy( - backbone_presets["resnet50_imagenet"] - ), - } - - @classproperty - def presets_with_weights(cls): - """Dictionary of preset names and configurations that include - weights.""" - return cls.presets @keras_cv_export("keras_cv.models.ResNet101Backbone") @@ -172,17 +130,6 @@ def __new__( ) return ResNetBackbone.from_preset("resnet101", **kwargs) - @classproperty - def presets(cls): - """Dictionary of preset names and configurations.""" - return {} - - @classproperty - def presets_with_weights(cls): - """Dictionary of preset names and configurations that include - weights.""" - return {} - @keras_cv_export("keras_cv.models.ResNet152Backbone") class ResNet152Backbone(ResNetBackbone): @@ -203,16 +150,6 @@ def __new__( ) return ResNetBackbone.from_preset("resnet152", **kwargs) - @classproperty - def presets(cls): - """Dictionary of preset names and configurations.""" - return {} - - @classproperty - def presets_with_weights(cls): - """Dictionary of preset names and configurations that include - weights.""" - return {} setattr(ResNet18Backbone, "__doc__", ALIAS_DOCSTRING.format(num_layers=18)) diff --git a/keras_cv/models/backbones/resnet_v1/resnet_v1_backbone.py b/keras_cv/models/backbones/resnet_v1/resnet_v1_backbone.py index 07c896613c..6b9d37310d 100644 --- a/keras_cv/models/backbones/resnet_v1/resnet_v1_backbone.py +++ b/keras_cv/models/backbones/resnet_v1/resnet_v1_backbone.py @@ -18,19 +18,10 @@ - [Based on the original keras.applications ResNet](https://github.com/keras-team/keras/blob/master/keras/applications/resnet.py) # noqa: E501 """ -import copy - from keras_cv.api_export import keras_cv_export from keras_cv.backend import keras from keras_cv.models import utils from keras_cv.models.backbones.backbone import Backbone -from keras_cv.models.backbones.resnet_v1.resnet_v1_backbone_presets import ( - backbone_presets, -) -from keras_cv.models.backbones.resnet_v1.resnet_v1_backbone_presets import ( - backbone_presets_with_weights, -) -from keras_cv.utils.python_utils import classproperty BN_AXIS = 3 BN_EPSILON = 1.001e-5 @@ -162,17 +153,6 @@ def get_config(self): ) return config - @classproperty - def presets(cls): - """Dictionary of preset names and configurations.""" - return copy.deepcopy(backbone_presets) - - @classproperty - def presets_with_weights(cls): - """Dictionary of preset names and configurations that include - weights.""" - return copy.deepcopy(backbone_presets_with_weights) - def apply_basic_block( x, filters, kernel_size=3, stride=1, conv_shortcut=True, name=None diff --git a/keras_cv/models/backbones/resnet_v2/__init__.py b/keras_cv/models/backbones/resnet_v2/__init__.py index 3992ffb59a..d337558331 100644 --- a/keras_cv/models/backbones/resnet_v2/__init__.py +++ b/keras_cv/models/backbones/resnet_v2/__init__.py @@ -11,3 +11,22 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + +from keras_cv.models.backbones.resnet_v2.resnet_v2_backbone_presets import ( + backbone_presets_no_weights, +) +from keras_cv.models.backbones.resnet_v2.resnet_v2_backbone_presets import ( + backbone_presets_with_weights, +) +from keras_cv.models.backbones.resnet_v2.resnet_v2_backbone import ( + ResNetV2Backbone, +) +from keras_cv.models.backbones.resnet_v2.resnet_v2_aliases import ( + ResNet50V2Backbone, +) +from keras_cv.utils.preset_utils import register_presets, register_preset + +register_presets(backbone_presets_no_weights, (ResNetV2Backbone, ), with_weights=False) +register_presets(backbone_presets_with_weights, (ResNetV2Backbone, ), with_weights=True) +register_preset("resnet50_v2_imagenet", backbone_presets_with_weights["resnet50_v2_imagenet"], + (ResNet50V2Backbone,), with_weights=True) diff --git a/keras_cv/models/backbones/resnet_v2/resnet_v2_aliases.py b/keras_cv/models/backbones/resnet_v2/resnet_v2_aliases.py index 3878fb2a24..e9fdd9774e 100644 --- a/keras_cv/models/backbones/resnet_v2/resnet_v2_aliases.py +++ b/keras_cv/models/backbones/resnet_v2/resnet_v2_aliases.py @@ -12,16 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -import copy - from keras_cv.api_export import keras_cv_export from keras_cv.models.backbones.resnet_v2.resnet_v2_backbone import ( ResNetV2Backbone, ) -from keras_cv.models.backbones.resnet_v2.resnet_v2_backbone_presets import ( # noqa: E501 - backbone_presets, -) -from keras_cv.utils.python_utils import classproperty ALIAS_DOCSTRING = """ResNetV2Backbone model with {num_layers} layers. @@ -75,17 +69,6 @@ def __new__( ) return ResNetV2Backbone.from_preset("resnet18_v2", **kwargs) - @classproperty - def presets(cls): - """Dictionary of preset names and configurations.""" - return {} - - @classproperty - def presets_with_weights(cls): - """Dictionary of preset names and configurations that include - weights.""" - return {} - @keras_cv_export("keras_cv.models.ResNet34V2Backbone") class ResNet34V2Backbone(ResNetV2Backbone): @@ -106,17 +89,6 @@ def __new__( ) return ResNetV2Backbone.from_preset("resnet34_v2", **kwargs) - @classproperty - def presets(cls): - """Dictionary of preset names and configurations.""" - return {} - - @classproperty - def presets_with_weights(cls): - """Dictionary of preset names and configurations that include - weights.""" - return {} - @keras_cv_export("keras_cv.models.ResNet50V2Backbone") class ResNet50V2Backbone(ResNetV2Backbone): @@ -137,21 +109,6 @@ def __new__( ) return ResNetV2Backbone.from_preset("resnet50_v2", **kwargs) - @classproperty - def presets(cls): - """Dictionary of preset names and configurations.""" - return { - "resnet50_v2_imagenet": copy.deepcopy( - backbone_presets["resnet50_v2_imagenet"] - ), - } - - @classproperty - def presets_with_weights(cls): - """Dictionary of preset names and configurations that include - weights.""" - return cls.presets - @keras_cv_export("keras_cv.models.ResNet101V2Backbone") class ResNet101V2Backbone(ResNetV2Backbone): @@ -172,17 +129,6 @@ def __new__( ) return ResNetV2Backbone.from_preset("resnet101_v2", **kwargs) - @classproperty - def presets(cls): - """Dictionary of preset names and configurations.""" - return {} - - @classproperty - def presets_with_weights(cls): - """Dictionary of preset names and configurations that include - weights.""" - return {} - @keras_cv_export("keras_cv.models.ResNet152V2Backbone") class ResNet152V2Backbone(ResNetV2Backbone): @@ -203,17 +149,6 @@ def __new__( ) return ResNetV2Backbone.from_preset("resnet152_v2", **kwargs) - @classproperty - def presets(cls): - """Dictionary of preset names and configurations.""" - return {} - - @classproperty - def presets_with_weights(cls): - """Dictionary of preset names and configurations that include - weights.""" - return {} - setattr( ResNet18V2Backbone, diff --git a/keras_cv/models/backbones/resnet_v2/resnet_v2_backbone.py b/keras_cv/models/backbones/resnet_v2/resnet_v2_backbone.py index 6a0cc74740..23ac77ff07 100644 --- a/keras_cv/models/backbones/resnet_v2/resnet_v2_backbone.py +++ b/keras_cv/models/backbones/resnet_v2/resnet_v2_backbone.py @@ -17,19 +17,10 @@ - [Based on the original keras.applications ResNet](https://github.com/keras-team/keras/blob/master/keras/applications/resnet_v2.py) """ # noqa: E501 -import copy - from keras_cv.api_export import keras_cv_export from keras_cv.backend import keras from keras_cv.models import utils from keras_cv.models.backbones.backbone import Backbone -from keras_cv.models.backbones.resnet_v2.resnet_v2_backbone_presets import ( - backbone_presets, -) -from keras_cv.models.backbones.resnet_v2.resnet_v2_backbone_presets import ( - backbone_presets_with_weights, -) -from keras_cv.utils.python_utils import classproperty BN_AXIS = 3 BN_EPSILON = 1.001e-5 @@ -175,17 +166,6 @@ def get_config(self): ) return config - @classproperty - def presets(cls): - """Dictionary of preset names and configurations.""" - return copy.deepcopy(backbone_presets) - - @classproperty - def presets_with_weights(cls): - """Dictionary of preset names and configurations that include - weights.""" - return copy.deepcopy(backbone_presets_with_weights) - def apply_basic_block( x, diff --git a/keras_cv/models/backbones/video_swin/__init__.py b/keras_cv/models/backbones/video_swin/__init__.py index 0e9cbb5ac9..1f40fc3144 100644 --- a/keras_cv/models/backbones/video_swin/__init__.py +++ b/keras_cv/models/backbones/video_swin/__init__.py @@ -11,3 +11,26 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + +from keras_cv.models.backbones.video_swin.video_swin_backbone_presets import ( + backbone_presets_no_weights, +) +from keras_cv.models.backbones.video_swin.video_swin_backbone_presets import ( + backbone_presets_with_weights, +) +from keras_cv.models.backbones.video_swin.video_swin_backbone import ( + VideoSwinBackbone, +) +from keras_cv.models.backbones.video_swin.video_swin_aliases import ( + VideoSwinTBackbone, VideoSwinSBackbone, VideoSwinBBackbone, +) +from keras_cv.utils.preset_utils import register_presets, register_preset + +register_presets(backbone_presets_no_weights, (VideoSwinBackbone, ), with_weights=False) +register_presets(backbone_presets_with_weights, (VideoSwinBackbone, ), with_weights=True) +register_preset("videoswin_tiny_kinetics400", backbone_presets_with_weights["videoswin_tiny_kinetics400"], + (VideoSwinTBackbone,), with_weights=True) +register_preset("videoswin_small_kinetics400", backbone_presets_with_weights["videoswin_small_kinetics400"], + (VideoSwinSBackbone,), with_weights=True) +register_preset("videoswin_base_kinetics400", backbone_presets_with_weights["videoswin_base_kinetics400"], + (VideoSwinBBackbone,), with_weights=True) \ No newline at end of file diff --git a/keras_cv/models/backbones/video_swin/video_swin_aliases.py b/keras_cv/models/backbones/video_swin/video_swin_aliases.py index 161ba0bbb4..707b57e493 100644 --- a/keras_cv/models/backbones/video_swin/video_swin_aliases.py +++ b/keras_cv/models/backbones/video_swin/video_swin_aliases.py @@ -12,15 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -import copy - from keras_cv.models.backbones.video_swin.video_swin_backbone import ( VideoSwinBackbone, ) -from keras_cv.models.backbones.video_swin.video_swin_backbone_presets import ( - backbone_presets, -) -from keras_cv.utils.python_utils import classproperty ALIAS_DOCSTRING = """VideoSwin{size}Backbone model. @@ -63,21 +57,6 @@ def __new__( ) return VideoSwinBackbone.from_preset("videoswin_tiny", **kwargs) - @classproperty - def presets(cls): - """Dictionary of preset names and configurations.""" - return { - "videoswin_tiny_kinetics400": copy.deepcopy( - backbone_presets["videoswin_tiny_kinetics400"] - ), - } - - @classproperty - def presets_with_weights(cls): - """Dictionary of preset names and configurations that include - weights.""" - return cls.presets - class VideoSwinSBackbone(VideoSwinBackbone): def __new__( @@ -100,21 +79,6 @@ def __new__( ) return VideoSwinBackbone.from_preset("videoswin_small", **kwargs) - @classproperty - def presets(cls): - """Dictionary of preset names and configurations.""" - return { - "videoswin_small_kinetics400": copy.deepcopy( - backbone_presets["videoswin_small_kinetics400"] - ), - } - - @classproperty - def presets_with_weights(cls): - """Dictionary of preset names and configurations that include - weights.""" - return cls.presets - class VideoSwinBBackbone(VideoSwinBackbone): def __new__( @@ -137,20 +101,6 @@ def __new__( ) return VideoSwinBackbone.from_preset("videoswin_base", **kwargs) - @classproperty - def presets(cls): - """Dictionary of preset names and configurations.""" - return { - "videoswin_base_kinetics400": copy.deepcopy( - backbone_presets["videoswin_base_kinetics400"] - ), - } - - @classproperty - def presets_with_weights(cls): - """Dictionary of preset names and configurations that include - weights.""" - return cls.presets setattr(VideoSwinTBackbone, "__doc__", ALIAS_DOCSTRING.format(size="T")) diff --git a/keras_cv/models/backbones/video_swin/video_swin_backbone.py b/keras_cv/models/backbones/video_swin/video_swin_backbone.py index 9bb62eb385..26872dc549 100644 --- a/keras_cv/models/backbones/video_swin/video_swin_backbone.py +++ b/keras_cv/models/backbones/video_swin/video_swin_backbone.py @@ -11,7 +11,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -import copy from functools import partial import numpy as np @@ -21,12 +20,6 @@ from keras_cv.backend import keras from keras_cv.models import utils from keras_cv.models.backbones.backbone import Backbone -from keras_cv.models.backbones.video_swin.video_swin_backbone_presets import ( # noqa: E501 - backbone_presets, -) -from keras_cv.models.backbones.video_swin.video_swin_backbone_presets import ( # noqa: E501 - backbone_presets_with_weights, -) from keras_cv.models.backbones.video_swin.video_swin_layers import ( VideoSwinBasicLayer, ) @@ -36,7 +29,6 @@ from keras_cv.models.backbones.video_swin.video_swin_layers import ( VideoSwinPatchMerging, ) -from keras_cv.utils.python_utils import classproperty @keras_cv_export("keras_cv.models.VideoSwinBackbone", package="keras_cv.models") @@ -222,17 +214,6 @@ def get_config(self): ) return config - @classproperty - def presets(cls): - """Dictionary of preset names and configurations.""" - return copy.deepcopy(backbone_presets) - - @classproperty - def presets_with_weights(cls): - """Dictionary of preset names and configurations that include - weights.""" - return copy.deepcopy(backbone_presets_with_weights) - @property def pyramid_level_inputs(self): raise NotImplementedError( diff --git a/keras_cv/models/backbones/vit_det/__init__.py b/keras_cv/models/backbones/vit_det/__init__.py index 3992ffb59a..9d0f010897 100644 --- a/keras_cv/models/backbones/vit_det/__init__.py +++ b/keras_cv/models/backbones/vit_det/__init__.py @@ -11,3 +11,26 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + +from keras_cv.models.backbones.vit_det.vit_det_backbone_presets import ( + backbone_presets_no_weights, +) +from keras_cv.models.backbones.vit_det.vit_det_backbone_presets import ( + backbone_presets_with_weights, +) +from keras_cv.models.backbones.vit_det.vit_det_backbone import ( + ViTDetBackbone, +) +from keras_cv.models.backbones.vit_det.vit_det_aliases import ( + ViTDetBBackbone, ViTDetLBackbone, ViTDetHBackbone, +) +from keras_cv.utils.preset_utils import register_presets, register_preset + +register_presets(backbone_presets_no_weights, (ViTDetBackbone, ), with_weights=False) +register_presets(backbone_presets_with_weights, (ViTDetBackbone, ), with_weights=True) +register_preset("vitdet_base_sa1b", backbone_presets_with_weights["vitdet_base_sa1b"], + (ViTDetBBackbone,), with_weights=True) +register_preset("vitdet_large_sa1b", backbone_presets_with_weights["vitdet_large_sa1b"], + (ViTDetLBackbone,), with_weights=True) +register_preset("vitdet_huge_sa1b", backbone_presets_with_weights["vitdet_huge_sa1b"], + (ViTDetHBackbone,), with_weights=True) diff --git a/keras_cv/models/object_detection/retinanet/retinanet_test.py b/keras_cv/models/object_detection/retinanet/retinanet_test.py index bbede75943..b939f2e481 100644 --- a/keras_cv/models/object_detection/retinanet/retinanet_test.py +++ b/keras_cv/models/object_detection/retinanet/retinanet_test.py @@ -280,7 +280,7 @@ def data_generator(): bounding_box_format="xyxy", backbone=keras_cv.models.ResNet50Backbone.from_preset( "resnet50_imagenet", - load_weights=False, + #load_weights=False, ), ) diff --git a/keras_cv/models/object_detection/yolo_v8/__init__.py b/keras_cv/models/object_detection/yolo_v8/__init__.py index 8ec6a842ed..a95055f2ff 100644 --- a/keras_cv/models/object_detection/yolo_v8/__init__.py +++ b/keras_cv/models/object_detection/yolo_v8/__init__.py @@ -14,3 +14,16 @@ from keras_cv.models.object_detection.yolo_v8.yolo_v8_label_encoder import ( YOLOV8LabelEncoder, ) +from keras_cv.models.object_detection.yolo_v8.yolo_v8_backbone_presets import ( + backbone_presets_no_weights, +) +from keras_cv.models.object_detection.yolo_v8.yolo_v8_backbone_presets import ( + backbone_presets_with_weights, +) +from keras_cv.models.object_detection.yolo_v8.yolo_v8_backbone import ( + YOLOV8Backbone, +) +from keras_cv.utils.preset_utils import register_presets + +register_presets(backbone_presets_no_weights, (YOLOV8Backbone, ), with_weights=False) +register_presets(backbone_presets_with_weights, (YOLOV8Backbone, ), with_weights=True) diff --git a/keras_cv/models/object_detection/yolo_v8/yolo_v8_backbone.py b/keras_cv/models/object_detection/yolo_v8/yolo_v8_backbone.py index a2bf4bdd3b..dfd0cfb1e8 100644 --- a/keras_cv/models/object_detection/yolo_v8/yolo_v8_backbone.py +++ b/keras_cv/models/object_detection/yolo_v8/yolo_v8_backbone.py @@ -11,26 +11,18 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -import copy from keras_cv.api_export import keras_cv_export from keras_cv.backend import keras from keras_cv.backend import ops from keras_cv.models import utils from keras_cv.models.backbones.backbone import Backbone -from keras_cv.models.object_detection.yolo_v8.yolo_v8_backbone_presets import ( - backbone_presets, -) -from keras_cv.models.object_detection.yolo_v8.yolo_v8_backbone_presets import ( - backbone_presets_with_weights, -) from keras_cv.models.object_detection.yolo_v8.yolo_v8_layers import ( apply_conv_bn, ) from keras_cv.models.object_detection.yolo_v8.yolo_v8_layers import ( apply_csp_block, ) -from keras_cv.utils.python_utils import classproperty def apply_spatial_pyramid_pooling_fast( @@ -203,13 +195,3 @@ def get_config(self): ) return config - @classproperty - def presets(cls): - """Dictionary of preset names and configurations.""" - return copy.deepcopy(backbone_presets) - - @classproperty - def presets_with_weights(cls): - """Dictionary of preset names and configurations that include - weights.""" - return copy.deepcopy(backbone_presets_with_weights) diff --git a/keras_cv/models/object_detection_3d/__init__.py b/keras_cv/models/object_detection_3d/__init__.py index 50ed959e68..588dabe0e3 100644 --- a/keras_cv/models/object_detection_3d/__init__.py +++ b/keras_cv/models/object_detection_3d/__init__.py @@ -17,3 +17,13 @@ from keras_cv.models.object_detection_3d.center_pillar_backbone import ( CenterPillarBackbone, ) +from keras_cv.models.object_detection_3d.center_pillar_backbone_presets import ( + backbone_presets_no_weights, +) +from keras_cv.models.object_detection_3d.center_pillar_backbone_presets import ( + backbone_presets_with_weights, +) +from keras_cv.utils.preset_utils import register_presets + +register_presets(backbone_presets_no_weights, (CenterPillarBackbone, ), with_weights=False) +register_presets(backbone_presets_with_weights, (CenterPillarBackbone, ), with_weights=True) diff --git a/keras_cv/models/object_detection_3d/center_pillar_backbone.py b/keras_cv/models/object_detection_3d/center_pillar_backbone.py index 01554f260b..1e669745b8 100644 --- a/keras_cv/models/object_detection_3d/center_pillar_backbone.py +++ b/keras_cv/models/object_detection_3d/center_pillar_backbone.py @@ -11,15 +11,10 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -import copy from keras_cv.api_export import keras_cv_export from keras_cv.backend import keras from keras_cv.models.backbones.backbone import Backbone -from keras_cv.models.object_detection_3d.center_pillar_backbone_presets import ( - backbone_presets, -) -from keras_cv.utils.python_utils import classproperty @keras_cv_export("keras_cv.models.CenterPillarBackbone") @@ -103,11 +98,6 @@ def get_config(self): ) return config - @classproperty - def presets(cls): - """Dictionary of preset names and configurations.""" - return copy.deepcopy(backbone_presets) - def Block(filters, downsample): """A default block which serves as an example of the block interface. diff --git a/keras_cv/models/object_detection_3d/center_pillar_backbone_presets.py b/keras_cv/models/object_detection_3d/center_pillar_backbone_presets.py index 8f875e638a..2ef5f65bda 100644 --- a/keras_cv/models/object_detection_3d/center_pillar_backbone_presets.py +++ b/keras_cv/models/object_detection_3d/center_pillar_backbone_presets.py @@ -14,7 +14,7 @@ """YOLOv8 Backbone presets.""" -backbone_presets = { +backbone_presets_no_weights = { "center_pillar_waymo_open_dataset": { "metadata": { "description": "An example CenterPillar backbone for WOD.", @@ -24,3 +24,10 @@ "kaggle_handle": "gs://keras-cv-kaggle/center_pillar_waymo_open_dataset", # noqa: E501 }, } + +backbone_presets_with_weights = {} + +backbone_presets = { + **backbone_presets_no_weights, + **backbone_presets_with_weights, +} \ No newline at end of file diff --git a/keras_cv/utils/preset_utils.py b/keras_cv/utils/preset_utils.py index bb0b6b0a0b..53df484f41 100644 --- a/keras_cv/utils/preset_utils.py +++ b/keras_cv/utils/preset_utils.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import collections import datetime import inspect import json @@ -27,6 +28,11 @@ KAGGLE_PREFIX = "kaggle://" GS_PREFIX = "gs://" +# Global state for preset registry. +BUILTIN_PRESETS = {} +BUILTIN_PRESETS_FOR_CLASS = collections.defaultdict(dict) +BUILTIN_PRESETS_FOR_CLASS_WITH_WEIGHT = collections.defaultdict(dict) + def get_file(preset, path): """Download a preset file in necessary and return the local path.""" @@ -34,6 +40,10 @@ def get_file(preset, path): raise ValueError( f"A preset identifier must be a string. Received: preset={preset}" ) + + if preset in BUILTIN_PRESETS: + preset = BUILTIN_PRESETS[preset]["kaggle_handle"] + if preset.startswith(KAGGLE_PREFIX): if kagglehub is None: raise ImportError( @@ -170,6 +180,23 @@ def load_from_preset( return layer +def check_config_class( + preset, + config_file="config.json", +): + """Validate a preset is being loaded on the correct class.""" + config_path = get_file(preset, config_file) + try: + with open(config_path) as config_file: + config = json.load(config_file) + except: + raise ValueError( + f"The specified preset `{preset}` is unknown. " + "Please check documentation to ensure the correct preset " + "handle is being used." + ) + return keras.saving.get_registered_object(config["registered_name"]) + def check_preset_class( preset, classes, @@ -202,7 +229,6 @@ def check_preset_class( ) return cls - def legacy_load_weights(layer, weights_path): # Hacky fix for TensorFlow 2.13 and 2.14 when loading a `.weights.h5` file. # We find the `Functional` class, and temporarily remove the @@ -216,3 +242,33 @@ def legacy_load_weights(layer, weights_path): functional_cls._layer_checkpoint_dependencies = {} layer.load_weights(weights_path) functional_cls._layer_checkpoint_dependencies = property + + +def register_preset(preset_name, preset, classes, with_weights=False): + BUILTIN_PRESETS[preset_name] = preset + for cls in classes: + BUILTIN_PRESETS_FOR_CLASS[cls][preset_name] = preset + if with_weights: + BUILTIN_PRESETS_FOR_CLASS_WITH_WEIGHT[cls][preset_name] = preset + + +def register_presets(presets, classes, with_weights=False): + for preset_name, preset in presets.items(): + register_preset(preset_name, preset, classes, with_weights) + + +def list_presets(cls, with_weights=False): + """Find all registered builtin presets for a class.""" + if with_weights: + return dict(BUILTIN_PRESETS_FOR_CLASS_WITH_WEIGHT[cls]) + return dict(BUILTIN_PRESETS_FOR_CLASS[cls]) + + +def list_subclasses(cls): + """Find all registered subclasses of a class.""" + custom_objects = keras.saving.get_custom_objects().values() + subclasses = [] + for x in custom_objects: + if inspect.isclass(x) and x != cls and issubclass(x, cls): + subclasses.append(x) + return subclasses From 49884ead062383551e571e5478531bf44a8e0c6c Mon Sep 17 00:00:00 2001 From: Smit Lunagariya Date: Tue, 16 Apr 2024 06:43:55 +0000 Subject: [PATCH 2/3] fix styling --- .../models/backbones/csp_darknet/__init__.py | 45 ++++++++++---- .../csp_darknet/csp_darknet_aliases.py | 1 - .../csp_darknet/csp_darknet_backbone.py | 1 + .../models/backbones/densenet/__init__.py | 51 ++++++++++----- .../backbones/densenet/densenet_aliases.py | 1 + .../backbones/efficientnet_lite/__init__.py | 16 +++-- .../efficientnet_lite_aliases.py | 2 +- .../backbones/efficientnet_v1/__init__.py | 14 +++-- .../efficientnet_v1_aliases.py | 2 + .../backbones/efficientnet_v2/__init__.py | 62 ++++++++++++++----- .../efficientnet_v2_aliases.py | 2 +- .../efficientnet_v2_backbone.py | 1 + .../backbones/mix_transformer/__init__.py | 29 ++++++--- .../mix_transformer_aliases.py | 5 +- .../models/backbones/mobilenet_v3/__init__.py | 40 ++++++++---- .../mobilenet_v3/mobilenet_v3_aliases.py | 1 - .../models/backbones/resnet_v1/__init__.py | 29 ++++++--- .../backbones/resnet_v1/resnet_v1_aliases.py | 2 - .../models/backbones/resnet_v2/__init__.py | 29 ++++++--- .../models/backbones/video_swin/__init__.py | 51 ++++++++++----- .../video_swin/video_swin_aliases.py | 1 - keras_cv/models/backbones/vit_det/__init__.py | 43 ++++++++----- .../retinanet/retinanet_test.py | 2 +- .../object_detection/yolo_v8/__init__.py | 16 +++-- .../yolo_v8/yolo_v8_backbone.py | 1 - .../models/object_detection_3d/__init__.py | 8 ++- .../center_pillar_backbone_presets.py | 4 +- keras_cv/utils/preset_utils.py | 2 + 28 files changed, 318 insertions(+), 143 deletions(-) diff --git a/keras_cv/models/backbones/csp_darknet/__init__.py b/keras_cv/models/backbones/csp_darknet/__init__.py index 3326878c56..327ebcf3d3 100644 --- a/keras_cv/models/backbones/csp_darknet/__init__.py +++ b/keras_cv/models/backbones/csp_darknet/__init__.py @@ -12,21 +12,42 @@ # See the License for the specific language governing permissions and # limitations under the License. -from keras_cv.models.backbones.csp_darknet.csp_darknet_backbone_presets import ( - backbone_presets_no_weights, backbone_presets_with_weights, +from keras_cv.models.backbones.csp_darknet.csp_darknet_aliases import ( + CSPDarkNetLBackbone, +) +from keras_cv.models.backbones.csp_darknet.csp_darknet_aliases import ( + CSPDarkNetTinyBackbone, ) from keras_cv.models.backbones.csp_darknet.csp_darknet_backbone import ( CSPDarkNetBackbone, ) -from keras_cv.models.backbones.csp_darknet.csp_darknet_aliases import ( - CSPDarkNetTinyBackbone, CSPDarkNetLBackbone, +from keras_cv.models.backbones.csp_darknet.csp_darknet_backbone_presets import ( + backbone_presets_no_weights, ) -from keras_cv.utils.preset_utils import register_presets, register_preset +from keras_cv.models.backbones.csp_darknet.csp_darknet_backbone_presets import ( + backbone_presets_with_weights, +) +from keras_cv.utils.preset_utils import register_preset +from keras_cv.utils.preset_utils import register_presets -register_presets(backbone_presets_no_weights, (CSPDarkNetBackbone, ), with_weights=False) -register_presets(backbone_presets_with_weights, (CSPDarkNetBackbone, ), with_weights=True) -register_presets(backbone_presets_with_weights, (CSPDarkNetBackbone, ), with_weights=True) -register_preset("csp_darknet_tiny_imagenet", backbone_presets_with_weights["csp_darknet_tiny_imagenet"], - (CSPDarkNetTinyBackbone,), with_weights=True) -register_preset("csp_darknet_l_imagenet", backbone_presets_with_weights["csp_darknet_l_imagenet"], - (CSPDarkNetLBackbone,), with_weights=True) +register_presets( + backbone_presets_no_weights, (CSPDarkNetBackbone,), with_weights=False +) +register_presets( + backbone_presets_with_weights, (CSPDarkNetBackbone,), with_weights=True +) +register_presets( + backbone_presets_with_weights, (CSPDarkNetBackbone,), with_weights=True +) +register_preset( + "csp_darknet_tiny_imagenet", + backbone_presets_with_weights["csp_darknet_tiny_imagenet"], + (CSPDarkNetTinyBackbone,), + with_weights=True, +) +register_preset( + "csp_darknet_l_imagenet", + backbone_presets_with_weights["csp_darknet_l_imagenet"], + (CSPDarkNetLBackbone,), + with_weights=True, +) diff --git a/keras_cv/models/backbones/csp_darknet/csp_darknet_aliases.py b/keras_cv/models/backbones/csp_darknet/csp_darknet_aliases.py index c3e85ac9a2..e028961a47 100644 --- a/keras_cv/models/backbones/csp_darknet/csp_darknet_aliases.py +++ b/keras_cv/models/backbones/csp_darknet/csp_darknet_aliases.py @@ -147,7 +147,6 @@ def __new__( return CSPDarkNetBackbone.from_preset("csp_darknet_xl", **kwargs) - setattr( CSPDarkNetTinyBackbone, "__doc__", diff --git a/keras_cv/models/backbones/csp_darknet/csp_darknet_backbone.py b/keras_cv/models/backbones/csp_darknet/csp_darknet_backbone.py index 28f075406c..a90e7c5a36 100644 --- a/keras_cv/models/backbones/csp_darknet/csp_darknet_backbone.py +++ b/keras_cv/models/backbones/csp_darknet/csp_darknet_backbone.py @@ -32,6 +32,7 @@ SpatialPyramidPoolingBottleneck, ) + @keras_cv_export("keras_cv.models.CSPDarkNetBackbone") class CSPDarkNetBackbone(Backbone): """This class represents the CSPDarkNet architecture. diff --git a/keras_cv/models/backbones/densenet/__init__.py b/keras_cv/models/backbones/densenet/__init__.py index aeda8288ae..0ef0be1d11 100644 --- a/keras_cv/models/backbones/densenet/__init__.py +++ b/keras_cv/models/backbones/densenet/__init__.py @@ -12,25 +12,48 @@ # See the License for the specific language governing permissions and # limitations under the License. +from keras_cv.models.backbones.densenet.densenet_aliases import ( + DenseNet121Backbone, +) +from keras_cv.models.backbones.densenet.densenet_aliases import ( + DenseNet169Backbone, +) +from keras_cv.models.backbones.densenet.densenet_aliases import ( + DenseNet201Backbone, +) +from keras_cv.models.backbones.densenet.densenet_backbone import ( + DenseNetBackbone, +) from keras_cv.models.backbones.densenet.densenet_backbone_presets import ( backbone_presets_no_weights, ) from keras_cv.models.backbones.densenet.densenet_backbone_presets import ( backbone_presets_with_weights, ) -from keras_cv.models.backbones.densenet.densenet_backbone import ( - DenseNetBackbone, +from keras_cv.utils.preset_utils import register_preset +from keras_cv.utils.preset_utils import register_presets + +register_presets( + backbone_presets_no_weights, (DenseNetBackbone,), with_weights=False ) -from keras_cv.models.backbones.densenet.densenet_aliases import ( - DenseNet121Backbone, DenseNet169Backbone, DenseNet201Backbone +register_presets( + backbone_presets_with_weights, (DenseNetBackbone,), with_weights=True +) +register_preset( + "densenet121_imagenet", + backbone_presets_with_weights["densenet121_imagenet"], + (DenseNet121Backbone,), + with_weights=True, +) +register_preset( + "densenet169_imagenet", + backbone_presets_with_weights["densenet169_imagenet"], + (DenseNet169Backbone,), + with_weights=True, +) +register_preset( + "densenet201_imagenet", + backbone_presets_with_weights["densenet201_imagenet"], + (DenseNet201Backbone,), + with_weights=True, ) -from keras_cv.utils.preset_utils import register_presets, register_preset - -register_presets(backbone_presets_no_weights, (DenseNetBackbone, ), with_weights=False) -register_presets(backbone_presets_with_weights, (DenseNetBackbone, ), with_weights=True) -register_preset("densenet121_imagenet", backbone_presets_with_weights["densenet121_imagenet"], - (DenseNet121Backbone,), with_weights=True) -register_preset("densenet169_imagenet", backbone_presets_with_weights["densenet169_imagenet"], - (DenseNet169Backbone,), with_weights=True) -register_preset("densenet201_imagenet", backbone_presets_with_weights["densenet201_imagenet"], - (DenseNet201Backbone,), with_weights=True) diff --git a/keras_cv/models/backbones/densenet/densenet_aliases.py b/keras_cv/models/backbones/densenet/densenet_aliases.py index 789695ea0e..ec0d8a0f11 100644 --- a/keras_cv/models/backbones/densenet/densenet_aliases.py +++ b/keras_cv/models/backbones/densenet/densenet_aliases.py @@ -63,6 +63,7 @@ def __new__( ) return DenseNetBackbone.from_preset("densenet121", **kwargs) + @keras_cv_export("keras_cv.models.DenseNet169Backbone") class DenseNet169Backbone(DenseNetBackbone): def __new__( diff --git a/keras_cv/models/backbones/efficientnet_lite/__init__.py b/keras_cv/models/backbones/efficientnet_lite/__init__.py index b90f74b7df..0950d60130 100644 --- a/keras_cv/models/backbones/efficientnet_lite/__init__.py +++ b/keras_cv/models/backbones/efficientnet_lite/__init__.py @@ -12,16 +12,22 @@ # See the License for the specific language governing permissions and # limitations under the License. +from keras_cv.models.backbones.efficientnet_lite.efficientnet_lite_backbone import ( + EfficientNetLiteBackbone, +) from keras_cv.models.backbones.efficientnet_lite.efficientnet_lite_backbone_presets import ( backbone_presets_no_weights, ) from keras_cv.models.backbones.efficientnet_lite.efficientnet_lite_backbone_presets import ( backbone_presets_with_weights, ) -from keras_cv.models.backbones.efficientnet_lite.efficientnet_lite_backbone import ( - EfficientNetLiteBackbone, -) from keras_cv.utils.preset_utils import register_presets -register_presets(backbone_presets_no_weights, (EfficientNetLiteBackbone, ), with_weights=False) -register_presets(backbone_presets_with_weights, (EfficientNetLiteBackbone, ), with_weights=True) +register_presets( + backbone_presets_no_weights, (EfficientNetLiteBackbone,), with_weights=False +) +register_presets( + backbone_presets_with_weights, + (EfficientNetLiteBackbone,), + with_weights=True, +) diff --git a/keras_cv/models/backbones/efficientnet_lite/efficientnet_lite_aliases.py b/keras_cv/models/backbones/efficientnet_lite/efficientnet_lite_aliases.py index 4eafdb3258..3f2fb87a4f 100644 --- a/keras_cv/models/backbones/efficientnet_lite/efficientnet_lite_aliases.py +++ b/keras_cv/models/backbones/efficientnet_lite/efficientnet_lite_aliases.py @@ -107,7 +107,6 @@ def __new__( ) - @keras_cv_export("keras_cv.models.EfficientNetLiteB3Backbone") class EfficientNetLiteB3Backbone(EfficientNetLiteBackbone): def __new__( @@ -151,6 +150,7 @@ def __new__( "efficientnetlite_b4", **kwargs ) + setattr( EfficientNetLiteB0Backbone, "__doc__", diff --git a/keras_cv/models/backbones/efficientnet_v1/__init__.py b/keras_cv/models/backbones/efficientnet_v1/__init__.py index 5f0a53c7ec..26faa501f5 100644 --- a/keras_cv/models/backbones/efficientnet_v1/__init__.py +++ b/keras_cv/models/backbones/efficientnet_v1/__init__.py @@ -12,16 +12,20 @@ # See the License for the specific language governing permissions and # limitations under the License. +from keras_cv.models.backbones.efficientnet_v1.efficientnet_v1_backbone import ( + EfficientNetV1Backbone, +) from keras_cv.models.backbones.efficientnet_v1.efficientnet_v1_backbone_presets import ( backbone_presets_no_weights, ) from keras_cv.models.backbones.efficientnet_v1.efficientnet_v1_backbone_presets import ( backbone_presets_with_weights, ) -from keras_cv.models.backbones.efficientnet_v1.efficientnet_v1_backbone import ( - EfficientNetV1Backbone, -) from keras_cv.utils.preset_utils import register_presets -register_presets(backbone_presets_no_weights, (EfficientNetV1Backbone, ), with_weights=False) -register_presets(backbone_presets_with_weights, (EfficientNetV1Backbone, ), with_weights=True) +register_presets( + backbone_presets_no_weights, (EfficientNetV1Backbone,), with_weights=False +) +register_presets( + backbone_presets_with_weights, (EfficientNetV1Backbone,), with_weights=True +) diff --git a/keras_cv/models/backbones/efficientnet_v1/efficientnet_v1_aliases.py b/keras_cv/models/backbones/efficientnet_v1/efficientnet_v1_aliases.py index 0bf86d6b9a..6752b656c1 100644 --- a/keras_cv/models/backbones/efficientnet_v1/efficientnet_v1_aliases.py +++ b/keras_cv/models/backbones/efficientnet_v1/efficientnet_v1_aliases.py @@ -112,6 +112,7 @@ def __new__( ) return EfficientNetV1Backbone.from_preset("efficientnetv1_b3", **kwargs) + @keras_cv_export("keras_cv.models.EfficientNetV1B4Backbone") class EfficientNetV1B4Backbone(EfficientNetV1Backbone): def __new__( @@ -131,6 +132,7 @@ def __new__( ) return EfficientNetV1Backbone.from_preset("efficientnetv1_b4", **kwargs) + @keras_cv_export("keras_cv.models.EfficientNetV1B5Backbone") class EfficientNetV1B5Backbone(EfficientNetV1Backbone): def __new__( diff --git a/keras_cv/models/backbones/efficientnet_v2/__init__.py b/keras_cv/models/backbones/efficientnet_v2/__init__.py index 5c7750d78f..ced94c1910 100644 --- a/keras_cv/models/backbones/efficientnet_v2/__init__.py +++ b/keras_cv/models/backbones/efficientnet_v2/__init__.py @@ -12,27 +12,57 @@ # See the License for the specific language governing permissions and # limitations under the License. +from keras_cv.models.backbones.efficientnet_v2.efficientnet_v2_aliases import ( + EfficientNetV2B0Backbone, +) +from keras_cv.models.backbones.efficientnet_v2.efficientnet_v2_aliases import ( + EfficientNetV2B1Backbone, +) +from keras_cv.models.backbones.efficientnet_v2.efficientnet_v2_aliases import ( + EfficientNetV2B2Backbone, +) +from keras_cv.models.backbones.efficientnet_v2.efficientnet_v2_aliases import ( + EfficientNetV2SBackbone, +) +from keras_cv.models.backbones.efficientnet_v2.efficientnet_v2_backbone import ( + EfficientNetV2Backbone, +) from keras_cv.models.backbones.efficientnet_v2.efficientnet_v2_backbone_presets import ( backbone_presets_no_weights, ) from keras_cv.models.backbones.efficientnet_v2.efficientnet_v2_backbone_presets import ( backbone_presets_with_weights, ) -from keras_cv.models.backbones.efficientnet_v2.efficientnet_v2_backbone import ( - EfficientNetV2Backbone, +from keras_cv.utils.preset_utils import register_preset +from keras_cv.utils.preset_utils import register_presets + +register_presets( + backbone_presets_no_weights, (EfficientNetV2Backbone,), with_weights=False ) -from keras_cv.models.backbones.efficientnet_v2.efficientnet_v2_aliases import ( - EfficientNetV2SBackbone, EfficientNetV2B0Backbone, EfficientNetV2B1Backbone, EfficientNetV2B2Backbone, +register_presets( + backbone_presets_with_weights, (EfficientNetV2Backbone,), with_weights=True +) +register_preset( + "efficientnetv2_s_imagenet", + backbone_presets_with_weights["efficientnetv2_s_imagenet"], + (EfficientNetV2SBackbone,), + with_weights=True, +) +register_preset( + "efficientnetv2_b0_imagenet", + backbone_presets_with_weights["efficientnetv2_b0_imagenet"], + (EfficientNetV2B0Backbone,), + with_weights=True, +) +register_preset( + "efficientnetv2_b1_imagenet", + backbone_presets_with_weights["efficientnetv2_b1_imagenet"], + (EfficientNetV2B1Backbone,), + with_weights=True, +) +register_preset( + "efficientnetv2_b2_imagenet", + backbone_presets_with_weights["efficientnetv2_b2_imagenet"], + (EfficientNetV2B2Backbone,), + with_weights=True, ) -from keras_cv.utils.preset_utils import register_presets, register_preset - -register_presets(backbone_presets_no_weights, (EfficientNetV2Backbone, ), with_weights=False) -register_presets(backbone_presets_with_weights, (EfficientNetV2Backbone, ), with_weights=True) -register_preset("efficientnetv2_s_imagenet", backbone_presets_with_weights["efficientnetv2_s_imagenet"], - (EfficientNetV2SBackbone,), with_weights=True) -register_preset("efficientnetv2_b0_imagenet", backbone_presets_with_weights["efficientnetv2_b0_imagenet"], - (EfficientNetV2B0Backbone,), with_weights=True) -register_preset("efficientnetv2_b1_imagenet", backbone_presets_with_weights["efficientnetv2_b1_imagenet"], - (EfficientNetV2B1Backbone,), with_weights=True) -register_preset("efficientnetv2_b2_imagenet", backbone_presets_with_weights["efficientnetv2_b2_imagenet"], - (EfficientNetV2B2Backbone,), with_weights=True) diff --git a/keras_cv/models/backbones/efficientnet_v2/efficientnet_v2_aliases.py b/keras_cv/models/backbones/efficientnet_v2/efficientnet_v2_aliases.py index 713c82d599..4e246676e1 100644 --- a/keras_cv/models/backbones/efficientnet_v2/efficientnet_v2_aliases.py +++ b/keras_cv/models/backbones/efficientnet_v2/efficientnet_v2_aliases.py @@ -91,6 +91,7 @@ def __new__( ) return EfficientNetV2Backbone.from_preset("efficientnetv2_l", **kwargs) + @keras_cv_export("keras_cv.models.EfficientNetV2B0Backbone") class EfficientNetV2B0Backbone(EfficientNetV2Backbone): def __new__( @@ -171,7 +172,6 @@ def __new__( return EfficientNetV2Backbone.from_preset("efficientnetv2_b3", **kwargs) - setattr( EfficientNetV2SBackbone, "__doc__", diff --git a/keras_cv/models/backbones/efficientnet_v2/efficientnet_v2_backbone.py b/keras_cv/models/backbones/efficientnet_v2/efficientnet_v2_backbone.py index 6cfe30809a..8d1c0cc5a6 100644 --- a/keras_cv/models/backbones/efficientnet_v2/efficientnet_v2_backbone.py +++ b/keras_cv/models/backbones/efficientnet_v2/efficientnet_v2_backbone.py @@ -20,6 +20,7 @@ from keras_cv.models import utils from keras_cv.models.backbones.backbone import Backbone + @keras_cv_export("keras_cv.models.EfficientNetV2Backbone") class EfficientNetV2Backbone(Backbone): """Instantiates the EfficientNetV2 architecture. diff --git a/keras_cv/models/backbones/mix_transformer/__init__.py b/keras_cv/models/backbones/mix_transformer/__init__.py index 3cc12a1763..8f77e19c79 100644 --- a/keras_cv/models/backbones/mix_transformer/__init__.py +++ b/keras_cv/models/backbones/mix_transformer/__init__.py @@ -12,21 +12,30 @@ # See the License for the specific language governing permissions and # limitations under the License. +from keras_cv.models.backbones.mix_transformer.mix_transformer_aliases import ( + MiTB0Backbone, +) +from keras_cv.models.backbones.mix_transformer.mix_transformer_backbone import ( + MiTBackbone, +) from keras_cv.models.backbones.mix_transformer.mix_transformer_backbone_presets import ( backbone_presets_no_weights, ) from keras_cv.models.backbones.mix_transformer.mix_transformer_backbone_presets import ( backbone_presets_with_weights, ) -from keras_cv.models.backbones.mix_transformer.mix_transformer_backbone import ( - MiTBackbone, +from keras_cv.utils.preset_utils import register_preset +from keras_cv.utils.preset_utils import register_presets + +register_presets( + backbone_presets_no_weights, (MiTBackbone,), with_weights=False ) -from keras_cv.models.backbones.mix_transformer.mix_transformer_aliases import ( - MiTB0Backbone, +register_presets( + backbone_presets_with_weights, (MiTBackbone,), with_weights=True +) +register_preset( + "mit_b0_imagenet", + backbone_presets_with_weights["mit_b0_imagenet"], + (MiTB0Backbone,), + with_weights=True, ) -from keras_cv.utils.preset_utils import register_presets, register_preset - -register_presets(backbone_presets_no_weights, (MiTBackbone, ), with_weights=False) -register_presets(backbone_presets_with_weights, (MiTBackbone, ), with_weights=True) -register_preset("mit_b0_imagenet", backbone_presets_with_weights["mit_b0_imagenet"], - (MiTB0Backbone,), with_weights=True) \ No newline at end of file diff --git a/keras_cv/models/backbones/mix_transformer/mix_transformer_aliases.py b/keras_cv/models/backbones/mix_transformer/mix_transformer_aliases.py index a1fb04a751..e704903635 100644 --- a/keras_cv/models/backbones/mix_transformer/mix_transformer_aliases.py +++ b/keras_cv/models/backbones/mix_transformer/mix_transformer_aliases.py @@ -61,7 +61,6 @@ def __new__( return MiTBackbone.from_preset("mit_b0", **kwargs) - @keras_cv_export("keras_cv.models.MiTB1Backbone") class MiTB1Backbone(MiTBackbone): def __new__( @@ -81,6 +80,7 @@ def __new__( ) return MiTBackbone.from_preset("mit_b1", **kwargs) + @keras_cv_export("keras_cv.models.MiTB2Backbone") class MiTB2Backbone(MiTBackbone): def __new__( @@ -101,7 +101,6 @@ def __new__( return MiTBackbone.from_preset("mit_b2", **kwargs) - @keras_cv_export("keras_cv.models.MiTB3Backbone") class MiTB3Backbone(MiTBackbone): def __new__( @@ -120,6 +119,8 @@ def __new__( } ) return MiTBackbone.from_preset("mit_b3", **kwargs) + + @keras_cv_export("keras_cv.models.MiTB4Backbone") class MiTB4Backbone(MiTBackbone): def __new__( diff --git a/keras_cv/models/backbones/mobilenet_v3/__init__.py b/keras_cv/models/backbones/mobilenet_v3/__init__.py index 7b5618046b..27a297c647 100644 --- a/keras_cv/models/backbones/mobilenet_v3/__init__.py +++ b/keras_cv/models/backbones/mobilenet_v3/__init__.py @@ -12,23 +12,39 @@ # See the License for the specific language governing permissions and # limitations under the License. +from keras_cv.models.backbones.mobilenet_v3.mobilenet_v3_aliases import ( + MobileNetV3LargeBackbone, +) +from keras_cv.models.backbones.mobilenet_v3.mobilenet_v3_aliases import ( + MobileNetV3SmallBackbone, +) +from keras_cv.models.backbones.mobilenet_v3.mobilenet_v3_backbone import ( + MobileNetV3Backbone, +) from keras_cv.models.backbones.mobilenet_v3.mobilenet_v3_backbone_presets import ( backbone_presets_no_weights, ) from keras_cv.models.backbones.mobilenet_v3.mobilenet_v3_backbone_presets import ( backbone_presets_with_weights, ) -from keras_cv.models.backbones.mobilenet_v3.mobilenet_v3_backbone import ( - MobileNetV3Backbone, +from keras_cv.utils.preset_utils import register_preset +from keras_cv.utils.preset_utils import register_presets + +register_presets( + backbone_presets_no_weights, (MobileNetV3Backbone,), with_weights=False ) -from keras_cv.models.backbones.mobilenet_v3.mobilenet_v3_aliases import ( - MobileNetV3SmallBackbone, MobileNetV3LargeBackbone +register_presets( + backbone_presets_with_weights, (MobileNetV3Backbone,), with_weights=True +) +register_preset( + "mobilenet_v3_small_imagenet", + backbone_presets_with_weights["mobilenet_v3_small_imagenet"], + (MobileNetV3SmallBackbone,), + with_weights=True, +) +register_preset( + "mobilenet_v3_large_imagenet", + backbone_presets_with_weights["mobilenet_v3_large_imagenet"], + (MobileNetV3LargeBackbone,), + with_weights=True, ) -from keras_cv.utils.preset_utils import register_presets, register_preset - -register_presets(backbone_presets_no_weights, (MobileNetV3Backbone, ), with_weights=False) -register_presets(backbone_presets_with_weights, (MobileNetV3Backbone, ), with_weights=True) -register_preset("mobilenet_v3_small_imagenet", backbone_presets_with_weights["mobilenet_v3_small_imagenet"], - (MobileNetV3SmallBackbone, ), with_weights=True) -register_preset("mobilenet_v3_large_imagenet", backbone_presets_with_weights["mobilenet_v3_large_imagenet"], - (MobileNetV3LargeBackbone, ), with_weights=True) \ No newline at end of file diff --git a/keras_cv/models/backbones/mobilenet_v3/mobilenet_v3_aliases.py b/keras_cv/models/backbones/mobilenet_v3/mobilenet_v3_aliases.py index f28ea67d5e..319071e524 100644 --- a/keras_cv/models/backbones/mobilenet_v3/mobilenet_v3_aliases.py +++ b/keras_cv/models/backbones/mobilenet_v3/mobilenet_v3_aliases.py @@ -17,7 +17,6 @@ MobileNetV3Backbone, ) - ALIAS_DOCSTRING = """MobileNetV3Backbone model with {num_layers} layers. References: diff --git a/keras_cv/models/backbones/resnet_v1/__init__.py b/keras_cv/models/backbones/resnet_v1/__init__.py index 6aa3951fba..80145a8ec3 100644 --- a/keras_cv/models/backbones/resnet_v1/__init__.py +++ b/keras_cv/models/backbones/resnet_v1/__init__.py @@ -12,21 +12,30 @@ # See the License for the specific language governing permissions and # limitations under the License. +from keras_cv.models.backbones.resnet_v1.resnet_v1_aliases import ( + ResNet50Backbone, +) +from keras_cv.models.backbones.resnet_v1.resnet_v1_backbone import ( + ResNetBackbone, +) from keras_cv.models.backbones.resnet_v1.resnet_v1_backbone_presets import ( backbone_presets_no_weights, ) from keras_cv.models.backbones.resnet_v1.resnet_v1_backbone_presets import ( backbone_presets_with_weights, ) -from keras_cv.models.backbones.resnet_v1.resnet_v1_backbone import ( - ResNetBackbone, +from keras_cv.utils.preset_utils import register_preset +from keras_cv.utils.preset_utils import register_presets + +register_presets( + backbone_presets_no_weights, (ResNetBackbone,), with_weights=False ) -from keras_cv.models.backbones.resnet_v1.resnet_v1_aliases import ( - ResNet50Backbone, +register_presets( + backbone_presets_with_weights, (ResNetBackbone,), with_weights=True +) +register_preset( + "resnet50_imagenet", + backbone_presets_with_weights["resnet50_imagenet"], + (ResNet50Backbone,), + with_weights=True, ) -from keras_cv.utils.preset_utils import register_presets, register_preset - -register_presets(backbone_presets_no_weights, (ResNetBackbone, ), with_weights=False) -register_presets(backbone_presets_with_weights, (ResNetBackbone, ), with_weights=True) -register_preset("resnet50_imagenet", backbone_presets_with_weights["resnet50_imagenet"], - (ResNet50Backbone,), with_weights=True) diff --git a/keras_cv/models/backbones/resnet_v1/resnet_v1_aliases.py b/keras_cv/models/backbones/resnet_v1/resnet_v1_aliases.py index 70c54c0ac7..f1572af996 100644 --- a/keras_cv/models/backbones/resnet_v1/resnet_v1_aliases.py +++ b/keras_cv/models/backbones/resnet_v1/resnet_v1_aliases.py @@ -110,7 +110,6 @@ def __new__( return ResNetBackbone.from_preset("resnet50", **kwargs) - @keras_cv_export("keras_cv.models.ResNet101Backbone") class ResNet101Backbone(ResNetBackbone): def __new__( @@ -151,7 +150,6 @@ def __new__( return ResNetBackbone.from_preset("resnet152", **kwargs) - setattr(ResNet18Backbone, "__doc__", ALIAS_DOCSTRING.format(num_layers=18)) setattr(ResNet34Backbone, "__doc__", ALIAS_DOCSTRING.format(num_layers=34)) setattr(ResNet50Backbone, "__doc__", ALIAS_DOCSTRING.format(num_layers=50)) diff --git a/keras_cv/models/backbones/resnet_v2/__init__.py b/keras_cv/models/backbones/resnet_v2/__init__.py index d337558331..1e81797931 100644 --- a/keras_cv/models/backbones/resnet_v2/__init__.py +++ b/keras_cv/models/backbones/resnet_v2/__init__.py @@ -12,21 +12,30 @@ # See the License for the specific language governing permissions and # limitations under the License. +from keras_cv.models.backbones.resnet_v2.resnet_v2_aliases import ( + ResNet50V2Backbone, +) +from keras_cv.models.backbones.resnet_v2.resnet_v2_backbone import ( + ResNetV2Backbone, +) from keras_cv.models.backbones.resnet_v2.resnet_v2_backbone_presets import ( backbone_presets_no_weights, ) from keras_cv.models.backbones.resnet_v2.resnet_v2_backbone_presets import ( backbone_presets_with_weights, ) -from keras_cv.models.backbones.resnet_v2.resnet_v2_backbone import ( - ResNetV2Backbone, +from keras_cv.utils.preset_utils import register_preset +from keras_cv.utils.preset_utils import register_presets + +register_presets( + backbone_presets_no_weights, (ResNetV2Backbone,), with_weights=False ) -from keras_cv.models.backbones.resnet_v2.resnet_v2_aliases import ( - ResNet50V2Backbone, +register_presets( + backbone_presets_with_weights, (ResNetV2Backbone,), with_weights=True +) +register_preset( + "resnet50_v2_imagenet", + backbone_presets_with_weights["resnet50_v2_imagenet"], + (ResNet50V2Backbone,), + with_weights=True, ) -from keras_cv.utils.preset_utils import register_presets, register_preset - -register_presets(backbone_presets_no_weights, (ResNetV2Backbone, ), with_weights=False) -register_presets(backbone_presets_with_weights, (ResNetV2Backbone, ), with_weights=True) -register_preset("resnet50_v2_imagenet", backbone_presets_with_weights["resnet50_v2_imagenet"], - (ResNet50V2Backbone,), with_weights=True) diff --git a/keras_cv/models/backbones/video_swin/__init__.py b/keras_cv/models/backbones/video_swin/__init__.py index 1f40fc3144..472a1bdbd8 100644 --- a/keras_cv/models/backbones/video_swin/__init__.py +++ b/keras_cv/models/backbones/video_swin/__init__.py @@ -12,25 +12,48 @@ # See the License for the specific language governing permissions and # limitations under the License. +from keras_cv.models.backbones.video_swin.video_swin_aliases import ( + VideoSwinBBackbone, +) +from keras_cv.models.backbones.video_swin.video_swin_aliases import ( + VideoSwinSBackbone, +) +from keras_cv.models.backbones.video_swin.video_swin_aliases import ( + VideoSwinTBackbone, +) +from keras_cv.models.backbones.video_swin.video_swin_backbone import ( + VideoSwinBackbone, +) from keras_cv.models.backbones.video_swin.video_swin_backbone_presets import ( backbone_presets_no_weights, ) from keras_cv.models.backbones.video_swin.video_swin_backbone_presets import ( backbone_presets_with_weights, ) -from keras_cv.models.backbones.video_swin.video_swin_backbone import ( - VideoSwinBackbone, +from keras_cv.utils.preset_utils import register_preset +from keras_cv.utils.preset_utils import register_presets + +register_presets( + backbone_presets_no_weights, (VideoSwinBackbone,), with_weights=False ) -from keras_cv.models.backbones.video_swin.video_swin_aliases import ( - VideoSwinTBackbone, VideoSwinSBackbone, VideoSwinBBackbone, +register_presets( + backbone_presets_with_weights, (VideoSwinBackbone,), with_weights=True +) +register_preset( + "videoswin_tiny_kinetics400", + backbone_presets_with_weights["videoswin_tiny_kinetics400"], + (VideoSwinTBackbone,), + with_weights=True, +) +register_preset( + "videoswin_small_kinetics400", + backbone_presets_with_weights["videoswin_small_kinetics400"], + (VideoSwinSBackbone,), + with_weights=True, +) +register_preset( + "videoswin_base_kinetics400", + backbone_presets_with_weights["videoswin_base_kinetics400"], + (VideoSwinBBackbone,), + with_weights=True, ) -from keras_cv.utils.preset_utils import register_presets, register_preset - -register_presets(backbone_presets_no_weights, (VideoSwinBackbone, ), with_weights=False) -register_presets(backbone_presets_with_weights, (VideoSwinBackbone, ), with_weights=True) -register_preset("videoswin_tiny_kinetics400", backbone_presets_with_weights["videoswin_tiny_kinetics400"], - (VideoSwinTBackbone,), with_weights=True) -register_preset("videoswin_small_kinetics400", backbone_presets_with_weights["videoswin_small_kinetics400"], - (VideoSwinSBackbone,), with_weights=True) -register_preset("videoswin_base_kinetics400", backbone_presets_with_weights["videoswin_base_kinetics400"], - (VideoSwinBBackbone,), with_weights=True) \ No newline at end of file diff --git a/keras_cv/models/backbones/video_swin/video_swin_aliases.py b/keras_cv/models/backbones/video_swin/video_swin_aliases.py index 707b57e493..3a4b192f76 100644 --- a/keras_cv/models/backbones/video_swin/video_swin_aliases.py +++ b/keras_cv/models/backbones/video_swin/video_swin_aliases.py @@ -102,7 +102,6 @@ def __new__( return VideoSwinBackbone.from_preset("videoswin_base", **kwargs) - setattr(VideoSwinTBackbone, "__doc__", ALIAS_DOCSTRING.format(size="T")) setattr(VideoSwinSBackbone, "__doc__", ALIAS_DOCSTRING.format(size="S")) setattr(VideoSwinBBackbone, "__doc__", ALIAS_DOCSTRING.format(size="B")) diff --git a/keras_cv/models/backbones/vit_det/__init__.py b/keras_cv/models/backbones/vit_det/__init__.py index 9d0f010897..e003cbf8de 100644 --- a/keras_cv/models/backbones/vit_det/__init__.py +++ b/keras_cv/models/backbones/vit_det/__init__.py @@ -12,25 +12,40 @@ # See the License for the specific language governing permissions and # limitations under the License. +from keras_cv.models.backbones.vit_det.vit_det_aliases import ViTDetBBackbone +from keras_cv.models.backbones.vit_det.vit_det_aliases import ViTDetHBackbone +from keras_cv.models.backbones.vit_det.vit_det_aliases import ViTDetLBackbone +from keras_cv.models.backbones.vit_det.vit_det_backbone import ViTDetBackbone from keras_cv.models.backbones.vit_det.vit_det_backbone_presets import ( backbone_presets_no_weights, ) from keras_cv.models.backbones.vit_det.vit_det_backbone_presets import ( backbone_presets_with_weights, ) -from keras_cv.models.backbones.vit_det.vit_det_backbone import ( - ViTDetBackbone, +from keras_cv.utils.preset_utils import register_preset +from keras_cv.utils.preset_utils import register_presets + +register_presets( + backbone_presets_no_weights, (ViTDetBackbone,), with_weights=False ) -from keras_cv.models.backbones.vit_det.vit_det_aliases import ( - ViTDetBBackbone, ViTDetLBackbone, ViTDetHBackbone, +register_presets( + backbone_presets_with_weights, (ViTDetBackbone,), with_weights=True +) +register_preset( + "vitdet_base_sa1b", + backbone_presets_with_weights["vitdet_base_sa1b"], + (ViTDetBBackbone,), + with_weights=True, +) +register_preset( + "vitdet_large_sa1b", + backbone_presets_with_weights["vitdet_large_sa1b"], + (ViTDetLBackbone,), + with_weights=True, +) +register_preset( + "vitdet_huge_sa1b", + backbone_presets_with_weights["vitdet_huge_sa1b"], + (ViTDetHBackbone,), + with_weights=True, ) -from keras_cv.utils.preset_utils import register_presets, register_preset - -register_presets(backbone_presets_no_weights, (ViTDetBackbone, ), with_weights=False) -register_presets(backbone_presets_with_weights, (ViTDetBackbone, ), with_weights=True) -register_preset("vitdet_base_sa1b", backbone_presets_with_weights["vitdet_base_sa1b"], - (ViTDetBBackbone,), with_weights=True) -register_preset("vitdet_large_sa1b", backbone_presets_with_weights["vitdet_large_sa1b"], - (ViTDetLBackbone,), with_weights=True) -register_preset("vitdet_huge_sa1b", backbone_presets_with_weights["vitdet_huge_sa1b"], - (ViTDetHBackbone,), with_weights=True) diff --git a/keras_cv/models/object_detection/retinanet/retinanet_test.py b/keras_cv/models/object_detection/retinanet/retinanet_test.py index b939f2e481..b45b91028d 100644 --- a/keras_cv/models/object_detection/retinanet/retinanet_test.py +++ b/keras_cv/models/object_detection/retinanet/retinanet_test.py @@ -280,7 +280,7 @@ def data_generator(): bounding_box_format="xyxy", backbone=keras_cv.models.ResNet50Backbone.from_preset( "resnet50_imagenet", - #load_weights=False, + # load_weights=False, ), ) diff --git a/keras_cv/models/object_detection/yolo_v8/__init__.py b/keras_cv/models/object_detection/yolo_v8/__init__.py index a95055f2ff..587b660acf 100644 --- a/keras_cv/models/object_detection/yolo_v8/__init__.py +++ b/keras_cv/models/object_detection/yolo_v8/__init__.py @@ -11,8 +11,8 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -from keras_cv.models.object_detection.yolo_v8.yolo_v8_label_encoder import ( - YOLOV8LabelEncoder, +from keras_cv.models.object_detection.yolo_v8.yolo_v8_backbone import ( + YOLOV8Backbone, ) from keras_cv.models.object_detection.yolo_v8.yolo_v8_backbone_presets import ( backbone_presets_no_weights, @@ -20,10 +20,14 @@ from keras_cv.models.object_detection.yolo_v8.yolo_v8_backbone_presets import ( backbone_presets_with_weights, ) -from keras_cv.models.object_detection.yolo_v8.yolo_v8_backbone import ( - YOLOV8Backbone, +from keras_cv.models.object_detection.yolo_v8.yolo_v8_label_encoder import ( + YOLOV8LabelEncoder, ) from keras_cv.utils.preset_utils import register_presets -register_presets(backbone_presets_no_weights, (YOLOV8Backbone, ), with_weights=False) -register_presets(backbone_presets_with_weights, (YOLOV8Backbone, ), with_weights=True) +register_presets( + backbone_presets_no_weights, (YOLOV8Backbone,), with_weights=False +) +register_presets( + backbone_presets_with_weights, (YOLOV8Backbone,), with_weights=True +) diff --git a/keras_cv/models/object_detection/yolo_v8/yolo_v8_backbone.py b/keras_cv/models/object_detection/yolo_v8/yolo_v8_backbone.py index dfd0cfb1e8..2c9ee7c974 100644 --- a/keras_cv/models/object_detection/yolo_v8/yolo_v8_backbone.py +++ b/keras_cv/models/object_detection/yolo_v8/yolo_v8_backbone.py @@ -194,4 +194,3 @@ def get_config(self): } ) return config - diff --git a/keras_cv/models/object_detection_3d/__init__.py b/keras_cv/models/object_detection_3d/__init__.py index 588dabe0e3..508f629870 100644 --- a/keras_cv/models/object_detection_3d/__init__.py +++ b/keras_cv/models/object_detection_3d/__init__.py @@ -25,5 +25,9 @@ ) from keras_cv.utils.preset_utils import register_presets -register_presets(backbone_presets_no_weights, (CenterPillarBackbone, ), with_weights=False) -register_presets(backbone_presets_with_weights, (CenterPillarBackbone, ), with_weights=True) +register_presets( + backbone_presets_no_weights, (CenterPillarBackbone,), with_weights=False +) +register_presets( + backbone_presets_with_weights, (CenterPillarBackbone,), with_weights=True +) diff --git a/keras_cv/models/object_detection_3d/center_pillar_backbone_presets.py b/keras_cv/models/object_detection_3d/center_pillar_backbone_presets.py index 2ef5f65bda..d50d151a81 100644 --- a/keras_cv/models/object_detection_3d/center_pillar_backbone_presets.py +++ b/keras_cv/models/object_detection_3d/center_pillar_backbone_presets.py @@ -25,9 +25,9 @@ }, } -backbone_presets_with_weights = {} +backbone_presets_with_weights = {} backbone_presets = { **backbone_presets_no_weights, **backbone_presets_with_weights, -} \ No newline at end of file +} diff --git a/keras_cv/utils/preset_utils.py b/keras_cv/utils/preset_utils.py index 53df484f41..d3ace14009 100644 --- a/keras_cv/utils/preset_utils.py +++ b/keras_cv/utils/preset_utils.py @@ -197,6 +197,7 @@ def check_config_class( ) return keras.saving.get_registered_object(config["registered_name"]) + def check_preset_class( preset, classes, @@ -229,6 +230,7 @@ def check_preset_class( ) return cls + def legacy_load_weights(layer, weights_path): # Hacky fix for TensorFlow 2.13 and 2.14 when loading a `.weights.h5` file. # We find the `Functional` class, and temporarily remove the From 86e14c97685af1bda8a47714f0855035671e4548 Mon Sep 17 00:00:00 2001 From: Smit Lunagariya Date: Tue, 16 Apr 2024 08:55:46 +0000 Subject: [PATCH 3/3] ignore line length warnings --- keras_cv/models/backbones/efficientnet_lite/__init__.py | 6 +++--- keras_cv/models/backbones/efficientnet_v1/__init__.py | 4 ++-- keras_cv/models/backbones/efficientnet_v2/__init__.py | 4 ++-- keras_cv/models/backbones/mix_transformer/__init__.py | 4 ++-- keras_cv/models/backbones/mobilenet_v3/__init__.py | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/keras_cv/models/backbones/efficientnet_lite/__init__.py b/keras_cv/models/backbones/efficientnet_lite/__init__.py index 0950d60130..c0c48953d9 100644 --- a/keras_cv/models/backbones/efficientnet_lite/__init__.py +++ b/keras_cv/models/backbones/efficientnet_lite/__init__.py @@ -12,13 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -from keras_cv.models.backbones.efficientnet_lite.efficientnet_lite_backbone import ( +from keras_cv.models.backbones.efficientnet_lite.efficientnet_lite_backbone import ( # noqa: E501 EfficientNetLiteBackbone, ) -from keras_cv.models.backbones.efficientnet_lite.efficientnet_lite_backbone_presets import ( +from keras_cv.models.backbones.efficientnet_lite.efficientnet_lite_backbone_presets import ( # noqa: E501 backbone_presets_no_weights, ) -from keras_cv.models.backbones.efficientnet_lite.efficientnet_lite_backbone_presets import ( +from keras_cv.models.backbones.efficientnet_lite.efficientnet_lite_backbone_presets import ( # noqa: E501 backbone_presets_with_weights, ) from keras_cv.utils.preset_utils import register_presets diff --git a/keras_cv/models/backbones/efficientnet_v1/__init__.py b/keras_cv/models/backbones/efficientnet_v1/__init__.py index 26faa501f5..725aa6096e 100644 --- a/keras_cv/models/backbones/efficientnet_v1/__init__.py +++ b/keras_cv/models/backbones/efficientnet_v1/__init__.py @@ -15,10 +15,10 @@ from keras_cv.models.backbones.efficientnet_v1.efficientnet_v1_backbone import ( EfficientNetV1Backbone, ) -from keras_cv.models.backbones.efficientnet_v1.efficientnet_v1_backbone_presets import ( +from keras_cv.models.backbones.efficientnet_v1.efficientnet_v1_backbone_presets import ( # noqa: E501 backbone_presets_no_weights, ) -from keras_cv.models.backbones.efficientnet_v1.efficientnet_v1_backbone_presets import ( +from keras_cv.models.backbones.efficientnet_v1.efficientnet_v1_backbone_presets import ( # noqa: E501 backbone_presets_with_weights, ) from keras_cv.utils.preset_utils import register_presets diff --git a/keras_cv/models/backbones/efficientnet_v2/__init__.py b/keras_cv/models/backbones/efficientnet_v2/__init__.py index ced94c1910..66792b1503 100644 --- a/keras_cv/models/backbones/efficientnet_v2/__init__.py +++ b/keras_cv/models/backbones/efficientnet_v2/__init__.py @@ -27,10 +27,10 @@ from keras_cv.models.backbones.efficientnet_v2.efficientnet_v2_backbone import ( EfficientNetV2Backbone, ) -from keras_cv.models.backbones.efficientnet_v2.efficientnet_v2_backbone_presets import ( +from keras_cv.models.backbones.efficientnet_v2.efficientnet_v2_backbone_presets import ( # noqa: E501 backbone_presets_no_weights, ) -from keras_cv.models.backbones.efficientnet_v2.efficientnet_v2_backbone_presets import ( +from keras_cv.models.backbones.efficientnet_v2.efficientnet_v2_backbone_presets import ( # noqa: E501 backbone_presets_with_weights, ) from keras_cv.utils.preset_utils import register_preset diff --git a/keras_cv/models/backbones/mix_transformer/__init__.py b/keras_cv/models/backbones/mix_transformer/__init__.py index 8f77e19c79..5fc2016898 100644 --- a/keras_cv/models/backbones/mix_transformer/__init__.py +++ b/keras_cv/models/backbones/mix_transformer/__init__.py @@ -18,10 +18,10 @@ from keras_cv.models.backbones.mix_transformer.mix_transformer_backbone import ( MiTBackbone, ) -from keras_cv.models.backbones.mix_transformer.mix_transformer_backbone_presets import ( +from keras_cv.models.backbones.mix_transformer.mix_transformer_backbone_presets import ( # noqa: E501 backbone_presets_no_weights, ) -from keras_cv.models.backbones.mix_transformer.mix_transformer_backbone_presets import ( +from keras_cv.models.backbones.mix_transformer.mix_transformer_backbone_presets import ( # noqa: E501 backbone_presets_with_weights, ) from keras_cv.utils.preset_utils import register_preset diff --git a/keras_cv/models/backbones/mobilenet_v3/__init__.py b/keras_cv/models/backbones/mobilenet_v3/__init__.py index 27a297c647..63620c724e 100644 --- a/keras_cv/models/backbones/mobilenet_v3/__init__.py +++ b/keras_cv/models/backbones/mobilenet_v3/__init__.py @@ -21,10 +21,10 @@ from keras_cv.models.backbones.mobilenet_v3.mobilenet_v3_backbone import ( MobileNetV3Backbone, ) -from keras_cv.models.backbones.mobilenet_v3.mobilenet_v3_backbone_presets import ( +from keras_cv.models.backbones.mobilenet_v3.mobilenet_v3_backbone_presets import ( # noqa: E501 backbone_presets_no_weights, ) -from keras_cv.models.backbones.mobilenet_v3.mobilenet_v3_backbone_presets import ( +from keras_cv.models.backbones.mobilenet_v3.mobilenet_v3_backbone_presets import ( # noqa: E501 backbone_presets_with_weights, ) from keras_cv.utils.preset_utils import register_preset