keras-nightly 3.12.0.dev2025082703__py3-none-any.whl → 3.12.0.dev2025082903__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.
@@ -682,7 +682,9 @@ def gaussian_blur(
682
682
  ):
683
683
  def _create_gaussian_kernel(kernel_size, sigma, dtype):
684
684
  def _get_gaussian_kernel1d(size, sigma):
685
- x = jnp.arange(size, dtype=dtype) - (size - 1) / 2
685
+ x = jnp.arange(size, dtype=dtype) - jnp.array(
686
+ (size - 1) / 2, dtype=dtype
687
+ )
686
688
  kernel1d = jnp.exp(-0.5 * (x / sigma) ** 2)
687
689
  return kernel1d / jnp.sum(kernel1d)
688
690
 
@@ -697,8 +699,8 @@ def gaussian_blur(
697
699
  return kernel
698
700
 
699
701
  images = convert_to_tensor(images)
700
- sigma = convert_to_tensor(sigma)
701
- dtype = images.dtype
702
+ dtype = backend.standardize_dtype(images.dtype)
703
+ sigma = convert_to_tensor(sigma, dtype=dtype)
702
704
 
703
705
  if len(images.shape) not in (3, 4):
704
706
  raise ValueError(
@@ -560,6 +560,7 @@ def affine_transform(
560
560
  f"{AFFINE_TRANSFORM_FILL_MODES}. Received: fill_mode={fill_mode}"
561
561
  )
562
562
 
563
+ images = convert_to_tensor(images)
563
564
  transform = convert_to_tensor(transform)
564
565
 
565
566
  if len(images.shape) not in (3, 4):
@@ -575,10 +576,11 @@ def affine_transform(
575
576
  f"transform.shape={transform.shape}"
576
577
  )
577
578
 
578
- # scipy.ndimage.map_coordinates lacks support for half precision.
579
- input_dtype = images.dtype
580
- if input_dtype == "float16":
581
- images = images.astype("float32")
579
+ # `scipy.ndimage.map_coordinates` lacks support for float16 and bfloat16.
580
+ input_dtype = backend.standardize_dtype(images.dtype)
581
+ compute_dtype = backend.result_type(input_dtype, "float32")
582
+ images = images.astype(compute_dtype)
583
+ transform = transform.astype(compute_dtype)
582
584
 
583
585
  # unbatched case
584
586
  need_squeeze = False
@@ -622,7 +624,7 @@ def affine_transform(
622
624
  # transform the indices
623
625
  coordinates = np.einsum("Bhwij, Bjk -> Bhwik", indices, transform)
624
626
  coordinates = np.moveaxis(coordinates, source=-1, destination=1)
625
- coordinates += np.reshape(offset, newshape=(*offset.shape, 1, 1, 1))
627
+ coordinates += np.reshape(offset, (*offset.shape, 1, 1, 1))
626
628
 
627
629
  # apply affine transformation
628
630
  affined = np.stack(
@@ -643,9 +645,7 @@ def affine_transform(
643
645
  affined = np.transpose(affined, (0, 3, 1, 2))
644
646
  if need_squeeze:
645
647
  affined = np.squeeze(affined, axis=0)
646
- if input_dtype == "float16":
647
- affined = affined.astype(input_dtype)
648
- return affined
648
+ return affined.astype(input_dtype)
649
649
 
650
650
 
651
651
  def perspective_transform(
@@ -758,6 +758,14 @@ def perspective_transform(
758
758
 
759
759
 
760
760
  def compute_homography_matrix(start_points, end_points):
761
+ start_points = convert_to_tensor(start_points)
762
+ end_points = convert_to_tensor(end_points)
763
+ dtype = backend.result_type(start_points.dtype, end_points.dtype, float)
764
+ # `np.linalg.solve` lacks support for float16 and bfloat16.
765
+ compute_dtype = backend.result_type(dtype, "float32")
766
+ start_points = start_points.astype(dtype)
767
+ end_points = end_points.astype(dtype)
768
+
761
769
  start_x1, start_y1 = start_points[:, 0, 0], start_points[:, 0, 1]
762
770
  start_x2, start_y2 = start_points[:, 1, 0], start_points[:, 1, 1]
763
771
  start_x3, start_y3 = start_points[:, 2, 0], start_points[:, 2, 1]
@@ -892,11 +900,11 @@ def compute_homography_matrix(start_points, end_points):
892
900
  axis=-1,
893
901
  )
894
902
  target_vector = np.expand_dims(target_vector, axis=-1)
895
-
903
+ coefficient_matrix = coefficient_matrix.astype(compute_dtype)
904
+ target_vector = target_vector.astype(compute_dtype)
896
905
  homography_matrix = np.linalg.solve(coefficient_matrix, target_vector)
897
906
  homography_matrix = np.reshape(homography_matrix, [-1, 8])
898
-
899
- return homography_matrix
907
+ return homography_matrix.astype(dtype)
900
908
 
901
909
 
902
910
  def map_coordinates(
@@ -950,10 +958,14 @@ def map_coordinates(
950
958
  )
951
959
  else:
952
960
  padded = np.pad(inputs, padding, mode=pad_mode)
961
+
962
+ # `scipy.ndimage.map_coordinates` lacks support for float16 and bfloat16.
963
+ if backend.is_float_dtype(padded.dtype):
964
+ padded = padded.astype("float32")
953
965
  result = scipy.ndimage.map_coordinates(
954
966
  padded, shifted_coords, order=order, mode=fill_mode, cval=fill_value
955
967
  )
956
- return result
968
+ return result.astype(inputs.dtype)
957
969
 
958
970
 
959
971
  def gaussian_blur(
@@ -979,7 +991,11 @@ def gaussian_blur(
979
991
  images = convert_to_tensor(images)
980
992
  kernel_size = convert_to_tensor(kernel_size)
981
993
  sigma = convert_to_tensor(sigma)
982
- input_dtype = images.dtype
994
+ input_dtype = backend.standardize_dtype(images.dtype)
995
+ # `scipy.signal.convolve2d` lacks support for float16 and bfloat16.
996
+ compute_dtype = backend.result_type(input_dtype, "float32")
997
+ images = images.astype(compute_dtype)
998
+ sigma = sigma.astype(compute_dtype)
983
999
 
984
1000
  if len(images.shape) not in (3, 4):
985
1001
  raise ValueError(
@@ -1022,8 +1038,7 @@ def gaussian_blur(
1022
1038
  blurred_images = np.transpose(blurred_images, (0, 3, 1, 2))
1023
1039
  if need_squeeze:
1024
1040
  blurred_images = np.squeeze(blurred_images, axis=0)
1025
-
1026
- return blurred_images
1041
+ return blurred_images.astype(input_dtype)
1027
1042
 
1028
1043
 
1029
1044
  def elastic_transform(
@@ -761,9 +761,9 @@ def gaussian_blur(
761
761
  return kernel
762
762
 
763
763
  images = convert_to_tensor(images)
764
- kernel_size = convert_to_tensor(kernel_size)
765
- sigma = convert_to_tensor(sigma)
766
- dtype = images.dtype
764
+ dtype = backend.standardize_dtype(images.dtype)
765
+ kernel_size = convert_to_tensor(kernel_size, dtype=dtype)
766
+ sigma = convert_to_tensor(sigma, dtype=dtype)
767
767
 
768
768
  if len(images.shape) not in (3, 4):
769
769
  raise ValueError(
@@ -468,8 +468,9 @@ def perspective_transform(
468
468
  data_format = backend.standardize_data_format(data_format)
469
469
 
470
470
  images = convert_to_tensor(images)
471
- start_points = torch.tensor(start_points, dtype=torch.float32)
472
- end_points = torch.tensor(end_points, dtype=torch.float32)
471
+ dtype = backend.standardize_dtype(images.dtype)
472
+ start_points = convert_to_tensor(start_points, dtype=dtype)
473
+ end_points = convert_to_tensor(end_points, dtype=dtype)
473
474
 
474
475
  if interpolation not in AFFINE_TRANSFORM_INTERPOLATIONS.keys():
475
476
  raise ValueError(
@@ -525,13 +526,15 @@ def perspective_transform(
525
526
  transforms = transforms.repeat(batch_size, 1)
526
527
 
527
528
  grid_x, grid_y = torch.meshgrid(
528
- torch.arange(width, dtype=torch.float32, device=images.device),
529
- torch.arange(height, dtype=torch.float32, device=images.device),
529
+ torch.arange(width, dtype=to_torch_dtype(dtype), device=images.device),
530
+ torch.arange(height, dtype=to_torch_dtype(dtype), device=images.device),
530
531
  indexing="xy",
531
532
  )
532
533
 
533
534
  output = torch.empty(
534
- [batch_size, height, width, channels], device=images.device
535
+ [batch_size, height, width, channels],
536
+ dtype=to_torch_dtype(dtype),
537
+ device=images.device,
535
538
  )
536
539
 
537
540
  for i in range(batch_size):
@@ -563,8 +566,13 @@ def perspective_transform(
563
566
 
564
567
 
565
568
  def compute_homography_matrix(start_points, end_points):
566
- start_points = convert_to_tensor(start_points, dtype=torch.float32)
567
- end_points = convert_to_tensor(end_points, dtype=torch.float32)
569
+ start_points = convert_to_tensor(start_points)
570
+ end_points = convert_to_tensor(end_points)
571
+ dtype = backend.result_type(start_points.dtype, end_points.dtype, float)
572
+ # `torch.linalg.solve` requires float32.
573
+ compute_dtype = backend.result_type(dtype, "float32")
574
+ start_points = cast(start_points, dtype)
575
+ end_points = cast(end_points, dtype)
568
576
 
569
577
  start_x1, start_y1 = start_points[:, 0, 0], start_points[:, 0, 1]
570
578
  start_x2, start_y2 = start_points[:, 1, 0], start_points[:, 1, 1]
@@ -700,9 +708,11 @@ def compute_homography_matrix(start_points, end_points):
700
708
  dim=-1,
701
709
  ).unsqueeze(-1)
702
710
 
711
+ coefficient_matrix = cast(coefficient_matrix, compute_dtype)
712
+ target_vector = cast(target_vector, compute_dtype)
703
713
  homography_matrix = torch.linalg.solve(coefficient_matrix, target_vector)
704
714
  homography_matrix = homography_matrix.reshape(-1, 8)
705
-
715
+ homography_matrix = cast(homography_matrix, dtype)
706
716
  return homography_matrix
707
717
 
708
718
 
keras/src/version.py CHANGED
@@ -1,7 +1,7 @@
1
1
  from keras.src.api_export import keras_export
2
2
 
3
3
  # Unique source of truth for the version number.
4
- __version__ = "3.12.0.dev2025082703"
4
+ __version__ = "3.12.0.dev2025082903"
5
5
 
6
6
 
7
7
  @keras_export("keras.version")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: keras-nightly
3
- Version: 3.12.0.dev2025082703
3
+ Version: 3.12.0.dev2025082903
4
4
  Summary: Multi-backend Keras
5
5
  Author-email: Keras team <keras-users@googlegroups.com>
6
6
  License: Apache License 2.0
@@ -126,7 +126,7 @@ keras/regularizers/__init__.py,sha256=542Shphw7W8h4Dyf2rmqMKUECVZ8IVBvN9g1LWhz-b
126
126
  keras/saving/__init__.py,sha256=KvL2GZxjvgFgEhvEnkvqjIR9JSNHKz-NWZacXajsjLI,1298
127
127
  keras/src/__init__.py,sha256=Gi4S7EiCMkE03PbdGNpFdaUYySWDs_FcAJ8Taz9Y1BE,684
128
128
  keras/src/api_export.py,sha256=gXOkBOnmscV013WAc75lc4Up01-Kkg9EylIAT_QWctg,1173
129
- keras/src/version.py,sha256=_xotlmgpnmC5t-uC86NtDftpNS6M-KZgnTfkEVbAt2w,204
129
+ keras/src/version.py,sha256=4Ef-zjI1JVHSP_arvoUZl1BVOSSe-tNSyb2a9QMjONA,204
130
130
  keras/src/activations/__init__.py,sha256=0nL3IFDB9unlrMz8ninKOWo-uCHasTUpTo1tXZb2u44,4433
131
131
  keras/src/activations/activations.py,sha256=mogPggtp4CGldI3VOPNmesRxp6EbiR1_i4KLGaVwzL8,17614
132
132
  keras/src/applications/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -164,7 +164,7 @@ keras/src/backend/jax/__init__.py,sha256=l_HMwAZ3oAV4Etnw9RPqbvLYPPs3CZYbgaLd_qy
164
164
  keras/src/backend/jax/core.py,sha256=kd2-Q3Nm5zp7YwyO_d6ZFlqUCPKP7_hVFAUrgD_FvIU,21418
165
165
  keras/src/backend/jax/distribution_lib.py,sha256=-pm5qtFbzTgg_Z7sxq30x4Mjdopn-6qgXFysWoNLtZo,8663
166
166
  keras/src/backend/jax/export.py,sha256=jV2yKQLzYjK72vTJmdNomWPLeNS_lDTCEKzQx_5D_-E,7368
167
- keras/src/backend/jax/image.py,sha256=9ZibpED_HAY_YOCvPbH-3MBlJEAdlwBz4lJz85wI4-c,30388
167
+ keras/src/backend/jax/image.py,sha256=RiYIalbIaUQdDOGpDZUBk5KNsX94Xqg7iyXGATN9V58,30482
168
168
  keras/src/backend/jax/layer.py,sha256=QxZeeiimUulsb3j1h3ncNxIoTYdKPO89s0kP49ZwF-w,194
169
169
  keras/src/backend/jax/linalg.py,sha256=dtGHRYCvoVlRX0UwbDDdunA8Vp_mA3sdqoasX4P8SbQ,2532
170
170
  keras/src/backend/jax/math.py,sha256=1IEDpdoF8e5ltu3D4wbDQuihzvJHhMXz8W9Z_E-eJqU,9391
@@ -179,7 +179,7 @@ keras/src/backend/jax/trainer.py,sha256=N3Ct5iG2tZi1HjX5sLQYPbxKhqFxaMgHzJpGhWQZ
179
179
  keras/src/backend/numpy/__init__.py,sha256=NkIur677fC3eRPT_ZsnF_lgid8JQUEmNXxwjXVEdjw8,1305
180
180
  keras/src/backend/numpy/core.py,sha256=ZGTkv0BS03x-qJen5DgPlzIdx4v81sGszFX6jxiPsdU,13515
181
181
  keras/src/backend/numpy/export.py,sha256=mXJ8egC2Rl_I-ggYOTe-NbPeeWiv55od39aWZimUheo,351
182
- keras/src/backend/numpy/image.py,sha256=4GCzP2Z3dXfoB9E-y1gSjWX-Z9Jbh30wupnYiFnNs1g,39407
182
+ keras/src/backend/numpy/image.py,sha256=B3PyAIylUOkeFnflFvfqo56k-3jt1QYKJUc4cveG39o,40463
183
183
  keras/src/backend/numpy/layer.py,sha256=dTk7W7ql7vRgll7JbOXK5PlIhQw5VHdpSjKciHd8vec,27
184
184
  keras/src/backend/numpy/linalg.py,sha256=H8Bdu8LG6OlzXqx8uVxLmTKKE8s9lMoZHMsM2tW4e04,2417
185
185
  keras/src/backend/numpy/math.py,sha256=HdkEA5ro7dtQBTP78GFIgqTFLgNQ49PXHhqI1vLRGfo,10169
@@ -204,7 +204,7 @@ keras/src/backend/tensorflow/__init__.py,sha256=vdmzvlszS9T9PPxnfVJZWAJ2ODU00HIr
204
204
  keras/src/backend/tensorflow/core.py,sha256=fDR7T6OCVFsdRzwrY5dAPlGEYRWzo21RH2DXd4nIdGc,22852
205
205
  keras/src/backend/tensorflow/distribution_lib.py,sha256=Qm7WgudlRLWo6N_EFocqGUvsa1It6u4eAC7LSjOpKMk,2742
206
206
  keras/src/backend/tensorflow/export.py,sha256=TC6ikEIhcqw7IVLPigbOYqspKS6TnTzQoYb-jrNO92c,792
207
- keras/src/backend/tensorflow/image.py,sha256=vnK2pJ2ywHobOnbDLfVd1BdlmvgbLeR6DVE_pYbdHrc,35571
207
+ keras/src/backend/tensorflow/image.py,sha256=lPFNl9QZW1YH0sqe1UerK119SWhQ4_aDFUgjSA_aLOk,35624
208
208
  keras/src/backend/tensorflow/layer.py,sha256=iE6XYSZENEoTpNhoXrEOm7gnIOHwOjETZd_p9J_16f0,4334
209
209
  keras/src/backend/tensorflow/linalg.py,sha256=fpzxql1ycXIAks9AvS753aiSoaVqAuM6xbv671BulhQ,8038
210
210
  keras/src/backend/tensorflow/math.py,sha256=zTu_7Ff6B2Ro862z_xH0OCmIWbV74DjsO5UnfjYuOUQ,12370
@@ -220,7 +220,7 @@ keras/src/backend/tensorflow/trainer.py,sha256=PXQSWwTtQJWZlntBoi4q_FiYeRf8DOpw1
220
220
  keras/src/backend/torch/__init__.py,sha256=0SiJ91WMaE_tO5q1zUsLEnU6hmPTpGKPIOkmIWaHlhk,2131
221
221
  keras/src/backend/torch/core.py,sha256=k35_MwjA2AldkzgM48UPewJ5xytL4vKdbLepCsWtc4M,24369
222
222
  keras/src/backend/torch/export.py,sha256=yYc5-4JxSiaCkbFWpfCIdcm4dDBv_9uG_uH6JR6oGx0,4909
223
- keras/src/backend/torch/image.py,sha256=I1RY1MM99gufhxjQArkRXS9ZKf5Ki0uA-HG-D47s7kE,38643
223
+ keras/src/backend/torch/image.py,sha256=eer8LZwDMz3k2Dh5gxeTQfwrxPemM_H6eHMIP3AwRss,39149
224
224
  keras/src/backend/torch/layer.py,sha256=htECdpv9ioHWM8_zqQkEdxgDsgLu8XJi5yXgnLl-JFw,2084
225
225
  keras/src/backend/torch/linalg.py,sha256=2GUb107BufiHEK2zJ_fkFREo8Y8mo0OqUZLkwNNgOv4,1991
226
226
  keras/src/backend/torch/math.py,sha256=g-ElDii2Y_o1-t6BAu2nbS7JH-aPqVS5Fqds8aYzIlg,14324
@@ -597,7 +597,7 @@ keras/utils/bounding_boxes/__init__.py,sha256=jtvQll4u8ZY0Z96HwNhP1nxWEG9FM3gI-6
597
597
  keras/utils/legacy/__init__.py,sha256=oSYZz6uS8UxSElRaaJYWJEoweJ4GAasZjnn7fNaOlog,342
598
598
  keras/visualization/__init__.py,sha256=UKWmiy6sps4SWlmQi9WX8_Z53cPpLlphz2zIeHdwJpQ,722
599
599
  keras/wrappers/__init__.py,sha256=QkS-O5K8qGS7C3sytF8MpmO6PasATpNVGF8qtb7Ojsw,407
600
- keras_nightly-3.12.0.dev2025082703.dist-info/METADATA,sha256=-atFYY_hEpWu-qQ2tRIYNfvuXPpxwM36-TDG_iLmdR8,5970
601
- keras_nightly-3.12.0.dev2025082703.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
602
- keras_nightly-3.12.0.dev2025082703.dist-info/top_level.txt,sha256=ptcw_-QuGZ4ZDjMdwi_Z0clZm8QAqFdvzzFnDEOTs9o,6
603
- keras_nightly-3.12.0.dev2025082703.dist-info/RECORD,,
600
+ keras_nightly-3.12.0.dev2025082903.dist-info/METADATA,sha256=UMxqyn5P7_6QqAPxbKGnyGk8x0Yxf3tQWRvCg_DZQ2I,5970
601
+ keras_nightly-3.12.0.dev2025082903.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
602
+ keras_nightly-3.12.0.dev2025082903.dist-info/top_level.txt,sha256=ptcw_-QuGZ4ZDjMdwi_Z0clZm8QAqFdvzzFnDEOTs9o,6
603
+ keras_nightly-3.12.0.dev2025082903.dist-info/RECORD,,