keras-nightly 3.12.0.dev2025082103__py3-none-any.whl → 3.12.0.dev2025082303__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/_tf_keras/keras/ops/__init__.py +1 -0
- keras/_tf_keras/keras/ops/numpy/__init__.py +1 -0
- keras/_tf_keras/keras/quantizers/__init__.py +1 -0
- keras/ops/__init__.py +1 -0
- keras/ops/numpy/__init__.py +1 -0
- keras/quantizers/__init__.py +1 -0
- keras/src/applications/convnext.py +20 -20
- keras/src/applications/densenet.py +21 -21
- keras/src/applications/efficientnet.py +16 -16
- keras/src/applications/efficientnet_v2.py +28 -28
- keras/src/applications/inception_resnet_v2.py +7 -7
- keras/src/applications/inception_v3.py +5 -5
- keras/src/applications/mobilenet_v2.py +13 -20
- keras/src/applications/mobilenet_v3.py +15 -15
- keras/src/applications/nasnet.py +7 -8
- keras/src/applications/resnet.py +32 -32
- keras/src/applications/xception.py +10 -10
- keras/src/backend/common/dtypes.py +8 -3
- keras/src/backend/common/variables.py +3 -1
- keras/src/backend/jax/export.py +1 -1
- keras/src/backend/jax/numpy.py +6 -0
- keras/src/backend/jax/trainer.py +1 -1
- keras/src/backend/numpy/numpy.py +28 -0
- keras/src/backend/openvino/numpy.py +5 -1
- keras/src/backend/tensorflow/numpy.py +22 -0
- keras/src/backend/tensorflow/trainer.py +19 -1
- keras/src/backend/torch/core.py +6 -9
- keras/src/backend/torch/nn.py +1 -2
- keras/src/backend/torch/numpy.py +16 -0
- keras/src/backend/torch/trainer.py +1 -1
- keras/src/callbacks/backup_and_restore.py +2 -2
- keras/src/callbacks/csv_logger.py +1 -1
- keras/src/callbacks/model_checkpoint.py +1 -1
- keras/src/callbacks/tensorboard.py +6 -6
- keras/src/constraints/constraints.py +9 -7
- keras/src/datasets/boston_housing.py +1 -1
- keras/src/datasets/california_housing.py +1 -1
- keras/src/datasets/cifar10.py +1 -1
- keras/src/datasets/cifar100.py +2 -2
- keras/src/datasets/imdb.py +2 -2
- keras/src/datasets/mnist.py +1 -1
- keras/src/datasets/reuters.py +2 -2
- keras/src/dtype_policies/dtype_policy.py +1 -1
- keras/src/dtype_policies/dtype_policy_map.py +1 -1
- keras/src/export/tf2onnx_lib.py +1 -3
- keras/src/initializers/constant_initializers.py +9 -5
- keras/src/layers/input_spec.py +6 -6
- keras/src/layers/layer.py +1 -1
- keras/src/layers/preprocessing/category_encoding.py +3 -3
- keras/src/layers/preprocessing/data_layer.py +159 -0
- keras/src/layers/preprocessing/discretization.py +3 -3
- keras/src/layers/preprocessing/feature_space.py +4 -4
- keras/src/layers/preprocessing/image_preprocessing/aug_mix.py +7 -4
- keras/src/layers/preprocessing/image_preprocessing/auto_contrast.py +3 -0
- keras/src/layers/preprocessing/image_preprocessing/base_image_preprocessing_layer.py +2 -2
- keras/src/layers/preprocessing/image_preprocessing/center_crop.py +1 -1
- keras/src/layers/preprocessing/image_preprocessing/cut_mix.py +6 -3
- keras/src/layers/preprocessing/image_preprocessing/equalization.py +1 -1
- keras/src/layers/preprocessing/image_preprocessing/max_num_bounding_box.py +3 -0
- keras/src/layers/preprocessing/image_preprocessing/mix_up.py +7 -4
- keras/src/layers/preprocessing/image_preprocessing/rand_augment.py +3 -1
- keras/src/layers/preprocessing/image_preprocessing/random_brightness.py +1 -1
- keras/src/layers/preprocessing/image_preprocessing/random_color_degeneration.py +3 -0
- keras/src/layers/preprocessing/image_preprocessing/random_color_jitter.py +3 -0
- keras/src/layers/preprocessing/image_preprocessing/random_contrast.py +1 -1
- keras/src/layers/preprocessing/image_preprocessing/random_crop.py +1 -1
- keras/src/layers/preprocessing/image_preprocessing/random_elastic_transform.py +3 -0
- keras/src/layers/preprocessing/image_preprocessing/random_erasing.py +6 -3
- keras/src/layers/preprocessing/image_preprocessing/random_flip.py +1 -1
- keras/src/layers/preprocessing/image_preprocessing/random_gaussian_blur.py +3 -0
- keras/src/layers/preprocessing/image_preprocessing/random_grayscale.py +1 -1
- keras/src/layers/preprocessing/image_preprocessing/random_hue.py +3 -0
- keras/src/layers/preprocessing/image_preprocessing/random_invert.py +3 -0
- keras/src/layers/preprocessing/image_preprocessing/random_perspective.py +3 -0
- keras/src/layers/preprocessing/image_preprocessing/random_posterization.py +3 -0
- keras/src/layers/preprocessing/image_preprocessing/random_rotation.py +1 -1
- keras/src/layers/preprocessing/image_preprocessing/random_saturation.py +3 -0
- keras/src/layers/preprocessing/image_preprocessing/random_sharpness.py +3 -0
- keras/src/layers/preprocessing/image_preprocessing/random_shear.py +3 -0
- keras/src/layers/preprocessing/image_preprocessing/random_translation.py +3 -3
- keras/src/layers/preprocessing/image_preprocessing/random_zoom.py +3 -3
- keras/src/layers/preprocessing/image_preprocessing/resizing.py +3 -3
- keras/src/layers/preprocessing/image_preprocessing/solarization.py +3 -0
- keras/src/layers/preprocessing/mel_spectrogram.py +29 -25
- keras/src/layers/preprocessing/normalization.py +5 -2
- keras/src/layers/preprocessing/rescaling.py +3 -3
- keras/src/layers/rnn/bidirectional.py +4 -4
- keras/src/legacy/backend.py +9 -23
- keras/src/legacy/preprocessing/image.py +11 -22
- keras/src/legacy/preprocessing/text.py +1 -1
- keras/src/models/functional.py +2 -2
- keras/src/models/model.py +21 -3
- keras/src/ops/function.py +1 -1
- keras/src/ops/numpy.py +49 -5
- keras/src/ops/operation.py +3 -2
- keras/src/optimizers/base_optimizer.py +3 -4
- keras/src/optimizers/schedules/learning_rate_schedule.py +16 -9
- keras/src/quantizers/gptq.py +350 -0
- keras/src/quantizers/gptq_config.py +169 -0
- keras/src/quantizers/gptq_core.py +335 -0
- keras/src/quantizers/gptq_quant.py +133 -0
- keras/src/saving/file_editor.py +22 -20
- keras/src/saving/object_registration.py +1 -1
- keras/src/saving/saving_lib.py +4 -4
- keras/src/saving/serialization_lib.py +3 -5
- keras/src/trainers/compile_utils.py +1 -1
- keras/src/trainers/data_adapters/array_data_adapter.py +9 -3
- keras/src/trainers/data_adapters/data_adapter_utils.py +15 -5
- keras/src/trainers/data_adapters/generator_data_adapter.py +2 -0
- keras/src/trainers/data_adapters/grain_dataset_adapter.py +8 -2
- keras/src/trainers/data_adapters/tf_dataset_adapter.py +4 -2
- keras/src/trainers/data_adapters/torch_data_loader_adapter.py +3 -1
- keras/src/tree/dmtree_impl.py +19 -3
- keras/src/tree/optree_impl.py +3 -3
- keras/src/tree/tree_api.py +5 -2
- keras/src/utils/file_utils.py +13 -5
- keras/src/utils/io_utils.py +1 -1
- keras/src/utils/model_visualization.py +1 -1
- keras/src/utils/progbar.py +5 -5
- keras/src/utils/summary_utils.py +4 -4
- keras/src/version.py +1 -1
- {keras_nightly-3.12.0.dev2025082103.dist-info → keras_nightly-3.12.0.dev2025082303.dist-info}/METADATA +1 -1
- {keras_nightly-3.12.0.dev2025082103.dist-info → keras_nightly-3.12.0.dev2025082303.dist-info}/RECORD +125 -121
- keras/src/layers/preprocessing/tf_data_layer.py +0 -78
- {keras_nightly-3.12.0.dev2025082103.dist-info → keras_nightly-3.12.0.dev2025082303.dist-info}/WHEEL +0 -0
- {keras_nightly-3.12.0.dev2025082103.dist-info → keras_nightly-3.12.0.dev2025082303.dist-info}/top_level.txt +0 -0
@@ -195,6 +195,7 @@ from keras.src.ops.numpy import hanning as hanning
|
|
195
195
|
from keras.src.ops.numpy import heaviside as heaviside
|
196
196
|
from keras.src.ops.numpy import histogram as histogram
|
197
197
|
from keras.src.ops.numpy import hstack as hstack
|
198
|
+
from keras.src.ops.numpy import hypot as hypot
|
198
199
|
from keras.src.ops.numpy import identity as identity
|
199
200
|
from keras.src.ops.numpy import imag as imag
|
200
201
|
from keras.src.ops.numpy import inner as inner
|
@@ -83,6 +83,7 @@ from keras.src.ops.numpy import hanning as hanning
|
|
83
83
|
from keras.src.ops.numpy import heaviside as heaviside
|
84
84
|
from keras.src.ops.numpy import histogram as histogram
|
85
85
|
from keras.src.ops.numpy import hstack as hstack
|
86
|
+
from keras.src.ops.numpy import hypot as hypot
|
86
87
|
from keras.src.ops.numpy import identity as identity
|
87
88
|
from keras.src.ops.numpy import imag as imag
|
88
89
|
from keras.src.ops.numpy import inner as inner
|
@@ -7,6 +7,7 @@ since your modifications would be overwritten.
|
|
7
7
|
from keras.src.quantizers import deserialize as deserialize
|
8
8
|
from keras.src.quantizers import get as get
|
9
9
|
from keras.src.quantizers import serialize as serialize
|
10
|
+
from keras.src.quantizers.gptq_config import GPTQConfig as GPTQConfig
|
10
11
|
from keras.src.quantizers.quantizers import AbsMaxQuantizer as AbsMaxQuantizer
|
11
12
|
from keras.src.quantizers.quantizers import Quantizer as Quantizer
|
12
13
|
from keras.src.quantizers.quantizers import abs_max_quantize as abs_max_quantize
|
keras/ops/__init__.py
CHANGED
@@ -195,6 +195,7 @@ from keras.src.ops.numpy import hanning as hanning
|
|
195
195
|
from keras.src.ops.numpy import heaviside as heaviside
|
196
196
|
from keras.src.ops.numpy import histogram as histogram
|
197
197
|
from keras.src.ops.numpy import hstack as hstack
|
198
|
+
from keras.src.ops.numpy import hypot as hypot
|
198
199
|
from keras.src.ops.numpy import identity as identity
|
199
200
|
from keras.src.ops.numpy import imag as imag
|
200
201
|
from keras.src.ops.numpy import inner as inner
|
keras/ops/numpy/__init__.py
CHANGED
@@ -83,6 +83,7 @@ from keras.src.ops.numpy import hanning as hanning
|
|
83
83
|
from keras.src.ops.numpy import heaviside as heaviside
|
84
84
|
from keras.src.ops.numpy import histogram as histogram
|
85
85
|
from keras.src.ops.numpy import hstack as hstack
|
86
|
+
from keras.src.ops.numpy import hypot as hypot
|
86
87
|
from keras.src.ops.numpy import identity as identity
|
87
88
|
from keras.src.ops.numpy import imag as imag
|
88
89
|
from keras.src.ops.numpy import inner as inner
|
keras/quantizers/__init__.py
CHANGED
@@ -7,6 +7,7 @@ since your modifications would be overwritten.
|
|
7
7
|
from keras.src.quantizers import deserialize as deserialize
|
8
8
|
from keras.src.quantizers import get as get
|
9
9
|
from keras.src.quantizers import serialize as serialize
|
10
|
+
from keras.src.quantizers.gptq_config import GPTQConfig as GPTQConfig
|
10
11
|
from keras.src.quantizers.quantizers import AbsMaxQuantizer as AbsMaxQuantizer
|
11
12
|
from keras.src.quantizers.quantizers import Quantizer as Quantizer
|
12
13
|
from keras.src.quantizers.quantizers import abs_max_quantize as abs_max_quantize
|
@@ -244,7 +244,7 @@ def ConvNeXtBlock(
|
|
244
244
|
A function representing a ConvNeXtBlock block.
|
245
245
|
"""
|
246
246
|
if name is None:
|
247
|
-
name = "prestem
|
247
|
+
name = f"prestem{str(backend.get_uid('prestem'))}"
|
248
248
|
|
249
249
|
def apply(inputs):
|
250
250
|
x = inputs
|
@@ -254,25 +254,25 @@ def ConvNeXtBlock(
|
|
254
254
|
kernel_size=7,
|
255
255
|
padding="same",
|
256
256
|
groups=projection_dim,
|
257
|
-
name=name
|
257
|
+
name=f"{name}_depthwise_conv",
|
258
258
|
)(x)
|
259
|
-
x = layers.LayerNormalization(epsilon=1e-6, name=name
|
260
|
-
x = layers.Dense(4 * projection_dim, name=name
|
261
|
-
x = layers.Activation("gelu", name=name
|
262
|
-
x = layers.Dense(projection_dim, name=name
|
259
|
+
x = layers.LayerNormalization(epsilon=1e-6, name=f"{name}_layernorm")(x)
|
260
|
+
x = layers.Dense(4 * projection_dim, name=f"{name}_pointwise_conv_1")(x)
|
261
|
+
x = layers.Activation("gelu", name=f"{name}_gelu")(x)
|
262
|
+
x = layers.Dense(projection_dim, name=f"{name}_pointwise_conv_2")(x)
|
263
263
|
|
264
264
|
if layer_scale_init_value is not None:
|
265
265
|
x = LayerScale(
|
266
266
|
layer_scale_init_value,
|
267
267
|
projection_dim,
|
268
|
-
name=name
|
268
|
+
name=f"{name}_layer_scale",
|
269
269
|
)(x)
|
270
270
|
if drop_path_rate:
|
271
271
|
layer = StochasticDepth(
|
272
|
-
drop_path_rate, name=name
|
272
|
+
drop_path_rate, name=f"{name}_stochastic_depth"
|
273
273
|
)
|
274
274
|
else:
|
275
|
-
layer = layers.Activation("linear", name=name
|
275
|
+
layer = layers.Activation("linear", name=f"{name}_identity")
|
276
276
|
|
277
277
|
return inputs + layer(x)
|
278
278
|
|
@@ -282,7 +282,7 @@ def ConvNeXtBlock(
|
|
282
282
|
def PreStem(name=None):
|
283
283
|
"""Normalizes inputs with ImageNet-1k mean and std."""
|
284
284
|
if name is None:
|
285
|
-
name = "prestem"
|
285
|
+
name = "prestem{0}".format(str(backend.get_uid("prestem")))
|
286
286
|
|
287
287
|
def apply(x):
|
288
288
|
x = layers.Normalization(
|
@@ -292,7 +292,7 @@ def PreStem(name=None):
|
|
292
292
|
(0.224 * 255) ** 2,
|
293
293
|
(0.225 * 255) ** 2,
|
294
294
|
],
|
295
|
-
name=name
|
295
|
+
name=f"{name}_prestem_normalization",
|
296
296
|
)(x)
|
297
297
|
return x
|
298
298
|
|
@@ -314,14 +314,14 @@ def Head(num_classes=1000, classifier_activation=None, name=None):
|
|
314
314
|
name = str(backend.get_uid("head"))
|
315
315
|
|
316
316
|
def apply(x):
|
317
|
-
x = layers.GlobalAveragePooling2D(name=name
|
317
|
+
x = layers.GlobalAveragePooling2D(name=f"{name}_head_gap")(x)
|
318
318
|
x = layers.LayerNormalization(
|
319
|
-
epsilon=1e-6, name=name
|
319
|
+
epsilon=1e-6, name=f"{name}_head_layernorm"
|
320
320
|
)(x)
|
321
321
|
x = layers.Dense(
|
322
322
|
num_classes,
|
323
323
|
activation=classifier_activation,
|
324
|
-
name=name
|
324
|
+
name=f"{name}_head_dense",
|
325
325
|
)(x)
|
326
326
|
return x
|
327
327
|
|
@@ -452,13 +452,13 @@ def ConvNeXt(
|
|
452
452
|
projection_dims[0],
|
453
453
|
kernel_size=4,
|
454
454
|
strides=4,
|
455
|
-
name=name
|
455
|
+
name=f"{name}_stem_conv",
|
456
456
|
),
|
457
457
|
layers.LayerNormalization(
|
458
|
-
epsilon=1e-6, name=name
|
458
|
+
epsilon=1e-6, name=f"{name}_stem_layernorm"
|
459
459
|
),
|
460
460
|
],
|
461
|
-
name=name
|
461
|
+
name=f"{name}_stem",
|
462
462
|
)
|
463
463
|
|
464
464
|
# Downsampling blocks.
|
@@ -471,16 +471,16 @@ def ConvNeXt(
|
|
471
471
|
[
|
472
472
|
layers.LayerNormalization(
|
473
473
|
epsilon=1e-6,
|
474
|
-
name=name
|
474
|
+
name=f"{name}_downsampling_layernorm_{i}",
|
475
475
|
),
|
476
476
|
layers.Conv2D(
|
477
477
|
projection_dims[i + 1],
|
478
478
|
kernel_size=2,
|
479
479
|
strides=2,
|
480
|
-
name=name
|
480
|
+
name=f"{name}_downsampling_conv_{i}",
|
481
481
|
),
|
482
482
|
],
|
483
|
-
name=name
|
483
|
+
name=f"{name}_downsampling_block_{i}",
|
484
484
|
)
|
485
485
|
downsample_layers.append(downsample_layer)
|
486
486
|
|
@@ -10,25 +10,25 @@ BASE_WEIGHTS_PATH = (
|
|
10
10
|
"https://storage.googleapis.com/tensorflow/keras-applications/densenet/"
|
11
11
|
)
|
12
12
|
DENSENET121_WEIGHT_PATH = (
|
13
|
-
BASE_WEIGHTS_PATH
|
13
|
+
f"{BASE_WEIGHTS_PATH}densenet121_weights_tf_dim_ordering_tf_kernels.h5"
|
14
14
|
)
|
15
15
|
DENSENET121_WEIGHT_PATH_NO_TOP = (
|
16
|
-
BASE_WEIGHTS_PATH
|
17
|
-
|
16
|
+
f"{BASE_WEIGHTS_PATH}"
|
17
|
+
"densenet121_weights_tf_dim_ordering_tf_kernels_notop.h5"
|
18
18
|
)
|
19
19
|
DENSENET169_WEIGHT_PATH = (
|
20
|
-
BASE_WEIGHTS_PATH
|
20
|
+
f"{BASE_WEIGHTS_PATH}densenet169_weights_tf_dim_ordering_tf_kernels.h5"
|
21
21
|
)
|
22
22
|
DENSENET169_WEIGHT_PATH_NO_TOP = (
|
23
|
-
BASE_WEIGHTS_PATH
|
24
|
-
|
23
|
+
f"{BASE_WEIGHTS_PATH}"
|
24
|
+
"densenet169_weights_tf_dim_ordering_tf_kernels_notop.h5"
|
25
25
|
)
|
26
26
|
DENSENET201_WEIGHT_PATH = (
|
27
|
-
BASE_WEIGHTS_PATH
|
27
|
+
f"{BASE_WEIGHTS_PATH}densenet201_weights_tf_dim_ordering_tf_kernels.h5"
|
28
28
|
)
|
29
29
|
DENSENET201_WEIGHT_PATH_NO_TOP = (
|
30
|
-
BASE_WEIGHTS_PATH
|
31
|
-
|
30
|
+
f"{BASE_WEIGHTS_PATH}"
|
31
|
+
"densenet201_weights_tf_dim_ordering_tf_kernels_notop.h5"
|
32
32
|
)
|
33
33
|
|
34
34
|
|
@@ -44,7 +44,7 @@ def dense_block(x, blocks, name):
|
|
44
44
|
Output tensor for the block.
|
45
45
|
"""
|
46
46
|
for i in range(blocks):
|
47
|
-
x = conv_block(x, 32, name=name
|
47
|
+
x = conv_block(x, 32, name=f"{name}_block{i + 1}")
|
48
48
|
return x
|
49
49
|
|
50
50
|
|
@@ -61,16 +61,16 @@ def transition_block(x, reduction, name):
|
|
61
61
|
"""
|
62
62
|
bn_axis = 3 if backend.image_data_format() == "channels_last" else 1
|
63
63
|
x = layers.BatchNormalization(
|
64
|
-
axis=bn_axis, epsilon=1.001e-5, name=name
|
64
|
+
axis=bn_axis, epsilon=1.001e-5, name=f"{name}_bn"
|
65
65
|
)(x)
|
66
|
-
x = layers.Activation("relu", name=name
|
66
|
+
x = layers.Activation("relu", name=f"{name}_relu")(x)
|
67
67
|
x = layers.Conv2D(
|
68
68
|
int(x.shape[bn_axis] * reduction),
|
69
69
|
1,
|
70
70
|
use_bias=False,
|
71
|
-
name=name
|
71
|
+
name=f"{name}_conv",
|
72
72
|
)(x)
|
73
|
-
x = layers.AveragePooling2D(2, strides=2, name=name
|
73
|
+
x = layers.AveragePooling2D(2, strides=2, name=f"{name}_pool")(x)
|
74
74
|
return x
|
75
75
|
|
76
76
|
|
@@ -87,20 +87,20 @@ def conv_block(x, growth_rate, name):
|
|
87
87
|
"""
|
88
88
|
bn_axis = 3 if backend.image_data_format() == "channels_last" else 1
|
89
89
|
x1 = layers.BatchNormalization(
|
90
|
-
axis=bn_axis, epsilon=1.001e-5, name=name
|
90
|
+
axis=bn_axis, epsilon=1.001e-5, name=f"{name}_0_bn"
|
91
91
|
)(x)
|
92
|
-
x1 = layers.Activation("relu", name=name
|
92
|
+
x1 = layers.Activation("relu", name=f"{name}_0_relu")(x1)
|
93
93
|
x1 = layers.Conv2D(
|
94
|
-
4 * growth_rate, 1, use_bias=False, name=name
|
94
|
+
4 * growth_rate, 1, use_bias=False, name=f"{name}_1_conv"
|
95
95
|
)(x1)
|
96
96
|
x1 = layers.BatchNormalization(
|
97
|
-
axis=bn_axis, epsilon=1.001e-5, name=name
|
97
|
+
axis=bn_axis, epsilon=1.001e-5, name=f"{name}_1_bn"
|
98
98
|
)(x1)
|
99
|
-
x1 = layers.Activation("relu", name=name
|
99
|
+
x1 = layers.Activation("relu", name=f"{name}_1_relu")(x1)
|
100
100
|
x1 = layers.Conv2D(
|
101
|
-
growth_rate, 3, padding="same", use_bias=False, name=name
|
101
|
+
growth_rate, 3, padding="same", use_bias=False, name=f"{name}_2_conv"
|
102
102
|
)(x1)
|
103
|
-
x = layers.Concatenate(axis=bn_axis, name=name
|
103
|
+
x = layers.Concatenate(axis=bn_axis, name=f"{name}_concat")([x, x1])
|
104
104
|
return x
|
105
105
|
|
106
106
|
|
@@ -479,10 +479,10 @@ def block(
|
|
479
479
|
padding="same",
|
480
480
|
use_bias=False,
|
481
481
|
kernel_initializer=CONV_KERNEL_INITIALIZER,
|
482
|
-
name=name
|
482
|
+
name=f"{name}expand_conv",
|
483
483
|
)(inputs)
|
484
|
-
x = layers.BatchNormalization(axis=bn_axis, name=name
|
485
|
-
x = layers.Activation(activation, name=name
|
484
|
+
x = layers.BatchNormalization(axis=bn_axis, name=f"{name}expand_bn")(x)
|
485
|
+
x = layers.Activation(activation, name=f"{name}expand_activation")(x)
|
486
486
|
else:
|
487
487
|
x = inputs
|
488
488
|
|
@@ -490,7 +490,7 @@ def block(
|
|
490
490
|
if strides == 2:
|
491
491
|
x = layers.ZeroPadding2D(
|
492
492
|
padding=imagenet_utils.correct_pad(x, kernel_size),
|
493
|
-
name=name
|
493
|
+
name=f"{name}dwconv_pad",
|
494
494
|
)(x)
|
495
495
|
conv_pad = "valid"
|
496
496
|
else:
|
@@ -501,27 +501,27 @@ def block(
|
|
501
501
|
padding=conv_pad,
|
502
502
|
use_bias=False,
|
503
503
|
depthwise_initializer=CONV_KERNEL_INITIALIZER,
|
504
|
-
name=name
|
504
|
+
name=f"{name}dwconv",
|
505
505
|
)(x)
|
506
|
-
x = layers.BatchNormalization(axis=bn_axis, name=name
|
507
|
-
x = layers.Activation(activation, name=name
|
506
|
+
x = layers.BatchNormalization(axis=bn_axis, name=f"{name}bn")(x)
|
507
|
+
x = layers.Activation(activation, name=f"{name}activation")(x)
|
508
508
|
|
509
509
|
# Squeeze and Excitation phase
|
510
510
|
if 0 < se_ratio <= 1:
|
511
511
|
filters_se = max(1, int(filters_in * se_ratio))
|
512
|
-
se = layers.GlobalAveragePooling2D(name=name
|
512
|
+
se = layers.GlobalAveragePooling2D(name=f"{name}se_squeeze")(x)
|
513
513
|
if bn_axis == 1:
|
514
514
|
se_shape = (filters, 1, 1)
|
515
515
|
else:
|
516
516
|
se_shape = (1, 1, filters)
|
517
|
-
se = layers.Reshape(se_shape, name=name
|
517
|
+
se = layers.Reshape(se_shape, name=f"{name}se_reshape")(se)
|
518
518
|
se = layers.Conv2D(
|
519
519
|
filters_se,
|
520
520
|
1,
|
521
521
|
padding="same",
|
522
522
|
activation=activation,
|
523
523
|
kernel_initializer=CONV_KERNEL_INITIALIZER,
|
524
|
-
name=name
|
524
|
+
name=f"{name}se_reduce",
|
525
525
|
)(se)
|
526
526
|
se = layers.Conv2D(
|
527
527
|
filters,
|
@@ -529,9 +529,9 @@ def block(
|
|
529
529
|
padding="same",
|
530
530
|
activation="sigmoid",
|
531
531
|
kernel_initializer=CONV_KERNEL_INITIALIZER,
|
532
|
-
name=name
|
532
|
+
name=f"{name}se_expand",
|
533
533
|
)(se)
|
534
|
-
x = layers.multiply([x, se], name=name
|
534
|
+
x = layers.multiply([x, se], name=f"{name}se_excite")
|
535
535
|
|
536
536
|
# Output phase
|
537
537
|
x = layers.Conv2D(
|
@@ -540,15 +540,15 @@ def block(
|
|
540
540
|
padding="same",
|
541
541
|
use_bias=False,
|
542
542
|
kernel_initializer=CONV_KERNEL_INITIALIZER,
|
543
|
-
name=name
|
543
|
+
name=f"{name}project_conv",
|
544
544
|
)(x)
|
545
|
-
x = layers.BatchNormalization(axis=bn_axis, name=name
|
545
|
+
x = layers.BatchNormalization(axis=bn_axis, name=f"{name}project_bn")(x)
|
546
546
|
if id_skip and strides == 1 and filters_in == filters_out:
|
547
547
|
if drop_rate > 0:
|
548
548
|
x = layers.Dropout(
|
549
|
-
drop_rate, noise_shape=(None, 1, 1, 1), name=name
|
549
|
+
drop_rate, noise_shape=(None, 1, 1, 1), name=f"{name}drop"
|
550
550
|
)(x)
|
551
|
-
x = layers.add([x, inputs], name=name
|
551
|
+
x = layers.add([x, inputs], name=f"{name}add")
|
552
552
|
return x
|
553
553
|
|
554
554
|
|
@@ -632,14 +632,14 @@ def MBConvBlock(
|
|
632
632
|
padding="same",
|
633
633
|
data_format=backend.image_data_format(),
|
634
634
|
use_bias=False,
|
635
|
-
name=name
|
635
|
+
name=f"{name}expand_conv",
|
636
636
|
)(inputs)
|
637
637
|
x = layers.BatchNormalization(
|
638
638
|
axis=bn_axis,
|
639
639
|
momentum=bn_momentum,
|
640
|
-
name=name
|
640
|
+
name=f"{name}expand_bn",
|
641
641
|
)(x)
|
642
|
-
x = layers.Activation(activation, name=name
|
642
|
+
x = layers.Activation(activation, name=f"{name}expand_activation")(
|
643
643
|
x
|
644
644
|
)
|
645
645
|
else:
|
@@ -653,22 +653,22 @@ def MBConvBlock(
|
|
653
653
|
padding="same",
|
654
654
|
data_format=backend.image_data_format(),
|
655
655
|
use_bias=False,
|
656
|
-
name=name
|
656
|
+
name=f"{name}dwconv2",
|
657
657
|
)(x)
|
658
658
|
x = layers.BatchNormalization(
|
659
|
-
axis=bn_axis, momentum=bn_momentum, name=name
|
659
|
+
axis=bn_axis, momentum=bn_momentum, name=f"{name}bn"
|
660
660
|
)(x)
|
661
|
-
x = layers.Activation(activation, name=name
|
661
|
+
x = layers.Activation(activation, name=f"{name}activation")(x)
|
662
662
|
|
663
663
|
# Squeeze and excite
|
664
664
|
if 0 < se_ratio <= 1:
|
665
665
|
filters_se = max(1, int(input_filters * se_ratio))
|
666
|
-
se = layers.GlobalAveragePooling2D(name=name
|
666
|
+
se = layers.GlobalAveragePooling2D(name=f"{name}se_squeeze")(x)
|
667
667
|
if bn_axis == 1:
|
668
668
|
se_shape = (filters, 1, 1)
|
669
669
|
else:
|
670
670
|
se_shape = (1, 1, filters)
|
671
|
-
se = layers.Reshape(se_shape, name=name
|
671
|
+
se = layers.Reshape(se_shape, name=f"{name}se_reshape")(se)
|
672
672
|
|
673
673
|
se = layers.Conv2D(
|
674
674
|
filters_se,
|
@@ -676,7 +676,7 @@ def MBConvBlock(
|
|
676
676
|
padding="same",
|
677
677
|
activation=activation,
|
678
678
|
kernel_initializer=CONV_KERNEL_INITIALIZER,
|
679
|
-
name=name
|
679
|
+
name=f"{name}se_reduce",
|
680
680
|
)(se)
|
681
681
|
se = layers.Conv2D(
|
682
682
|
filters,
|
@@ -684,10 +684,10 @@ def MBConvBlock(
|
|
684
684
|
padding="same",
|
685
685
|
activation="sigmoid",
|
686
686
|
kernel_initializer=CONV_KERNEL_INITIALIZER,
|
687
|
-
name=name
|
687
|
+
name=f"{name}se_expand",
|
688
688
|
)(se)
|
689
689
|
|
690
|
-
x = layers.multiply([x, se], name=name
|
690
|
+
x = layers.multiply([x, se], name=f"{name}se_excite")
|
691
691
|
|
692
692
|
# Output phase
|
693
693
|
x = layers.Conv2D(
|
@@ -698,10 +698,10 @@ def MBConvBlock(
|
|
698
698
|
padding="same",
|
699
699
|
data_format=backend.image_data_format(),
|
700
700
|
use_bias=False,
|
701
|
-
name=name
|
701
|
+
name=f"{name}project_conv",
|
702
702
|
)(x)
|
703
703
|
x = layers.BatchNormalization(
|
704
|
-
axis=bn_axis, momentum=bn_momentum, name=name
|
704
|
+
axis=bn_axis, momentum=bn_momentum, name=f"{name}project_bn"
|
705
705
|
)(x)
|
706
706
|
|
707
707
|
if strides == 1 and input_filters == output_filters:
|
@@ -709,9 +709,9 @@ def MBConvBlock(
|
|
709
709
|
x = layers.Dropout(
|
710
710
|
survival_probability,
|
711
711
|
noise_shape=(None, 1, 1, 1),
|
712
|
-
name=name
|
712
|
+
name=f"{name}drop",
|
713
713
|
)(x)
|
714
|
-
x = layers.add([x, inputs], name=name
|
714
|
+
x = layers.add([x, inputs], name=f"{name}add")
|
715
715
|
|
716
716
|
return x
|
717
717
|
|
@@ -747,13 +747,13 @@ def FusedMBConvBlock(
|
|
747
747
|
data_format=backend.image_data_format(),
|
748
748
|
padding="same",
|
749
749
|
use_bias=False,
|
750
|
-
name=name
|
750
|
+
name=f"{name}expand_conv",
|
751
751
|
)(inputs)
|
752
752
|
x = layers.BatchNormalization(
|
753
|
-
axis=bn_axis, momentum=bn_momentum, name=name
|
753
|
+
axis=bn_axis, momentum=bn_momentum, name=f"{name}expand_bn"
|
754
754
|
)(x)
|
755
755
|
x = layers.Activation(
|
756
|
-
activation=activation, name=name
|
756
|
+
activation=activation, name=f"{name}expand_activation"
|
757
757
|
)(x)
|
758
758
|
else:
|
759
759
|
x = inputs
|
@@ -761,13 +761,13 @@ def FusedMBConvBlock(
|
|
761
761
|
# Squeeze and excite
|
762
762
|
if 0 < se_ratio <= 1:
|
763
763
|
filters_se = max(1, int(input_filters * se_ratio))
|
764
|
-
se = layers.GlobalAveragePooling2D(name=name
|
764
|
+
se = layers.GlobalAveragePooling2D(name=f"{name}se_squeeze")(x)
|
765
765
|
if bn_axis == 1:
|
766
766
|
se_shape = (filters, 1, 1)
|
767
767
|
else:
|
768
768
|
se_shape = (1, 1, filters)
|
769
769
|
|
770
|
-
se = layers.Reshape(se_shape, name=name
|
770
|
+
se = layers.Reshape(se_shape, name=f"{name}se_reshape")(se)
|
771
771
|
|
772
772
|
se = layers.Conv2D(
|
773
773
|
filters_se,
|
@@ -775,7 +775,7 @@ def FusedMBConvBlock(
|
|
775
775
|
padding="same",
|
776
776
|
activation=activation,
|
777
777
|
kernel_initializer=CONV_KERNEL_INITIALIZER,
|
778
|
-
name=name
|
778
|
+
name=f"{name}se_reduce",
|
779
779
|
)(se)
|
780
780
|
se = layers.Conv2D(
|
781
781
|
filters,
|
@@ -783,10 +783,10 @@ def FusedMBConvBlock(
|
|
783
783
|
padding="same",
|
784
784
|
activation="sigmoid",
|
785
785
|
kernel_initializer=CONV_KERNEL_INITIALIZER,
|
786
|
-
name=name
|
786
|
+
name=f"{name}se_expand",
|
787
787
|
)(se)
|
788
788
|
|
789
|
-
x = layers.multiply([x, se], name=name
|
789
|
+
x = layers.multiply([x, se], name=f"{name}se_excite")
|
790
790
|
|
791
791
|
# Output phase:
|
792
792
|
x = layers.Conv2D(
|
@@ -796,14 +796,14 @@ def FusedMBConvBlock(
|
|
796
796
|
kernel_initializer=CONV_KERNEL_INITIALIZER,
|
797
797
|
padding="same",
|
798
798
|
use_bias=False,
|
799
|
-
name=name
|
799
|
+
name=f"{name}project_conv",
|
800
800
|
)(x)
|
801
801
|
x = layers.BatchNormalization(
|
802
|
-
axis=bn_axis, momentum=bn_momentum, name=name
|
802
|
+
axis=bn_axis, momentum=bn_momentum, name=f"{name}project_bn"
|
803
803
|
)(x)
|
804
804
|
if expand_ratio == 1:
|
805
805
|
x = layers.Activation(
|
806
|
-
activation=activation, name=name
|
806
|
+
activation=activation, name=f"{name}project_activation"
|
807
807
|
)(x)
|
808
808
|
|
809
809
|
# Residual:
|
@@ -812,9 +812,9 @@ def FusedMBConvBlock(
|
|
812
812
|
x = layers.Dropout(
|
813
813
|
survival_probability,
|
814
814
|
noise_shape=(None, 1, 1, 1),
|
815
|
-
name=name
|
815
|
+
name=f"{name}drop",
|
816
816
|
)(x)
|
817
|
-
x = layers.add([x, inputs], name=name
|
817
|
+
x = layers.add([x, inputs], name=f"{name}add")
|
818
818
|
return x
|
819
819
|
|
820
820
|
return apply
|
@@ -281,12 +281,12 @@ def conv2d_bn(
|
|
281
281
|
)(x)
|
282
282
|
if not use_bias:
|
283
283
|
bn_axis = 1 if backend.image_data_format() == "channels_first" else 3
|
284
|
-
bn_name = None if name is None else name
|
284
|
+
bn_name = None if name is None else f"{name}_bn"
|
285
285
|
x = layers.BatchNormalization(axis=bn_axis, scale=False, name=bn_name)(
|
286
286
|
x
|
287
287
|
)
|
288
288
|
if activation is not None:
|
289
|
-
ac_name = None if name is None else name
|
289
|
+
ac_name = None if name is None else f"{name}_ac"
|
290
290
|
x = layers.Activation(activation, name=ac_name)(x)
|
291
291
|
return x
|
292
292
|
|
@@ -353,12 +353,12 @@ def inception_resnet_block(x, scale, block_type, block_idx, activation="relu"):
|
|
353
353
|
raise ValueError(
|
354
354
|
"Unknown Inception-ResNet block type. "
|
355
355
|
'Expects "block35", "block17" or "block8", '
|
356
|
-
"but got: "
|
356
|
+
f"but got: {block_type}"
|
357
357
|
)
|
358
358
|
|
359
|
-
block_name = block_type
|
359
|
+
block_name = f"{block_type}_{block_idx}"
|
360
360
|
channel_axis = 1 if backend.image_data_format() == "channels_first" else 3
|
361
|
-
mixed = layers.Concatenate(axis=channel_axis, name=block_name
|
361
|
+
mixed = layers.Concatenate(axis=channel_axis, name=f"{block_name}_mixed")(
|
362
362
|
branches
|
363
363
|
)
|
364
364
|
up = conv2d_bn(
|
@@ -367,12 +367,12 @@ def inception_resnet_block(x, scale, block_type, block_idx, activation="relu"):
|
|
367
367
|
1,
|
368
368
|
activation=None,
|
369
369
|
use_bias=True,
|
370
|
-
name=block_name
|
370
|
+
name=f"{block_name}_conv",
|
371
371
|
)
|
372
372
|
|
373
373
|
x = CustomScaleLayer(scale)([x, up])
|
374
374
|
if activation is not None:
|
375
|
-
x = layers.Activation(activation, name=block_name
|
375
|
+
x = layers.Activation(activation, name=f"{block_name}_ac")(x)
|
376
376
|
return x
|
377
377
|
|
378
378
|
|
@@ -263,7 +263,7 @@ def InceptionV3(
|
|
263
263
|
x = layers.concatenate(
|
264
264
|
[branch1x1, branch7x7, branch7x7dbl, branch_pool],
|
265
265
|
axis=channel_axis,
|
266
|
-
name="mixed"
|
266
|
+
name="mixed{0}".format(5 + i),
|
267
267
|
)
|
268
268
|
|
269
269
|
# mixed 7: 17 x 17 x 768
|
@@ -315,7 +315,7 @@ def InceptionV3(
|
|
315
315
|
branch3x3 = layers.concatenate(
|
316
316
|
[branch3x3_1, branch3x3_2],
|
317
317
|
axis=channel_axis,
|
318
|
-
name="mixed9_"
|
318
|
+
name=f"mixed9_{i}",
|
319
319
|
)
|
320
320
|
|
321
321
|
branch3x3dbl = conv2d_bn(x, 448, 1, 1)
|
@@ -333,7 +333,7 @@ def InceptionV3(
|
|
333
333
|
x = layers.concatenate(
|
334
334
|
[branch1x1, branch3x3, branch3x3dbl, branch_pool],
|
335
335
|
axis=channel_axis,
|
336
|
-
name="mixed
|
336
|
+
name=f"mixed{9 + i}",
|
337
337
|
)
|
338
338
|
if include_top:
|
339
339
|
# Classification block
|
@@ -400,8 +400,8 @@ def conv2d_bn(
|
|
400
400
|
Output tensor after applying `Conv2D` and `BatchNormalization`.
|
401
401
|
"""
|
402
402
|
if name is not None:
|
403
|
-
bn_name = name
|
404
|
-
conv_name = name
|
403
|
+
bn_name = f"{name}_bn"
|
404
|
+
conv_name = f"{name}_conv"
|
405
405
|
else:
|
406
406
|
bn_name = None
|
407
407
|
conv_name = None
|