keras-hub-nightly 0.21.0.dev202504050402__py3-none-any.whl → 0.21.0.dev202504052235__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- keras_hub/api/layers/__init__.py +3 -0
- keras_hub/api/models/__init__.py +7 -0
- keras_hub/src/models/xception/__init__.py +5 -0
- keras_hub/src/models/xception/xception_backbone.py +188 -0
- keras_hub/src/models/xception/xception_image_classifier.py +12 -0
- keras_hub/src/models/xception/xception_image_classifier_preprocessor.py +14 -0
- keras_hub/src/models/xception/xception_image_converter.py +8 -0
- keras_hub/src/models/xception/xception_presets.py +14 -0
- keras_hub/src/version_utils.py +1 -1
- {keras_hub_nightly-0.21.0.dev202504050402.dist-info → keras_hub_nightly-0.21.0.dev202504052235.dist-info}/METADATA +1 -1
- {keras_hub_nightly-0.21.0.dev202504050402.dist-info → keras_hub_nightly-0.21.0.dev202504052235.dist-info}/RECORD +13 -7
- {keras_hub_nightly-0.21.0.dev202504050402.dist-info → keras_hub_nightly-0.21.0.dev202504052235.dist-info}/WHEEL +0 -0
- {keras_hub_nightly-0.21.0.dev202504050402.dist-info → keras_hub_nightly-0.21.0.dev202504052235.dist-info}/top_level.txt +0 -0
keras_hub/api/layers/__init__.py
CHANGED
@@ -84,3 +84,6 @@ from keras_hub.src.models.vit.vit_image_converter import ViTImageConverter
|
|
84
84
|
from keras_hub.src.models.whisper.whisper_audio_converter import (
|
85
85
|
WhisperAudioConverter,
|
86
86
|
)
|
87
|
+
from keras_hub.src.models.xception.xception_image_converter import (
|
88
|
+
XceptionImageConverter,
|
89
|
+
)
|
keras_hub/api/models/__init__.py
CHANGED
@@ -388,6 +388,13 @@ from keras_hub.src.models.vit.vit_image_classifier_preprocessor import (
|
|
388
388
|
from keras_hub.src.models.vit_det.vit_det_backbone import ViTDetBackbone
|
389
389
|
from keras_hub.src.models.whisper.whisper_backbone import WhisperBackbone
|
390
390
|
from keras_hub.src.models.whisper.whisper_tokenizer import WhisperTokenizer
|
391
|
+
from keras_hub.src.models.xception.xception_backbone import XceptionBackbone
|
392
|
+
from keras_hub.src.models.xception.xception_image_classifier import (
|
393
|
+
XceptionImageClassifier,
|
394
|
+
)
|
395
|
+
from keras_hub.src.models.xception.xception_image_classifier_preprocessor import (
|
396
|
+
XceptionImageClassifierPreprocessor,
|
397
|
+
)
|
391
398
|
from keras_hub.src.models.xlm_roberta.xlm_roberta_backbone import (
|
392
399
|
XLMRobertaBackbone,
|
393
400
|
)
|
@@ -0,0 +1,5 @@
|
|
1
|
+
from keras_hub.src.models.xception.xception_backbone import XceptionBackbone
|
2
|
+
from keras_hub.src.models.xception.xception_presets import backbone_presets
|
3
|
+
from keras_hub.src.utils.preset_utils import register_presets
|
4
|
+
|
5
|
+
register_presets(backbone_presets, XceptionBackbone)
|
@@ -0,0 +1,188 @@
|
|
1
|
+
import functools
|
2
|
+
|
3
|
+
from keras import layers
|
4
|
+
|
5
|
+
from keras_hub.src.api_export import keras_hub_export
|
6
|
+
from keras_hub.src.models.backbone import Backbone
|
7
|
+
from keras_hub.src.utils.keras_utils import standardize_data_format
|
8
|
+
|
9
|
+
|
10
|
+
@keras_hub_export("keras_hub.models.XceptionBackbone")
|
11
|
+
class XceptionBackbone(Backbone):
|
12
|
+
"""Xception core network with hyperparameters.
|
13
|
+
|
14
|
+
This class implements a Xception backbone as described in
|
15
|
+
[Xception: Deep Learning with Depthwise Separable Convolutions](https://arxiv.org/abs/1610.02357).
|
16
|
+
|
17
|
+
Most users will want the pretrained presets available with this model. If
|
18
|
+
you are creating a custom backbone, this model provides customizability
|
19
|
+
through the `stackwise_conv_filters` and `stackwise_pooling` arguments. This
|
20
|
+
backbone assumes the same basic structure as the original Xception mode:
|
21
|
+
* Residuals and pre-activation everywhere but the first and last block.
|
22
|
+
* Conv layers for the first block only, separable conv layers elsewhere.
|
23
|
+
|
24
|
+
Args:
|
25
|
+
stackwise_conv_filters: list of list of ints. Each outermost list
|
26
|
+
entry represents a block, and each innermost list entry a conv
|
27
|
+
layer. The integer value specifies the number of filters for the
|
28
|
+
conv layer.
|
29
|
+
stackwise_pooling: list of bools. A list of booleans per block, where
|
30
|
+
each entry is true if the block should includes a max pooling layer
|
31
|
+
and false if it should not.
|
32
|
+
image_shape: tuple. The input shape without the batch size.
|
33
|
+
Defaults to `(None, None, 3)`.
|
34
|
+
data_format: `None` or str. If specified, either `"channels_last"` or
|
35
|
+
`"channels_first"`. If unspecified, the Keras default will be used.
|
36
|
+
dtype: `None` or str or `keras.mixed_precision.DTypePolicy`. The dtype
|
37
|
+
to use for the model's computations and weights.
|
38
|
+
|
39
|
+
Examples:
|
40
|
+
```python
|
41
|
+
input_data = np.random.uniform(0, 1, size=(2, 224, 224, 3))
|
42
|
+
|
43
|
+
# Pretrained Xception backbone.
|
44
|
+
model = keras_hub.models.Backbone.from_preset("xception_41_imagenet")
|
45
|
+
model(input_data)
|
46
|
+
|
47
|
+
# Randomly initialized Xception backbone with a custom config.
|
48
|
+
model = keras_hub.models.XceptionBackbone(
|
49
|
+
stackwise_conv_filters=[[32, 64], [64, 128], [256, 256]],
|
50
|
+
stackwise_pooling=[True, True, False],
|
51
|
+
)
|
52
|
+
model(input_data)
|
53
|
+
```
|
54
|
+
"""
|
55
|
+
|
56
|
+
def __init__(
|
57
|
+
self,
|
58
|
+
stackwise_conv_filters,
|
59
|
+
stackwise_pooling,
|
60
|
+
image_shape=(None, None, 3),
|
61
|
+
data_format=None,
|
62
|
+
dtype=None,
|
63
|
+
**kwargs,
|
64
|
+
):
|
65
|
+
if len(stackwise_conv_filters) != len(stackwise_pooling):
|
66
|
+
raise ValueError("All stackwise args should have the same length.")
|
67
|
+
|
68
|
+
data_format = standardize_data_format(data_format)
|
69
|
+
channel_axis = -1 if data_format == "channels_last" else 1
|
70
|
+
num_blocks = len(stackwise_conv_filters)
|
71
|
+
|
72
|
+
# Layer shorcuts with common args.
|
73
|
+
norm = functools.partial(
|
74
|
+
layers.BatchNormalization,
|
75
|
+
axis=channel_axis,
|
76
|
+
dtype=dtype,
|
77
|
+
)
|
78
|
+
act = functools.partial(
|
79
|
+
layers.Activation,
|
80
|
+
activation="relu",
|
81
|
+
dtype=dtype,
|
82
|
+
)
|
83
|
+
conv = functools.partial(
|
84
|
+
layers.Conv2D,
|
85
|
+
kernel_size=(3, 3),
|
86
|
+
use_bias=False,
|
87
|
+
data_format=data_format,
|
88
|
+
dtype=dtype,
|
89
|
+
)
|
90
|
+
sep_conv = functools.partial(
|
91
|
+
layers.SeparableConv2D,
|
92
|
+
kernel_size=(3, 3),
|
93
|
+
padding="same",
|
94
|
+
use_bias=False,
|
95
|
+
data_format=data_format,
|
96
|
+
dtype=dtype,
|
97
|
+
)
|
98
|
+
point_conv = functools.partial(
|
99
|
+
layers.Conv2D,
|
100
|
+
kernel_size=(1, 1),
|
101
|
+
strides=(2, 2),
|
102
|
+
padding="same",
|
103
|
+
use_bias=False,
|
104
|
+
data_format=data_format,
|
105
|
+
dtype=dtype,
|
106
|
+
)
|
107
|
+
pool = functools.partial(
|
108
|
+
layers.MaxPool2D,
|
109
|
+
pool_size=(3, 3),
|
110
|
+
strides=(2, 2),
|
111
|
+
padding="same",
|
112
|
+
data_format=data_format,
|
113
|
+
dtype=dtype,
|
114
|
+
)
|
115
|
+
|
116
|
+
# === Functional Model ===
|
117
|
+
image_input = layers.Input(shape=image_shape)
|
118
|
+
x = image_input # Intermediate result.
|
119
|
+
|
120
|
+
# Iterate through the blocks.
|
121
|
+
for block_i in range(num_blocks):
|
122
|
+
first_block, last_block = block_i == 0, block_i == num_blocks - 1
|
123
|
+
block_filters = stackwise_conv_filters[block_i]
|
124
|
+
use_pooling = stackwise_pooling[block_i]
|
125
|
+
|
126
|
+
# Save the block input as a residual.
|
127
|
+
residual = x
|
128
|
+
for conv_i, filters in enumerate(block_filters):
|
129
|
+
# First block has post activation and strides on first conv.
|
130
|
+
if first_block:
|
131
|
+
prefix = f"block{block_i + 1}_conv{conv_i + 1}"
|
132
|
+
strides = (2, 2) if conv_i == 0 else (1, 1)
|
133
|
+
x = conv(filters, strides=strides, name=prefix)(x)
|
134
|
+
x = norm(name=f"{prefix}_bn")(x)
|
135
|
+
x = act(name=f"{prefix}_act")(x)
|
136
|
+
# Last block has post activation.
|
137
|
+
elif last_block:
|
138
|
+
prefix = f"block{block_i + 1}_sepconv{conv_i + 1}"
|
139
|
+
x = sep_conv(filters, name=prefix)(x)
|
140
|
+
x = norm(name=f"{prefix}_bn")(x)
|
141
|
+
x = act(name=f"{prefix}_act")(x)
|
142
|
+
else:
|
143
|
+
prefix = f"block{block_i + 1}_sepconv{conv_i + 1}"
|
144
|
+
# The first conv in second block has no activation.
|
145
|
+
if block_i != 1 or conv_i != 0:
|
146
|
+
x = act(name=f"{prefix}_act")(x)
|
147
|
+
x = sep_conv(filters, name=prefix)(x)
|
148
|
+
x = norm(name=f"{prefix}_bn")(x)
|
149
|
+
|
150
|
+
# Optional block pooling.
|
151
|
+
if use_pooling:
|
152
|
+
x = pool(name=f"block{block_i + 1}_pool")(x)
|
153
|
+
|
154
|
+
# Sum residual, first and last block do not have a residual.
|
155
|
+
if not first_block and not last_block:
|
156
|
+
prefix = f"block{block_i + 1}_residual"
|
157
|
+
filters = x.shape[channel_axis]
|
158
|
+
# Match filters with a pointwise conv if needed.
|
159
|
+
if filters != residual.shape[channel_axis]:
|
160
|
+
residual = point_conv(filters, name=f"{prefix}_conv")(
|
161
|
+
residual
|
162
|
+
)
|
163
|
+
residual = norm(name=f"{prefix}_bn")(residual)
|
164
|
+
x = layers.Add(name=f"{prefix}_add", dtype=dtype)([x, residual])
|
165
|
+
|
166
|
+
super().__init__(
|
167
|
+
inputs=image_input,
|
168
|
+
outputs=x,
|
169
|
+
dtype=dtype,
|
170
|
+
**kwargs,
|
171
|
+
)
|
172
|
+
|
173
|
+
# === Config ===
|
174
|
+
self.stackwise_conv_filters = stackwise_conv_filters
|
175
|
+
self.stackwise_pooling = stackwise_pooling
|
176
|
+
self.image_shape = image_shape
|
177
|
+
self.data_format = data_format
|
178
|
+
|
179
|
+
def get_config(self):
|
180
|
+
config = super().get_config()
|
181
|
+
config.update(
|
182
|
+
{
|
183
|
+
"stackwise_conv_filters": self.stackwise_conv_filters,
|
184
|
+
"stackwise_pooling": self.stackwise_pooling,
|
185
|
+
"image_shape": self.image_shape,
|
186
|
+
}
|
187
|
+
)
|
188
|
+
return config
|
@@ -0,0 +1,12 @@
|
|
1
|
+
from keras_hub.src.api_export import keras_hub_export
|
2
|
+
from keras_hub.src.models.image_classifier import ImageClassifier
|
3
|
+
from keras_hub.src.models.xception.xception_backbone import XceptionBackbone
|
4
|
+
from keras_hub.src.models.xception.xception_image_classifier_preprocessor import ( # noqa: E501
|
5
|
+
XceptionImageClassifierPreprocessor,
|
6
|
+
)
|
7
|
+
|
8
|
+
|
9
|
+
@keras_hub_export("keras_hub.models.XceptionImageClassifier")
|
10
|
+
class XceptionImageClassifier(ImageClassifier):
|
11
|
+
backbone_cls = XceptionBackbone
|
12
|
+
preprocessor_cls = XceptionImageClassifierPreprocessor
|
@@ -0,0 +1,14 @@
|
|
1
|
+
from keras_hub.src.api_export import keras_hub_export
|
2
|
+
from keras_hub.src.models.image_classifier_preprocessor import (
|
3
|
+
ImageClassifierPreprocessor,
|
4
|
+
)
|
5
|
+
from keras_hub.src.models.xception.xception_backbone import XceptionBackbone
|
6
|
+
from keras_hub.src.models.xception.xception_image_converter import (
|
7
|
+
XceptionImageConverter,
|
8
|
+
)
|
9
|
+
|
10
|
+
|
11
|
+
@keras_hub_export("keras_hub.models.XceptionImageClassifierPreprocessor")
|
12
|
+
class XceptionImageClassifierPreprocessor(ImageClassifierPreprocessor):
|
13
|
+
backbone_cls = XceptionBackbone
|
14
|
+
image_converter_cls = XceptionImageConverter
|
@@ -0,0 +1,8 @@
|
|
1
|
+
from keras_hub.src.api_export import keras_hub_export
|
2
|
+
from keras_hub.src.layers.preprocessing.image_converter import ImageConverter
|
3
|
+
from keras_hub.src.models.xception.xception_backbone import XceptionBackbone
|
4
|
+
|
5
|
+
|
6
|
+
@keras_hub_export("keras_hub.layers.XceptionImageConverter")
|
7
|
+
class XceptionImageConverter(ImageConverter):
|
8
|
+
backbone_cls = XceptionBackbone
|
@@ -0,0 +1,14 @@
|
|
1
|
+
"""Xception preset configurations."""
|
2
|
+
|
3
|
+
backbone_presets = {
|
4
|
+
"xception_41_imagenet": {
|
5
|
+
"metadata": {
|
6
|
+
"description": (
|
7
|
+
"41-layer Xception model pre-trained on ImageNet 1k."
|
8
|
+
),
|
9
|
+
"params": 20861480,
|
10
|
+
"path": "xception",
|
11
|
+
},
|
12
|
+
"kaggle_handle": "kaggle://keras/xception/keras/xception_41_imagenet/2",
|
13
|
+
},
|
14
|
+
}
|
keras_hub/src/version_utils.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: keras-hub-nightly
|
3
|
-
Version: 0.21.0.
|
3
|
+
Version: 0.21.0.dev202504052235
|
4
4
|
Summary: Industry-strength Natural Language Processing extensions for Keras.
|
5
5
|
Home-page: https://github.com/keras-team/keras-hub
|
6
6
|
Author: Keras team
|
@@ -1,14 +1,14 @@
|
|
1
1
|
keras_hub/__init__.py,sha256=QGdXyHgYt6cMUAP1ebxwc6oR86dE0dkMxNy2eOCQtFo,855
|
2
2
|
keras_hub/api/__init__.py,sha256=EzR6D-XWsm_gDrX5LDwKEmrah_gu3ffpj8GKBudE0yI,485
|
3
|
-
keras_hub/api/layers/__init__.py,sha256=
|
3
|
+
keras_hub/api/layers/__init__.py,sha256=MXQbQ0PpkDDRmP7A38aHjF6V2WilFlOxqUx4psoyvFo,3818
|
4
4
|
keras_hub/api/metrics/__init__.py,sha256=So8Ec-lOcTzn_UUMmAdzDm8RKkPu2dbRUm2px8gpUEI,381
|
5
|
-
keras_hub/api/models/__init__.py,sha256=
|
5
|
+
keras_hub/api/models/__init__.py,sha256=Um3TlN6BfFBC2kLJvAbiQ3PwUaZk0yhq4yQWttxsH1o,19060
|
6
6
|
keras_hub/api/samplers/__init__.py,sha256=n-_SEXxr2LNUzK2FqVFN7alsrkx1P_HOVTeLZKeGCdE,730
|
7
7
|
keras_hub/api/tokenizers/__init__.py,sha256=ZMrudLg7bR9_ZoXJbiUEU3J6NHBqFRjKqLlfGrIWewo,2766
|
8
8
|
keras_hub/api/utils/__init__.py,sha256=Gp1E6gG-RtKQS3PBEQEOz9PQvXkXaJ0ySGMqZ7myN7A,215
|
9
9
|
keras_hub/src/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
10
10
|
keras_hub/src/api_export.py,sha256=9pQZK27JObxWZ96QPLBp1OBsjWigh1iuV6RglPGMRk0,1499
|
11
|
-
keras_hub/src/version_utils.py,sha256=
|
11
|
+
keras_hub/src/version_utils.py,sha256=Mqk6lNzlQbwKMGLbz6F3S17Wyh3dAXGdlQWnfve5138,222
|
12
12
|
keras_hub/src/layers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
13
13
|
keras_hub/src/layers/modeling/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
14
14
|
keras_hub/src/layers/modeling/alibi_bias.py,sha256=1XBTHI52L_iJDhN_w5ydu_iMhCuTgQAxEPwcLA6BPuk,4411
|
@@ -396,6 +396,12 @@ keras_hub/src/models/whisper/whisper_decoder.py,sha256=rx9tFiXyGPnu_CScG8t8_7TVC
|
|
396
396
|
keras_hub/src/models/whisper/whisper_encoder.py,sha256=ZJ93D6mP95Mb9cFDZbfMWbB9FlrV3706ZsUwUJMKOdg,3730
|
397
397
|
keras_hub/src/models/whisper/whisper_presets.py,sha256=T1koXMeU-S3WCs10oTXIScVvn_4DoB6ah-EkqQLnVKI,3898
|
398
398
|
keras_hub/src/models/whisper/whisper_tokenizer.py,sha256=HcF3PMoaLm-bNH9J_mG_iCBWGtJO6ahCRGAjjCptQOs,5575
|
399
|
+
keras_hub/src/models/xception/__init__.py,sha256=Q7rwxGiBNrbKuteTF6LepeyCTEPQf-s7AzxGsWqJxdI,269
|
400
|
+
keras_hub/src/models/xception/xception_backbone.py,sha256=oSLEZYqOUEFnTyU-81oqZlL6ENcShJN6rJAnr0IKOds,7208
|
401
|
+
keras_hub/src/models/xception/xception_image_classifier.py,sha256=dpTD3nnUFaqONL5eU7Mz6lj883l30DlcBFyNkUGLtqY,544
|
402
|
+
keras_hub/src/models/xception/xception_image_classifier_preprocessor.py,sha256=bHqPuNyrJEVvhSSBrlpXvztJDbU0kv7JFWpT4W46OS0,563
|
403
|
+
keras_hub/src/models/xception/xception_image_converter.py,sha256=eM1gi48RK2-3UW9qgqNpL3OBB14UDOgQUw3HPs_Jiyg,354
|
404
|
+
keras_hub/src/models/xception/xception_presets.py,sha256=UUBt_0AN5n0fSVUVNXyuk5KVx5nLDtdu10K0tdox4Ec,391
|
399
405
|
keras_hub/src/models/xlm_roberta/__init__.py,sha256=iiCNSvDxPXZdxDyQKRxSLp5qzSpTuodL2TlHfwfqQjQ,303
|
400
406
|
keras_hub/src/models/xlm_roberta/xlm_roberta_backbone.py,sha256=x7wSDya7M4qcmzAwskd6qx9avSQs8mWhvAMWS4hnpFY,2922
|
401
407
|
keras_hub/src/models/xlm_roberta/xlm_roberta_masked_lm.py,sha256=PTxsd3DSxciKL6ub4hRHXbusx7tFnIBj_pFJXPJu8zQ,4392
|
@@ -459,7 +465,7 @@ keras_hub/src/utils/transformers/convert_qwen.py,sha256=I2bfwo8AQd_JfwFpiAuCQ3k_
|
|
459
465
|
keras_hub/src/utils/transformers/convert_vit.py,sha256=9SUZ9utNJhW_5cj3acMn9cRy47u2eIcDsrhmzj77o9k,5187
|
460
466
|
keras_hub/src/utils/transformers/preset_loader.py,sha256=0Hi7R8HnATcwFVLsJwMMIMWTCXHNfep4IPiRpQXqM-w,3933
|
461
467
|
keras_hub/src/utils/transformers/safetensor_utils.py,sha256=CYUHyA4y-B61r7NDnCsFb4t_UmSwZ1k9L-8gzEd6KRg,3339
|
462
|
-
keras_hub_nightly-0.21.0.
|
463
|
-
keras_hub_nightly-0.21.0.
|
464
|
-
keras_hub_nightly-0.21.0.
|
465
|
-
keras_hub_nightly-0.21.0.
|
468
|
+
keras_hub_nightly-0.21.0.dev202504052235.dist-info/METADATA,sha256=YA8wftAkMAfM3SUAwFg2jIkVQD4LN3Mfr8yYeXbVntE,7715
|
469
|
+
keras_hub_nightly-0.21.0.dev202504052235.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
|
470
|
+
keras_hub_nightly-0.21.0.dev202504052235.dist-info/top_level.txt,sha256=N4J6piIWBKa38A4uV-CnIopnOEf8mHAbkNXafXm_CuA,10
|
471
|
+
keras_hub_nightly-0.21.0.dev202504052235.dist-info/RECORD,,
|
File without changes
|