keras-hub-nightly 0.16.1.dev202409240339__py3-none-any.whl → 0.16.1.dev202409260340__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 +5 -0
- keras_hub/api/models/__init__.py +19 -0
- keras_hub/api/tokenizers/__init__.py +1 -0
- keras_hub/src/models/{stable_diffusion_v3 → clip}/clip_encoder_block.py +8 -2
- keras_hub/src/models/clip/clip_preprocessor.py +147 -0
- keras_hub/src/models/{stable_diffusion_v3 → clip}/clip_text_encoder.py +60 -57
- keras_hub/src/models/{stable_diffusion_v3 → clip}/clip_tokenizer.py +69 -30
- keras_hub/src/models/densenet/__init__.py +6 -0
- keras_hub/src/models/densenet/densenet_backbone.py +11 -8
- keras_hub/src/models/densenet/densenet_image_classifier.py +27 -4
- keras_hub/src/models/densenet/densenet_image_classifier_preprocessor.py +27 -0
- keras_hub/src/models/densenet/densenet_image_converter.py +23 -0
- keras_hub/src/models/densenet/densenet_presets.py +56 -0
- keras_hub/src/models/image_segmenter.py +86 -0
- keras_hub/src/models/sam/__init__.py +13 -0
- keras_hub/src/models/sam/sam_backbone.py +153 -0
- keras_hub/src/models/sam/sam_image_segmenter.py +237 -0
- keras_hub/src/models/sam/sam_layers.py +402 -0
- keras_hub/src/models/sam/sam_mask_decoder.py +270 -0
- keras_hub/src/models/sam/sam_prompt_encoder.py +336 -0
- keras_hub/src/models/sam/sam_transformer.py +159 -0
- keras_hub/src/models/stable_diffusion_3/__init__.py +13 -0
- keras_hub/src/models/stable_diffusion_3/flow_match_euler_discrete_scheduler.py +93 -0
- keras_hub/src/models/{stable_diffusion_v3 → stable_diffusion_3}/mmdit.py +351 -26
- keras_hub/src/models/stable_diffusion_3/stable_diffusion_3_backbone.py +630 -0
- keras_hub/src/models/stable_diffusion_3/stable_diffusion_3_text_to_image.py +151 -0
- keras_hub/src/models/stable_diffusion_3/stable_diffusion_3_text_to_image_preprocessor.py +77 -0
- keras_hub/src/models/{stable_diffusion_v3/t5_xxl_text_encoder.py → stable_diffusion_3/t5_encoder.py} +7 -7
- keras_hub/src/models/stable_diffusion_3/vae_image_decoder.py +333 -0
- keras_hub/src/models/{stable_diffusion_v3/t5_xxl_preprocessor.py → t5/t5_preprocessor.py} +12 -3
- keras_hub/src/models/text_to_image.py +295 -0
- keras_hub/src/models/vit_det/vit_det_backbone.py +17 -12
- keras_hub/src/utils/timm/convert_densenet.py +107 -0
- keras_hub/src/utils/timm/preset_loader.py +3 -0
- keras_hub/src/version_utils.py +1 -1
- {keras_hub_nightly-0.16.1.dev202409240339.dist-info → keras_hub_nightly-0.16.1.dev202409260340.dist-info}/METADATA +1 -1
- {keras_hub_nightly-0.16.1.dev202409240339.dist-info → keras_hub_nightly-0.16.1.dev202409260340.dist-info}/RECORD +40 -24
- keras_hub/src/models/stable_diffusion_v3/clip_preprocessor.py +0 -93
- keras_hub/src/models/stable_diffusion_v3/mmdit_block.py +0 -317
- keras_hub/src/models/stable_diffusion_v3/vae_attention.py +0 -126
- keras_hub/src/models/stable_diffusion_v3/vae_image_decoder.py +0 -186
- /keras_hub/src/models/{stable_diffusion_v3 → clip}/__init__.py +0 -0
- {keras_hub_nightly-0.16.1.dev202409240339.dist-info → keras_hub_nightly-0.16.1.dev202409260340.dist-info}/WHEEL +0 -0
- {keras_hub_nightly-0.16.1.dev202409240339.dist-info → keras_hub_nightly-0.16.1.dev202409260340.dist-info}/top_level.txt +0 -0
@@ -1,186 +0,0 @@
|
|
1
|
-
# Copyright 2024 The KerasHub Authors
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# https://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
import keras
|
15
|
-
from keras import layers
|
16
|
-
|
17
|
-
from keras_hub.src.models.stable_diffusion_v3.vae_attention import VAEAttention
|
18
|
-
from keras_hub.src.utils.keras_utils import standardize_data_format
|
19
|
-
|
20
|
-
|
21
|
-
class VAEImageDecoder(keras.Model):
|
22
|
-
def __init__(
|
23
|
-
self,
|
24
|
-
stackwise_num_filters,
|
25
|
-
stackwise_num_blocks,
|
26
|
-
output_channels=3,
|
27
|
-
latent_shape=(None, None, 16),
|
28
|
-
data_format=None,
|
29
|
-
dtype=None,
|
30
|
-
**kwargs,
|
31
|
-
):
|
32
|
-
data_format = standardize_data_format(data_format)
|
33
|
-
gn_axis = -1 if data_format == "channels_last" else 1
|
34
|
-
|
35
|
-
# === Functional Model ===
|
36
|
-
latent_inputs = layers.Input(shape=latent_shape)
|
37
|
-
|
38
|
-
x = layers.Conv2D(
|
39
|
-
stackwise_num_filters[0],
|
40
|
-
3,
|
41
|
-
1,
|
42
|
-
padding="same",
|
43
|
-
data_format=data_format,
|
44
|
-
dtype=dtype,
|
45
|
-
name="input_projection",
|
46
|
-
)(latent_inputs)
|
47
|
-
x = apply_resnet_block(
|
48
|
-
x,
|
49
|
-
stackwise_num_filters[0],
|
50
|
-
data_format=data_format,
|
51
|
-
dtype=dtype,
|
52
|
-
name="input_block0",
|
53
|
-
)
|
54
|
-
x = VAEAttention(
|
55
|
-
stackwise_num_filters[0],
|
56
|
-
data_format=data_format,
|
57
|
-
dtype=dtype,
|
58
|
-
name="input_attention",
|
59
|
-
)(x)
|
60
|
-
x = apply_resnet_block(
|
61
|
-
x,
|
62
|
-
stackwise_num_filters[0],
|
63
|
-
data_format=data_format,
|
64
|
-
dtype=dtype,
|
65
|
-
name="input_block1",
|
66
|
-
)
|
67
|
-
|
68
|
-
# Stacks.
|
69
|
-
for i, filters in enumerate(stackwise_num_filters):
|
70
|
-
for j in range(stackwise_num_blocks[i]):
|
71
|
-
x = apply_resnet_block(
|
72
|
-
x,
|
73
|
-
filters,
|
74
|
-
data_format=data_format,
|
75
|
-
dtype=dtype,
|
76
|
-
name=f"block{i}_{j}",
|
77
|
-
)
|
78
|
-
if i != len(stackwise_num_filters) - 1:
|
79
|
-
# No upsamling in the last blcok.
|
80
|
-
x = layers.UpSampling2D(
|
81
|
-
2,
|
82
|
-
data_format=data_format,
|
83
|
-
dtype=dtype,
|
84
|
-
name=f"upsample_{i}",
|
85
|
-
)(x)
|
86
|
-
x = layers.Conv2D(
|
87
|
-
filters,
|
88
|
-
3,
|
89
|
-
1,
|
90
|
-
padding="same",
|
91
|
-
data_format=data_format,
|
92
|
-
dtype=dtype,
|
93
|
-
name=f"upsample_{i}_conv",
|
94
|
-
)(x)
|
95
|
-
|
96
|
-
# Ouput block.
|
97
|
-
x = layers.GroupNormalization(
|
98
|
-
groups=32,
|
99
|
-
axis=gn_axis,
|
100
|
-
epsilon=1e-6,
|
101
|
-
dtype=dtype,
|
102
|
-
name="output_norm",
|
103
|
-
)(x)
|
104
|
-
x = layers.Activation("swish", dtype=dtype, name="output_activation")(x)
|
105
|
-
image_outputs = layers.Conv2D(
|
106
|
-
output_channels,
|
107
|
-
3,
|
108
|
-
1,
|
109
|
-
padding="same",
|
110
|
-
data_format=data_format,
|
111
|
-
dtype=dtype,
|
112
|
-
name="output_projection",
|
113
|
-
)(x)
|
114
|
-
super().__init__(inputs=latent_inputs, outputs=image_outputs, **kwargs)
|
115
|
-
|
116
|
-
# === Config ===
|
117
|
-
self.stackwise_num_filters = stackwise_num_filters
|
118
|
-
self.stackwise_num_blocks = stackwise_num_blocks
|
119
|
-
self.output_channels = output_channels
|
120
|
-
self.latent_shape = latent_shape
|
121
|
-
|
122
|
-
if dtype is not None:
|
123
|
-
try:
|
124
|
-
self.dtype_policy = keras.dtype_policies.get(dtype)
|
125
|
-
# Before Keras 3.2, there is no `keras.dtype_policies.get`.
|
126
|
-
except AttributeError:
|
127
|
-
if isinstance(dtype, keras.DTypePolicy):
|
128
|
-
dtype = dtype.name
|
129
|
-
self.dtype_policy = keras.DTypePolicy(dtype)
|
130
|
-
|
131
|
-
def get_config(self):
|
132
|
-
config = super().get_config()
|
133
|
-
config.update(
|
134
|
-
{
|
135
|
-
"stackwise_num_filters": self.stackwise_num_filters,
|
136
|
-
"stackwise_num_blocks": self.stackwise_num_blocks,
|
137
|
-
"output_channels": self.output_channels,
|
138
|
-
"image_shape": self.latent_shape,
|
139
|
-
}
|
140
|
-
)
|
141
|
-
return config
|
142
|
-
|
143
|
-
|
144
|
-
def apply_resnet_block(x, filters, data_format=None, dtype=None, name=None):
|
145
|
-
data_format = standardize_data_format(data_format)
|
146
|
-
gn_axis = -1 if data_format == "channels_last" else 1
|
147
|
-
input_filters = x.shape[gn_axis]
|
148
|
-
|
149
|
-
residual = x
|
150
|
-
x = layers.GroupNormalization(
|
151
|
-
groups=32, axis=gn_axis, epsilon=1e-6, dtype=dtype, name=f"{name}_norm1"
|
152
|
-
)(x)
|
153
|
-
x = layers.Activation("swish", dtype=dtype)(x)
|
154
|
-
x = layers.Conv2D(
|
155
|
-
filters,
|
156
|
-
3,
|
157
|
-
1,
|
158
|
-
padding="same",
|
159
|
-
data_format=data_format,
|
160
|
-
dtype=dtype,
|
161
|
-
name=f"{name}_conv1",
|
162
|
-
)(x)
|
163
|
-
x = layers.GroupNormalization(
|
164
|
-
groups=32, axis=gn_axis, epsilon=1e-6, dtype=dtype, name=f"{name}_norm2"
|
165
|
-
)(x)
|
166
|
-
x = layers.Activation("swish")(x)
|
167
|
-
x = layers.Conv2D(
|
168
|
-
filters,
|
169
|
-
3,
|
170
|
-
1,
|
171
|
-
padding="same",
|
172
|
-
data_format=data_format,
|
173
|
-
dtype=dtype,
|
174
|
-
name=f"{name}_conv2",
|
175
|
-
)(x)
|
176
|
-
if input_filters != filters:
|
177
|
-
residual = layers.Conv2D(
|
178
|
-
filters,
|
179
|
-
1,
|
180
|
-
1,
|
181
|
-
data_format=data_format,
|
182
|
-
dtype=dtype,
|
183
|
-
name=f"{name}_residual_projection",
|
184
|
-
)(residual)
|
185
|
-
x = layers.Add(dtype=dtype)([residual, x])
|
186
|
-
return x
|
File without changes
|
File without changes
|