-
Notifications
You must be signed in to change notification settings - Fork 19.6k
Closed
Labels
Description
keras.ops.shape doesn't support input with unknown dimension with torch and tensorflow backend. jax backend is ok. the following code can reproduce the problem. please support input with unknown dimension for keras.ops.shape.
from os import environ
#environ['KERAS_BACKEND'] = 'tensorflow' # FAIL
#environ['KERAS_BACKEND'] = 'torch' # FAIL
environ['KERAS_BACKEND'] = 'jax' # OK
import keras as k
def Test():
inputs = k.Input((None, 3))
shape = k.layers.Lambda(lambda x: k.ops.shape(x))(inputs)
return k.Model(inputs = inputs, outputs = shape)
import numpy as np
inputs = np.random.normal(size = (1,10,3))
outputs = Test()(inputs)
print(outputs)
the pure tensorflow implement has no such problem.
import tensorflow as tf
def Test():
inputs = tf.keras.Input((None, 3))
shape = tf.keras.layers.Lambda(lambda x: tf.shape(x))(inputs)
return tf.keras.Model(inputs = inputs, outputs = shape)
import numpy as np
inputs = np.random.normal(size = (1,10,3))
outputs = Test()(inputs)
print(outputs)