You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using the Keras backend argmin function on an input array containing subnormal float values, Keras consistently returns the index of 0.0 as the minimum value, even though a smaller subnormal value (-1.401298464324817e-45) exists in the array. Other deep learning frameworks such as PyTorch and Chainer correctly return the index of the subnormal value, but Keras (and TensorFlow) return the index of 0.
Expected Behavior:
The expected behavior is for Keras's argmin function to return the index of the smallest value, which should be the subnormal float value (-1.401298464324817e-45) at index 2. Instead, Keras is returning the index of 0.0 (index 0).
Reproduction Code:
import torch
import tensorflow as tf
import numpy as np
from chainer import functions as F
import jax.numpy as jnp
import tensorflow.keras.backend as K
# Input data
input_data = [
0.0,
1.1754943508222875e-38,
-1.401298464324817e-45,
0.0,
459367.0
]
# Test PyTorch
def test_pytorch_argmin(input_data):
tensor = torch.tensor(input_data, dtype=torch.float32)
result = torch.argmin(tensor).item()
print(f"PyTorch argmin result: {result}")
return result
# Test TensorFlow
def test_tensorflow_argmin(input_data):
tensor = tf.constant(input_data, dtype=tf.float32)
result = tf.argmin(tensor).numpy()
print(f"TensorFlow argmin result: {result}")
return result
# Test Keras using backend
def test_keras_argmin(input_data):
tensor = K.constant(input_data, dtype=tf.float32)
result = K.argmin(tensor, axis=-1).numpy()
print(f"Keras argmin result: {result}")
return result
# Test Chainer
def test_chainer_argmin(input_data):
tensor = np.array(input_data, dtype=np.float32)
result = F.argmin(tensor).data
print(f"Chainer argmin result: {result}")
return result
# Test JAX
def test_jax_argmin(input_data):
tensor = jnp.array(input_data, dtype=jnp.float32)
result = jnp.argmin(tensor).item()
print(f"JAX argmin result: {result}")
return result
if __name__ == "__main__":
pytorch_result = test_pytorch_argmin(input_data)
tensorflow_result = test_tensorflow_argmin(input_data)
keras_result = test_keras_argmin(input_data)
chainer_result = test_chainer_argmin(input_data)
jax_result = test_jax_argmin(input_data)
print("\nSummary of results:")
print(f"PyTorch argmin: {pytorch_result}")
print(f"TensorFlow argmin: {tensorflow_result}")
print(f"Keras argmin: {keras_result}")
print(f"Chainer argmin: {chainer_result}")
print(f"JAX argmin: {jax_result}")
Summary of results:
PyTorch argmin: 2
TensorFlow argmin: 0
Keras argmin: 0
Chainer argmin: 2
JAX argmin: 0
The text was updated successfully, but these errors were encountered:
I checked the result with different backend using Keras 3, torch results in 2 where as TensorFlow results in 0.
The results are not consistent across different backend.
When using the Keras backend
argmin
function on an input array containing subnormal float values, Keras consistently returns the index of0.0
as the minimum value, even though a smaller subnormal value (-1.401298464324817e-45
) exists in the array. Other deep learning frameworks such as PyTorch and Chainer correctly return the index of the subnormal value, but Keras (and TensorFlow) return the index of0
.Expected Behavior:
The expected behavior is for Keras's
argmin
function to return the index of the smallest value, which should be the subnormal float value (-1.401298464324817e-45
) at index 2. Instead, Keras is returning the index of0.0
(index 0).Reproduction Code:
The text was updated successfully, but these errors were encountered: