Skip to content

Commit

Permalink
Export Model APIs (#2389)
Browse files Browse the repository at this point in the history
* Fix backbone export under models

* Namex for API generation

* Use Namex API generator

* Namex for API generation

* Export API namex

* Fix typo and export APIs
  • Loading branch information
sachinprasadhs authored Mar 18, 2024
1 parent 707132b commit fb05c82
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 6 deletions.
10 changes: 5 additions & 5 deletions keras_cv/models/backbones/csp_darknet/csp_darknet_aliases.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
""" # noqa: E501


@keras_cv_export("keras_cv.losses.CSPDarkNetTinyBackbone")
@keras_cv_export("keras_cv.models.CSPDarkNetTinyBackbone")
class CSPDarkNetTinyBackbone(CSPDarkNetBackbone):
def __new__(
cls,
Expand Down Expand Up @@ -87,7 +87,7 @@ def presets_with_weights(cls):
return cls.presets


@keras_cv_export("keras_cv.losses.CSPDarkNetSBackbone")
@keras_cv_export("keras_cv.models.CSPDarkNetSBackbone")
class CSPDarkNetSBackbone(CSPDarkNetBackbone):
def __new__(
cls,
Expand Down Expand Up @@ -118,7 +118,7 @@ def presets_with_weights(cls):
return {}


@keras_cv_export("keras_cv.losses.CSPDarkNetMBackbone")
@keras_cv_export("keras_cv.models.CSPDarkNetMBackbone")
class CSPDarkNetMBackbone(CSPDarkNetBackbone):
def __new__(
cls,
Expand Down Expand Up @@ -149,7 +149,7 @@ def presets_with_weights(cls):
return {}


@keras_cv_export("keras_cv.losses.CSPDarkNetLBackbone")
@keras_cv_export("keras_cv.models.CSPDarkNetLBackbone")
class CSPDarkNetLBackbone(CSPDarkNetBackbone):
def __new__(
cls,
Expand Down Expand Up @@ -184,7 +184,7 @@ def presets_with_weights(cls):
return cls.presets


@keras_cv_export("keras_cv.losses.CSPDarkNetXLBackbone")
@keras_cv_export("keras_cv.models.CSPDarkNetXLBackbone")
class CSPDarkNetXLBackbone(CSPDarkNetBackbone):
def __new__(
cls,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from keras_cv.api_export import keras_cv_export
from keras_cv.models.backbones.efficientnet_lite.efficientnet_lite_backbone import ( # noqa: E501
EfficientNetLiteBackbone,
)
Expand Down Expand Up @@ -41,6 +42,7 @@
""" # noqa: E501


@keras_cv_export("keras_cv.models.EfficientNetLiteB0Backbone")
class EfficientNetLiteB0Backbone(EfficientNetLiteBackbone):
def __new__(
cls,
Expand Down Expand Up @@ -73,6 +75,7 @@ def presets_with_weights(cls):
return {}


@keras_cv_export("keras_cv.models.EfficientNetLiteB1Backbone")
class EfficientNetLiteB1Backbone(EfficientNetLiteBackbone):
def __new__(
cls,
Expand Down Expand Up @@ -105,6 +108,7 @@ def presets_with_weights(cls):
return {}


@keras_cv_export("keras_cv.models.EfficientNetLiteB2Backbone")
class EfficientNetLiteB2Backbone(EfficientNetLiteBackbone):
def __new__(
cls,
Expand Down Expand Up @@ -137,6 +141,7 @@ def presets_with_weights(cls):
return {}


@keras_cv_export("keras_cv.models.EfficientNetLiteB3Backbone")
class EfficientNetLiteB3Backbone(EfficientNetLiteBackbone):
def __new__(
cls,
Expand Down Expand Up @@ -169,6 +174,7 @@ def presets_with_weights(cls):
return {}


@keras_cv_export("keras_cv.models.EfficientNetLiteB4Backbone")
class EfficientNetLiteB4Backbone(EfficientNetLiteBackbone):
def __new__(
cls,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
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
Expand All @@ -35,6 +36,7 @@
BN_AXIS = 3


@keras_cv_export("keras_cv.models.EfficientNetLiteBackbone")
@keras.saving.register_keras_serializable(package="keras_cv.models")
class EfficientNetLiteBackbone(Backbone):
"""Instantiates the EfficientNetLite architecture using given scaling
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from keras_cv.api_export import keras_cv_export
from keras_cv.models.backbones.efficientnet_v1.efficientnet_v1_backbone import (
EfficientNetV1Backbone,
)
Expand All @@ -33,6 +34,7 @@
""" # noqa: E501


@keras_cv_export("keras_cv.models.EfficientNetV1B0Backbone")
class EfficientNetV1B0Backbone(EfficientNetV1Backbone):
def __new__(
cls,
Expand Down Expand Up @@ -63,6 +65,7 @@ def presets_with_weights(cls):
return {}


@keras_cv_export("keras_cv.models.EfficientNetV1B1Backbone")
class EfficientNetV1B1Backbone(EfficientNetV1Backbone):
def __new__(
cls,
Expand Down Expand Up @@ -93,6 +96,7 @@ def presets_with_weights(cls):
return {}


@keras_cv_export("keras_cv.models.EfficientNetV1B2Backbone")
class EfficientNetV1B2Backbone(EfficientNetV1Backbone):
def __new__(
cls,
Expand Down Expand Up @@ -123,6 +127,7 @@ def presets_with_weights(cls):
return {}


@keras_cv_export("keras_cv.models.EfficientNetV1B3Backbone")
class EfficientNetV1B3Backbone(EfficientNetV1Backbone):
def __new__(
cls,
Expand Down Expand Up @@ -153,6 +158,7 @@ def presets_with_weights(cls):
return {}


@keras_cv_export("keras_cv.models.EfficientNetV1B4Backbone")
class EfficientNetV1B4Backbone(EfficientNetV1Backbone):
def __new__(
cls,
Expand Down Expand Up @@ -183,6 +189,7 @@ def presets_with_weights(cls):
return {}


@keras_cv_export("keras_cv.models.EfficientNetV1B5Backbone")
class EfficientNetV1B5Backbone(EfficientNetV1Backbone):
def __new__(
cls,
Expand Down Expand Up @@ -213,6 +220,7 @@ def presets_with_weights(cls):
return {}


@keras_cv_export("keras_cv.models.EfficientNetV1B6Backbone")
class EfficientNetV1B6Backbone(EfficientNetV1Backbone):
def __new__(
cls,
Expand Down Expand Up @@ -243,6 +251,7 @@ def presets_with_weights(cls):
return {}


@keras_cv_export("keras_cv.models.EfficientNetV1B7Backbone")
class EfficientNetV1B7Backbone(EfficientNetV1Backbone):
def __new__(
cls,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
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
Expand All @@ -23,6 +24,7 @@
from keras_cv.utils.python_utils import classproperty


@keras_cv_export("keras_cv.models.EfficientNetV1Backbone")
@keras.saving.register_keras_serializable(package="keras_cv.models")
class EfficientNetV1Backbone(Backbone):
"""Instantiates the EfficientNetV1 architecture.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import copy

from keras_cv.api_export import keras_cv_export
from keras_cv.models.backbones.mix_transformer.mix_transformer_backbone import (
MiTBackbone,
)
Expand Down Expand Up @@ -46,6 +47,7 @@
""" # noqa: E501


@keras_cv_export("keras_cv.models.MiTB0Backbone")
class MiTB0Backbone(MiTBackbone):
def __new__(
cls,
Expand Down Expand Up @@ -80,6 +82,7 @@ def presets_with_weights(cls):
return cls.presets


@keras_cv_export("keras_cv.models.MiTB1Backbone")
class MiTB1Backbone(MiTBackbone):
def __new__(
cls,
Expand Down Expand Up @@ -109,6 +112,7 @@ def presets_with_weights(cls):
return {}


@keras_cv_export("keras_cv.models.MiTB2Backbone")
class MiTB2Backbone(MiTBackbone):
def __new__(
cls,
Expand Down Expand Up @@ -138,6 +142,7 @@ def presets_with_weights(cls):
return {}


@keras_cv_export("keras_cv.models.MiTB3Backbone")
class MiTB3Backbone(MiTBackbone):
def __new__(
cls,
Expand Down Expand Up @@ -167,6 +172,7 @@ def presets_with_weights(cls):
return {}


@keras_cv_export("keras_cv.models.MiTB4Backbone")
class MiTB4Backbone(MiTBackbone):
def __new__(
cls,
Expand Down Expand Up @@ -196,6 +202,7 @@ def presets_with_weights(cls):
return {}


@keras_cv_export("keras_cv.models.MiTB5Backbone")
class MiTB5Backbone(MiTBackbone):
def __new__(
cls,
Expand Down
2 changes: 2 additions & 0 deletions keras_cv/models/backbones/vgg16/vgg16_backbone.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@

from keras import layers

from keras_cv.api_export import keras_cv_export
from keras_cv.models import utils
from keras_cv.models.backbones.backbone import Backbone


@keras_cv_export("keras_cv.models.VGG16Backbone")
class VGG16Backbone(Backbone):
"""
Reference:
Expand Down
4 changes: 4 additions & 0 deletions keras_cv/models/backbones/vit_det/vit_det_aliases.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import copy

from keras_cv.api_export import keras_cv_export
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,
Expand Down Expand Up @@ -41,6 +42,7 @@
""" # noqa: E501


@keras_cv_export("keras_cv.models.ViTDetBBackbone")
class ViTDetBBackbone(ViTDetBackbone):
def __new__(
cls,
Expand All @@ -64,6 +66,7 @@ def presets_with_weights(cls):
return cls.presets


@keras_cv_export("keras_cv.models.ViTDetLBackbone")
class ViTDetLBackbone(ViTDetBackbone):
def __new__(
cls,
Expand All @@ -87,6 +90,7 @@ def presets_with_weights(cls):
return cls.presets


@keras_cv_export("keras_cv.models.ViTDetHBackbone")
class ViTDetHBackbone(ViTDetBackbone):
def __new__(
cls,
Expand Down
5 changes: 5 additions & 0 deletions keras_cv/models/feature_extractor/clip/clip_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.
import numpy as np

from keras_cv.api_export import keras_cv_export
from keras_cv.backend import keras
from keras_cv.backend import ops

Expand All @@ -31,6 +32,7 @@ def get_initializer(initializer_range=0.02):
return keras.initializers.TruncatedNormal(stddev=initializer_range)


@keras_cv_export("keras_cv.models.feature_extractor.QuickGELU")
class QuickGELU(keras.layers.Layer):
def __init__(self, **kwargs):
super().__init__(**kwargs)
Expand All @@ -39,6 +41,7 @@ def call(self, x):
return x * ops.sigmoid(1.702 * x)


@keras_cv_export("keras_cv.models.feature_extractor.ResidualAttention")
class ResidualAttention(keras.layers.Layer):
def __init__(
self,
Expand Down Expand Up @@ -136,6 +139,7 @@ def get_config(self):
return config


@keras_cv_export("keras_cv.models.feature_extractor.CLIPEncoder")
class CLIPEncoder(keras.layers.Layer):
def __init__(self, width, num_layers, heads, **kwargs):
super().__init__(**kwargs)
Expand Down Expand Up @@ -185,6 +189,7 @@ def get_config(self):
return config


@keras_cv_export("keras_cv.models.feature_extractor.CLIPAttention")
class CLIPAttention(keras.layers.Layer):
"""
Adapted from https://github.com/huggingface/transformers/blob/main/src/transformers/models/clip/modeling_clip.py # noqa: E501
Expand Down
3 changes: 3 additions & 0 deletions keras_cv/models/feature_extractor/clip/clip_image_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.

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.feature_extractor.clip.clip_encoder import CLIPEncoder
from keras_cv.models.feature_extractor.clip.clip_encoder import get_initializer


@keras_cv_export("keras_cv.models.feature_extractor.CLIPPatchingAndEmbedding")
class CLIPPatchingAndEmbedding(keras.layers.Layer):
def __init__(
self, width, patch_size, input_resolution, output_dim, **kwargs
Expand Down Expand Up @@ -95,6 +97,7 @@ def get_config(self):
return config


@keras_cv_export("keras_cv.models.feature_extractor.CLIPImageEncoder")
class CLIPImageEncoder(keras.Model):
def __init__(
self,
Expand Down
2 changes: 1 addition & 1 deletion keras_cv/models/feature_extractor/clip/clip_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from keras_cv.models.feature_extractor.clip.clip_tokenizer import CLIPTokenizer


@keras_cv_export("keras_cv.models.feature_extractors.CLIPProcessor")
@keras_cv_export("keras_cv.models.feature_extractor.CLIPProcessor")
class CLIPProcessor:
"""
CLIPProcessor is a utility class that provides functionality for processing
Expand Down
2 changes: 2 additions & 0 deletions keras_cv/models/feature_extractor/clip/clip_text_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
# 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.api_export import keras_cv_export
from keras_cv.backend import keras
from keras_cv.backend import ops
from keras_cv.models.feature_extractor.clip.clip_encoder import CLIPEncoder


@keras_cv_export("keras_cv.models.feature_extractor.CLIPTextEncoder")
class CLIPTextEncoder(keras.Model):
def __init__(
self,
Expand Down
Loading

0 comments on commit fb05c82

Please sign in to comment.