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
@@ -369,11 +369,8 @@ def MobileNetV2(
|
|
369
369
|
if weights == "imagenet":
|
370
370
|
if include_top:
|
371
371
|
model_name = (
|
372
|
-
"
|
373
|
-
|
374
|
-
+ "_"
|
375
|
-
+ str(rows)
|
376
|
-
+ ".h5"
|
372
|
+
"mobilenet_v2_weights_tf_dim_ordering_tf_kernels"
|
373
|
+
f"_{float(alpha)}_{rows}.h5"
|
377
374
|
)
|
378
375
|
weight_path = BASE_WEIGHT_PATH + model_name
|
379
376
|
weights_path = file_utils.get_file(
|
@@ -382,11 +379,7 @@ def MobileNetV2(
|
|
382
379
|
else:
|
383
380
|
model_name = (
|
384
381
|
"mobilenet_v2_weights_tf_dim_ordering_tf_kernels_"
|
385
|
-
|
386
|
-
+ "_"
|
387
|
-
+ str(rows)
|
388
|
-
+ "_no_top"
|
389
|
-
+ ".h5"
|
382
|
+
f"{float(alpha)}_{rows}_no_top.h5"
|
390
383
|
)
|
391
384
|
weight_path = BASE_WEIGHT_PATH + model_name
|
392
385
|
weights_path = file_utils.get_file(
|
@@ -419,22 +412,22 @@ def _inverted_res_block(inputs, expansion, stride, alpha, filters, block_id):
|
|
419
412
|
padding="same",
|
420
413
|
use_bias=False,
|
421
414
|
activation=None,
|
422
|
-
name=prefix
|
415
|
+
name=f"{prefix}expand",
|
423
416
|
)(x)
|
424
417
|
x = layers.BatchNormalization(
|
425
418
|
axis=channel_axis,
|
426
419
|
epsilon=1e-3,
|
427
420
|
momentum=0.999,
|
428
|
-
name=prefix
|
421
|
+
name=f"{prefix}expand_BN",
|
429
422
|
)(x)
|
430
|
-
x = layers.ReLU(6.0, name=prefix
|
423
|
+
x = layers.ReLU(6.0, name=f"{prefix}expand_relu")(x)
|
431
424
|
else:
|
432
425
|
prefix = "expanded_conv_"
|
433
426
|
|
434
427
|
# Depthwise 3x3 convolution.
|
435
428
|
if stride == 2:
|
436
429
|
x = layers.ZeroPadding2D(
|
437
|
-
padding=imagenet_utils.correct_pad(x, 3), name=prefix
|
430
|
+
padding=imagenet_utils.correct_pad(x, 3), name=f"{prefix}pad"
|
438
431
|
)(x)
|
439
432
|
x = layers.DepthwiseConv2D(
|
440
433
|
kernel_size=3,
|
@@ -442,16 +435,16 @@ def _inverted_res_block(inputs, expansion, stride, alpha, filters, block_id):
|
|
442
435
|
activation=None,
|
443
436
|
use_bias=False,
|
444
437
|
padding="same" if stride == 1 else "valid",
|
445
|
-
name=prefix
|
438
|
+
name=f"{prefix}depthwise",
|
446
439
|
)(x)
|
447
440
|
x = layers.BatchNormalization(
|
448
441
|
axis=channel_axis,
|
449
442
|
epsilon=1e-3,
|
450
443
|
momentum=0.999,
|
451
|
-
name=prefix
|
444
|
+
name=f"{prefix}depthwise_BN",
|
452
445
|
)(x)
|
453
446
|
|
454
|
-
x = layers.ReLU(6.0, name=prefix
|
447
|
+
x = layers.ReLU(6.0, name=f"{prefix}depthwise_relu")(x)
|
455
448
|
|
456
449
|
# Project with a pointwise 1x1 convolution.
|
457
450
|
x = layers.Conv2D(
|
@@ -460,17 +453,17 @@ def _inverted_res_block(inputs, expansion, stride, alpha, filters, block_id):
|
|
460
453
|
padding="same",
|
461
454
|
use_bias=False,
|
462
455
|
activation=None,
|
463
|
-
name=prefix
|
456
|
+
name=f"{prefix}project",
|
464
457
|
)(x)
|
465
458
|
x = layers.BatchNormalization(
|
466
459
|
axis=channel_axis,
|
467
460
|
epsilon=1e-3,
|
468
461
|
momentum=0.999,
|
469
|
-
name=prefix
|
462
|
+
name=f"{prefix}project_BN",
|
470
463
|
)(x)
|
471
464
|
|
472
465
|
if in_channels == pointwise_filters and stride == 1:
|
473
|
-
return layers.Add(name=prefix
|
466
|
+
return layers.Add(name=f"{prefix}add")([inputs, x])
|
474
467
|
return x
|
475
468
|
|
476
469
|
|
@@ -385,10 +385,10 @@ def MobileNetV3(
|
|
385
385
|
model_type, "_minimalistic" if minimalistic else "", str(alpha)
|
386
386
|
)
|
387
387
|
if include_top:
|
388
|
-
file_name = "weights_mobilenet_v3_
|
388
|
+
file_name = f"weights_mobilenet_v3_{model_name}.h5"
|
389
389
|
file_hash = WEIGHTS_HASHES[model_name][0]
|
390
390
|
else:
|
391
|
-
file_name = "weights_mobilenet_v3_
|
391
|
+
file_name = f"weights_mobilenet_v3_{model_name}_no_top_v2.h5"
|
392
392
|
file_hash = WEIGHTS_HASHES[model_name][1]
|
393
393
|
weights_path = file_utils.get_file(
|
394
394
|
file_name,
|
@@ -570,23 +570,23 @@ def _depth(v, divisor=8, min_value=None):
|
|
570
570
|
|
571
571
|
def _se_block(inputs, filters, se_ratio, prefix):
|
572
572
|
x = layers.GlobalAveragePooling2D(
|
573
|
-
keepdims=True, name=prefix
|
573
|
+
keepdims=True, name=f"{prefix}squeeze_excite_avg_pool"
|
574
574
|
)(inputs)
|
575
575
|
x = layers.Conv2D(
|
576
576
|
_depth(filters * se_ratio),
|
577
577
|
kernel_size=1,
|
578
578
|
padding="same",
|
579
|
-
name=prefix
|
579
|
+
name=f"{prefix}squeeze_excite_conv",
|
580
580
|
)(x)
|
581
|
-
x = layers.ReLU(name=prefix
|
581
|
+
x = layers.ReLU(name=f"{prefix}squeeze_excite_relu")(x)
|
582
582
|
x = layers.Conv2D(
|
583
583
|
filters,
|
584
584
|
kernel_size=1,
|
585
585
|
padding="same",
|
586
|
-
name=prefix
|
586
|
+
name=f"{prefix}squeeze_excite_conv_1",
|
587
587
|
)(x)
|
588
588
|
x = hard_sigmoid(x)
|
589
|
-
x = layers.Multiply(name=prefix
|
589
|
+
x = layers.Multiply(name=f"{prefix}squeeze_excite_mul")([inputs, x])
|
590
590
|
return x
|
591
591
|
|
592
592
|
|
@@ -605,33 +605,33 @@ def _inverted_res_block(
|
|
605
605
|
kernel_size=1,
|
606
606
|
padding="same",
|
607
607
|
use_bias=False,
|
608
|
-
name=prefix
|
608
|
+
name=f"{prefix}expand",
|
609
609
|
)(x)
|
610
610
|
x = layers.BatchNormalization(
|
611
611
|
axis=channel_axis,
|
612
612
|
epsilon=1e-3,
|
613
613
|
momentum=0.999,
|
614
|
-
name=prefix
|
614
|
+
name=f"{prefix}expand_bn",
|
615
615
|
)(x)
|
616
616
|
x = activation(x)
|
617
617
|
|
618
618
|
if stride == 2:
|
619
619
|
x = layers.ZeroPadding2D(
|
620
620
|
padding=imagenet_utils.correct_pad(x, kernel_size),
|
621
|
-
name=prefix
|
621
|
+
name=f"{prefix}depthwise_pad",
|
622
622
|
)(x)
|
623
623
|
x = layers.DepthwiseConv2D(
|
624
624
|
kernel_size,
|
625
625
|
strides=stride,
|
626
626
|
padding="same" if stride == 1 else "valid",
|
627
627
|
use_bias=False,
|
628
|
-
name=prefix
|
628
|
+
name=f"{prefix}depthwise",
|
629
629
|
)(x)
|
630
630
|
x = layers.BatchNormalization(
|
631
631
|
axis=channel_axis,
|
632
632
|
epsilon=1e-3,
|
633
633
|
momentum=0.999,
|
634
|
-
name=prefix
|
634
|
+
name=f"{prefix}depthwise_bn",
|
635
635
|
)(x)
|
636
636
|
x = activation(x)
|
637
637
|
|
@@ -643,17 +643,17 @@ def _inverted_res_block(
|
|
643
643
|
kernel_size=1,
|
644
644
|
padding="same",
|
645
645
|
use_bias=False,
|
646
|
-
name=prefix
|
646
|
+
name=f"{prefix}project",
|
647
647
|
)(x)
|
648
648
|
x = layers.BatchNormalization(
|
649
649
|
axis=channel_axis,
|
650
650
|
epsilon=1e-3,
|
651
651
|
momentum=0.999,
|
652
|
-
name=prefix
|
652
|
+
name=f"{prefix}project_bn",
|
653
653
|
)(x)
|
654
654
|
|
655
655
|
if stride == 1 and infilters == filters:
|
656
|
-
x = layers.Add(name=prefix
|
656
|
+
x = layers.Add(name=f"{prefix}add")([shortcut, x])
|
657
657
|
return x
|
658
658
|
|
659
659
|
|
keras/src/applications/nasnet.py
CHANGED
@@ -11,10 +11,10 @@ from keras.src.utils import file_utils
|
|
11
11
|
BASE_WEIGHTS_PATH = (
|
12
12
|
"https://storage.googleapis.com/tensorflow/keras-applications/nasnet/"
|
13
13
|
)
|
14
|
-
NASNET_MOBILE_WEIGHT_PATH = BASE_WEIGHTS_PATH
|
15
|
-
NASNET_MOBILE_WEIGHT_PATH_NO_TOP = BASE_WEIGHTS_PATH
|
16
|
-
NASNET_LARGE_WEIGHT_PATH = BASE_WEIGHTS_PATH
|
17
|
-
NASNET_LARGE_WEIGHT_PATH_NO_TOP = BASE_WEIGHTS_PATH
|
14
|
+
NASNET_MOBILE_WEIGHT_PATH = f"{BASE_WEIGHTS_PATH}NASNet-mobile.h5"
|
15
|
+
NASNET_MOBILE_WEIGHT_PATH_NO_TOP = f"{BASE_WEIGHTS_PATH}NASNet-mobile-no-top.h5"
|
16
|
+
NASNET_LARGE_WEIGHT_PATH = f"{BASE_WEIGHTS_PATH}NASNet-large.h5"
|
17
|
+
NASNET_LARGE_WEIGHT_PATH_NO_TOP = f"{BASE_WEIGHTS_PATH}NASNet-large-no-top.h5"
|
18
18
|
|
19
19
|
|
20
20
|
def NASNet(
|
@@ -137,10 +137,9 @@ def NASNet(
|
|
137
137
|
and weights == "imagenet"
|
138
138
|
):
|
139
139
|
raise ValueError(
|
140
|
-
"When specifying the input shape of a NASNet"
|
141
|
-
"
|
142
|
-
"
|
143
|
-
"(no None entries). Got: `input_shape=" + str(input_shape) + "`."
|
140
|
+
"When specifying the input shape of a NASNet and loading "
|
141
|
+
"`ImageNet` weights, the input_shape argument must be static"
|
142
|
+
f" (no None entries). Got: `input_shape={input_shape}`."
|
144
143
|
)
|
145
144
|
|
146
145
|
if default_size is None:
|
keras/src/applications/resnet.py
CHANGED
@@ -196,16 +196,16 @@ def ResNet(
|
|
196
196
|
# Load weights.
|
197
197
|
if (weights == "imagenet") and (weights_name in WEIGHTS_HASHES):
|
198
198
|
if include_top:
|
199
|
-
file_name = weights_name
|
199
|
+
file_name = f"{weights_name}_weights_tf_dim_ordering_tf_kernels.h5"
|
200
200
|
file_hash = WEIGHTS_HASHES[weights_name][0]
|
201
201
|
else:
|
202
202
|
file_name = (
|
203
|
-
weights_name
|
203
|
+
f"{weights_name}_weights_tf_dim_ordering_tf_kernels_notop.h5"
|
204
204
|
)
|
205
205
|
file_hash = WEIGHTS_HASHES[weights_name][1]
|
206
206
|
weights_path = file_utils.get_file(
|
207
207
|
file_name,
|
208
|
-
BASE_WEIGHTS_PATH
|
208
|
+
f"{BASE_WEIGHTS_PATH}{file_name}",
|
209
209
|
cache_subdir="models",
|
210
210
|
file_hash=file_hash,
|
211
211
|
)
|
@@ -241,35 +241,35 @@ def residual_block_v1(
|
|
241
241
|
|
242
242
|
if conv_shortcut:
|
243
243
|
shortcut = layers.Conv2D(
|
244
|
-
4 * filters, 1, strides=stride, name=name
|
244
|
+
4 * filters, 1, strides=stride, name=f"{name}_0_conv"
|
245
245
|
)(x)
|
246
246
|
shortcut = layers.BatchNormalization(
|
247
|
-
axis=bn_axis, epsilon=1.001e-5, name=name
|
247
|
+
axis=bn_axis, epsilon=1.001e-5, name=f"{name}_0_bn"
|
248
248
|
)(shortcut)
|
249
249
|
else:
|
250
250
|
shortcut = x
|
251
251
|
|
252
|
-
x = layers.Conv2D(filters, 1, strides=stride, name=name
|
252
|
+
x = layers.Conv2D(filters, 1, strides=stride, name=f"{name}_1_conv")(x)
|
253
253
|
x = layers.BatchNormalization(
|
254
|
-
axis=bn_axis, epsilon=1.001e-5, name=name
|
254
|
+
axis=bn_axis, epsilon=1.001e-5, name=f"{name}_1_bn"
|
255
255
|
)(x)
|
256
|
-
x = layers.Activation("relu", name=name
|
256
|
+
x = layers.Activation("relu", name=f"{name}_1_relu")(x)
|
257
257
|
|
258
258
|
x = layers.Conv2D(
|
259
|
-
filters, kernel_size, padding="SAME", name=name
|
259
|
+
filters, kernel_size, padding="SAME", name=f"{name}_2_conv"
|
260
260
|
)(x)
|
261
261
|
x = layers.BatchNormalization(
|
262
|
-
axis=bn_axis, epsilon=1.001e-5, name=name
|
262
|
+
axis=bn_axis, epsilon=1.001e-5, name=f"{name}_2_bn"
|
263
263
|
)(x)
|
264
|
-
x = layers.Activation("relu", name=name
|
264
|
+
x = layers.Activation("relu", name=f"{name}_2_relu")(x)
|
265
265
|
|
266
|
-
x = layers.Conv2D(4 * filters, 1, name=name
|
266
|
+
x = layers.Conv2D(4 * filters, 1, name=f"{name}_3_conv")(x)
|
267
267
|
x = layers.BatchNormalization(
|
268
|
-
axis=bn_axis, epsilon=1.001e-5, name=name
|
268
|
+
axis=bn_axis, epsilon=1.001e-5, name=f"{name}_3_bn"
|
269
269
|
)(x)
|
270
270
|
|
271
|
-
x = layers.Add(name=name
|
272
|
-
x = layers.Activation("relu", name=name
|
271
|
+
x = layers.Add(name=f"{name}_add")([shortcut, x])
|
272
|
+
x = layers.Activation("relu", name=f"{name}_out")(x)
|
273
273
|
return x
|
274
274
|
|
275
275
|
|
@@ -287,10 +287,10 @@ def stack_residual_blocks_v1(x, filters, blocks, stride1=2, name=None):
|
|
287
287
|
Output tensor for the stacked blocks.
|
288
288
|
"""
|
289
289
|
|
290
|
-
x = residual_block_v1(x, filters, stride=stride1, name=name
|
290
|
+
x = residual_block_v1(x, filters, stride=stride1, name=f"{name}_block1")
|
291
291
|
for i in range(2, blocks + 1):
|
292
292
|
x = residual_block_v1(
|
293
|
-
x, filters, conv_shortcut=False, name=name
|
293
|
+
x, filters, conv_shortcut=False, name=f"{name}_block{i}"
|
294
294
|
)
|
295
295
|
return x
|
296
296
|
|
@@ -319,13 +319,13 @@ def residual_block_v2(
|
|
319
319
|
bn_axis = 1
|
320
320
|
|
321
321
|
preact = layers.BatchNormalization(
|
322
|
-
axis=bn_axis, epsilon=1.001e-5, name=name
|
322
|
+
axis=bn_axis, epsilon=1.001e-5, name=f"{name}_preact_bn"
|
323
323
|
)(x)
|
324
|
-
preact = layers.Activation("relu", name=name
|
324
|
+
preact = layers.Activation("relu", name=f"{name}_preact_relu")(preact)
|
325
325
|
|
326
326
|
if conv_shortcut:
|
327
327
|
shortcut = layers.Conv2D(
|
328
|
-
4 * filters, 1, strides=stride, name=name
|
328
|
+
4 * filters, 1, strides=stride, name=f"{name}_0_conv"
|
329
329
|
)(preact)
|
330
330
|
else:
|
331
331
|
shortcut = (
|
@@ -333,28 +333,28 @@ def residual_block_v2(
|
|
333
333
|
)
|
334
334
|
|
335
335
|
x = layers.Conv2D(
|
336
|
-
filters, 1, strides=1, use_bias=False, name=name
|
336
|
+
filters, 1, strides=1, use_bias=False, name=f"{name}_1_conv"
|
337
337
|
)(preact)
|
338
338
|
x = layers.BatchNormalization(
|
339
|
-
axis=bn_axis, epsilon=1.001e-5, name=name
|
339
|
+
axis=bn_axis, epsilon=1.001e-5, name=f"{name}_1_bn"
|
340
340
|
)(x)
|
341
|
-
x = layers.Activation("relu", name=name
|
341
|
+
x = layers.Activation("relu", name=f"{name}_1_relu")(x)
|
342
342
|
|
343
|
-
x = layers.ZeroPadding2D(padding=((1, 1), (1, 1)), name=name
|
343
|
+
x = layers.ZeroPadding2D(padding=((1, 1), (1, 1)), name=f"{name}_2_pad")(x)
|
344
344
|
x = layers.Conv2D(
|
345
345
|
filters,
|
346
346
|
kernel_size,
|
347
347
|
strides=stride,
|
348
348
|
use_bias=False,
|
349
|
-
name=name
|
349
|
+
name=f"{name}_2_conv",
|
350
350
|
)(x)
|
351
351
|
x = layers.BatchNormalization(
|
352
|
-
axis=bn_axis, epsilon=1.001e-5, name=name
|
352
|
+
axis=bn_axis, epsilon=1.001e-5, name=f"{name}_2_bn"
|
353
353
|
)(x)
|
354
|
-
x = layers.Activation("relu", name=name
|
354
|
+
x = layers.Activation("relu", name=f"{name}_2_relu")(x)
|
355
355
|
|
356
|
-
x = layers.Conv2D(4 * filters, 1, name=name
|
357
|
-
x = layers.Add(name=name
|
356
|
+
x = layers.Conv2D(4 * filters, 1, name=f"{name}_3_conv")(x)
|
357
|
+
x = layers.Add(name=f"{name}_out")([shortcut, x])
|
358
358
|
return x
|
359
359
|
|
360
360
|
|
@@ -372,11 +372,11 @@ def stack_residual_blocks_v2(x, filters, blocks, stride1=2, name=None):
|
|
372
372
|
Output tensor for the stacked blocks.
|
373
373
|
"""
|
374
374
|
|
375
|
-
x = residual_block_v2(x, filters, conv_shortcut=True, name=name
|
375
|
+
x = residual_block_v2(x, filters, conv_shortcut=True, name=f"{name}_block1")
|
376
376
|
for i in range(2, blocks):
|
377
|
-
x = residual_block_v2(x, filters, name=name
|
377
|
+
x = residual_block_v2(x, filters, name=f"{name}_block{i}")
|
378
378
|
x = residual_block_v2(
|
379
|
-
x, filters, stride=stride1, name=name
|
379
|
+
x, filters, stride=stride1, name=f"{name}_block{str(blocks)}"
|
380
380
|
)
|
381
381
|
return x
|
382
382
|
|
@@ -212,40 +212,40 @@ def Xception(
|
|
212
212
|
|
213
213
|
for i in range(8):
|
214
214
|
residual = x
|
215
|
-
prefix = "block
|
215
|
+
prefix = f"block{i + 5}"
|
216
216
|
|
217
|
-
x = layers.Activation("relu", name=prefix
|
217
|
+
x = layers.Activation("relu", name=f"{prefix}_sepconv1_act")(x)
|
218
218
|
x = layers.SeparableConv2D(
|
219
219
|
728,
|
220
220
|
(3, 3),
|
221
221
|
padding="same",
|
222
222
|
use_bias=False,
|
223
|
-
name=prefix
|
223
|
+
name=f"{prefix}_sepconv1",
|
224
224
|
)(x)
|
225
225
|
x = layers.BatchNormalization(
|
226
|
-
axis=channel_axis, name=prefix
|
226
|
+
axis=channel_axis, name=f"{prefix}_sepconv1_bn"
|
227
227
|
)(x)
|
228
|
-
x = layers.Activation("relu", name=prefix
|
228
|
+
x = layers.Activation("relu", name=f"{prefix}_sepconv2_act")(x)
|
229
229
|
x = layers.SeparableConv2D(
|
230
230
|
728,
|
231
231
|
(3, 3),
|
232
232
|
padding="same",
|
233
233
|
use_bias=False,
|
234
|
-
name=prefix
|
234
|
+
name=f"{prefix}_sepconv2",
|
235
235
|
)(x)
|
236
236
|
x = layers.BatchNormalization(
|
237
|
-
axis=channel_axis, name=prefix
|
237
|
+
axis=channel_axis, name=f"{prefix}_sepconv2_bn"
|
238
238
|
)(x)
|
239
|
-
x = layers.Activation("relu", name=prefix
|
239
|
+
x = layers.Activation("relu", name=f"{prefix}_sepconv3_act")(x)
|
240
240
|
x = layers.SeparableConv2D(
|
241
241
|
728,
|
242
242
|
(3, 3),
|
243
243
|
padding="same",
|
244
244
|
use_bias=False,
|
245
|
-
name=prefix
|
245
|
+
name=f"{prefix}_sepconv3",
|
246
246
|
)(x)
|
247
247
|
x = layers.BatchNormalization(
|
248
|
-
axis=channel_axis, name=prefix
|
248
|
+
axis=channel_axis, name=f"{prefix}_sepconv3_bn"
|
249
249
|
)(x)
|
250
250
|
|
251
251
|
x = layers.add([x, residual])
|
@@ -225,11 +225,11 @@ def _resolve_weak_type(dtype, precision="32"):
|
|
225
225
|
if dtype_indicator == "b":
|
226
226
|
return "bool"
|
227
227
|
elif dtype_indicator == "i":
|
228
|
-
return "int"
|
228
|
+
return f"int{precision}"
|
229
229
|
elif dtype_indicator == "u":
|
230
|
-
return "uint"
|
230
|
+
return f"uint{precision}"
|
231
231
|
else:
|
232
|
-
return "float"
|
232
|
+
return f"float{precision}"
|
233
233
|
|
234
234
|
|
235
235
|
BIT64_TO_BIT16_DTYPE = {
|
@@ -244,6 +244,7 @@ BIT64_TO_BIT32_DTYPE = {
|
|
244
244
|
"int64": "int32",
|
245
245
|
"uint64": "uint32",
|
246
246
|
"float64": "float32",
|
247
|
+
"complex128": "complex64",
|
247
248
|
}
|
248
249
|
|
249
250
|
|
@@ -275,6 +276,10 @@ def _lattice_result_type(*args):
|
|
275
276
|
precision = config.floatx()[-2:]
|
276
277
|
if out_weak_type:
|
277
278
|
out_dtype = _resolve_weak_type(out_dtype, precision=precision)
|
279
|
+
|
280
|
+
# Force to be 32-bit dtype when encountering 64-bit dtype.
|
281
|
+
# TODO(hongyu): Add a config to enable 64-bit dtypes.
|
282
|
+
out_dtype = BIT64_TO_BIT32_DTYPE.get(out_dtype, out_dtype)
|
278
283
|
return out_dtype
|
279
284
|
|
280
285
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
import os.path
|
2
|
+
|
1
3
|
import numpy as np
|
2
4
|
|
3
5
|
from keras.src import backend
|
@@ -142,7 +144,7 @@ class Variable:
|
|
142
144
|
self._name = name
|
143
145
|
parent_path = current_path()
|
144
146
|
if parent_path:
|
145
|
-
self._path = current_path()
|
147
|
+
self._path = os.path.join(current_path(), name)
|
146
148
|
else:
|
147
149
|
self._path = name
|
148
150
|
self._shape = None
|
keras/src/backend/jax/export.py
CHANGED
keras/src/backend/jax/numpy.py
CHANGED
@@ -58,6 +58,12 @@ def heaviside(x1, x2):
|
|
58
58
|
return jnp.heaviside(x1, x2)
|
59
59
|
|
60
60
|
|
61
|
+
def hypot(x1, x2):
|
62
|
+
x1 = convert_to_tensor(x1)
|
63
|
+
x2 = convert_to_tensor(x2)
|
64
|
+
return jnp.hypot(x1, x2)
|
65
|
+
|
66
|
+
|
61
67
|
def kaiser(x, beta):
|
62
68
|
x = convert_to_tensor(x)
|
63
69
|
return cast(jnp.kaiser(x, beta), config.floatx())
|
keras/src/backend/jax/trainer.py
CHANGED
@@ -504,7 +504,7 @@ class JAXTrainer(base_trainer.Trainer):
|
|
504
504
|
_use_cached_eval_dataset=True,
|
505
505
|
)
|
506
506
|
val_logs = {
|
507
|
-
"val_"
|
507
|
+
f"val_{name}": val for name, val in val_logs.items()
|
508
508
|
}
|
509
509
|
epoch_logs.update(val_logs)
|
510
510
|
|
keras/src/backend/numpy/numpy.py
CHANGED
@@ -372,6 +372,9 @@ def bincount(x, weights=None, minlength=0, sparse=False):
|
|
372
372
|
def bitwise_and(x, y):
|
373
373
|
x = convert_to_tensor(x)
|
374
374
|
y = convert_to_tensor(y)
|
375
|
+
dtype = dtypes.result_type(x.dtype, y.dtype)
|
376
|
+
x = x.astype(dtype)
|
377
|
+
y = y.astype(dtype)
|
375
378
|
return np.bitwise_and(x, y)
|
376
379
|
|
377
380
|
|
@@ -387,12 +390,18 @@ def bitwise_not(x):
|
|
387
390
|
def bitwise_or(x, y):
|
388
391
|
x = convert_to_tensor(x)
|
389
392
|
y = convert_to_tensor(y)
|
393
|
+
dtype = dtypes.result_type(x.dtype, y.dtype)
|
394
|
+
x = x.astype(dtype)
|
395
|
+
y = y.astype(dtype)
|
390
396
|
return np.bitwise_or(x, y)
|
391
397
|
|
392
398
|
|
393
399
|
def bitwise_xor(x, y):
|
394
400
|
x = convert_to_tensor(x)
|
395
401
|
y = convert_to_tensor(y)
|
402
|
+
dtype = dtypes.result_type(x.dtype, y.dtype)
|
403
|
+
x = x.astype(dtype)
|
404
|
+
y = y.astype(dtype)
|
396
405
|
return np.bitwise_xor(x, y)
|
397
406
|
|
398
407
|
|
@@ -400,6 +409,9 @@ def bitwise_left_shift(x, y):
|
|
400
409
|
x = convert_to_tensor(x)
|
401
410
|
if not isinstance(y, int):
|
402
411
|
y = convert_to_tensor(y)
|
412
|
+
dtype = dtypes.result_type(x.dtype, y.dtype)
|
413
|
+
x = x.astype(dtype)
|
414
|
+
y = y.astype(dtype)
|
403
415
|
return np.left_shift(x, y)
|
404
416
|
|
405
417
|
|
@@ -411,6 +423,9 @@ def bitwise_right_shift(x, y):
|
|
411
423
|
x = convert_to_tensor(x)
|
412
424
|
if not isinstance(y, int):
|
413
425
|
y = convert_to_tensor(y)
|
426
|
+
dtype = dtypes.result_type(x.dtype, y.dtype)
|
427
|
+
x = x.astype(dtype)
|
428
|
+
y = y.astype(dtype)
|
414
429
|
return np.right_shift(x, y)
|
415
430
|
|
416
431
|
|
@@ -665,6 +680,19 @@ def hstack(xs):
|
|
665
680
|
return np.hstack(xs)
|
666
681
|
|
667
682
|
|
683
|
+
def hypot(x1, x2):
|
684
|
+
x1 = convert_to_tensor(x1)
|
685
|
+
x2 = convert_to_tensor(x2)
|
686
|
+
|
687
|
+
dtype = dtypes.result_type(x1.dtype, x2.dtype)
|
688
|
+
if dtype in ["int8", "int16", "int32", "uint8", "uint16", "uint32"]:
|
689
|
+
dtype = config.floatx()
|
690
|
+
elif dtype in ["int64"]:
|
691
|
+
dtype = "float64"
|
692
|
+
|
693
|
+
return np.hypot(x1, x2).astype(dtype)
|
694
|
+
|
695
|
+
|
668
696
|
def identity(n, dtype=None):
|
669
697
|
dtype = dtype or config.floatx()
|
670
698
|
return np.identity(n, dtype=dtype)
|
@@ -687,7 +687,7 @@ def diff(a, n=1, axis=-1):
|
|
687
687
|
if n == 0:
|
688
688
|
return OpenVINOKerasTensor(get_ov_output(a))
|
689
689
|
if n < 0:
|
690
|
-
raise ValueError("order must be non-negative but got
|
690
|
+
raise ValueError(f"order must be non-negative but got {repr(n)}")
|
691
691
|
a = get_ov_output(a)
|
692
692
|
a_type = a.get_element_type()
|
693
693
|
if isinstance(a, np.ndarray):
|
@@ -902,6 +902,10 @@ def hstack(xs):
|
|
902
902
|
return OpenVINOKerasTensor(ov_opset.concat(elems, axis).output(0))
|
903
903
|
|
904
904
|
|
905
|
+
def hypot(x1, x2):
|
906
|
+
raise NotImplementedError("`hypot` is not supported with openvino backend")
|
907
|
+
|
908
|
+
|
905
909
|
def identity(n, dtype=None):
|
906
910
|
n = get_ov_output(n)
|
907
911
|
dtype = Type.f32 if dtype is None else dtype
|
@@ -1559,6 +1559,28 @@ def hstack(xs):
|
|
1559
1559
|
return tf.concat(xs, axis=1)
|
1560
1560
|
|
1561
1561
|
|
1562
|
+
def hypot(x1, x2):
|
1563
|
+
x1 = convert_to_tensor(x1)
|
1564
|
+
x2 = convert_to_tensor(x2)
|
1565
|
+
|
1566
|
+
dtype = dtypes.result_type(x1.dtype, x2.dtype)
|
1567
|
+
if dtype in ["int8", "int16", "int32", "uint8", "uint16", "uint32"]:
|
1568
|
+
dtype = config.floatx()
|
1569
|
+
elif dtype in ["int64"]:
|
1570
|
+
dtype = "float64"
|
1571
|
+
|
1572
|
+
x1 = tf.cast(x1, dtype)
|
1573
|
+
x2 = tf.cast(x2, dtype)
|
1574
|
+
|
1575
|
+
x1_abs = tf.abs(x1)
|
1576
|
+
x2_abs = tf.abs(x2)
|
1577
|
+
max_val = tf.maximum(x1_abs, x2_abs)
|
1578
|
+
min_val = tf.minimum(x1_abs, x2_abs)
|
1579
|
+
|
1580
|
+
ratio = tf.math.divide_no_nan(min_val, max_val)
|
1581
|
+
return max_val * tf.sqrt(1.0 + tf.square(ratio))
|
1582
|
+
|
1583
|
+
|
1562
1584
|
def identity(n, dtype=None):
|
1563
1585
|
return eye(N=n, M=n, dtype=dtype)
|
1564
1586
|
|