Skip to content

keras.ops.argmax returns incorrect shape for Keras Input when keepdims=True #22523

@tosubmitissue

Description

@tosubmitissue

Bug report

keras.ops.argmax(..., keepdims=True) produces the correct shape for eager tensors, but returns the original input shape when called on a Keras.Input placeholder.

Reproduction

import keras
import tensorflow as tf

x = tf.random.normal((3, 4, 5))
print(keras.ops.argmax(x, axis=None, keepdims=True).shape)

inp = keras.Input(shape=(4, 5), batch_size=3)
print(keras.ops.argmax(inp, axis=None, keepdims=True).shape)

Expected result

Both calls should return a reduced shape with singleton dimensions, i.e. (1, 1, 1) for this input.

Actual result

  • Eager tensor: (1, 1, 1)
  • Keras.Input placeholder: (3, 4, 5)

Notes

This makes argmax(..., keepdims=True) behave inconsistently between eager tensors and symbolic Keras tensors.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions