Skip to content Skip to sidebar Skip to footer

Keras: Tensor Object Has No Attribute "_keras_history"

Most of the answers to similar previous questions have suggested wrapping the problematic tensor in a Lambda layer. I've already done this, however (and tried many variations on th

Solution 1:

You can provide low and high to the layer with Lambda(..., arguments={'low': low, 'high': high}). From the documentation of Lambda:

arguments: optional dictionary of keyword arguments to be passed to the function.

For example,

clipped_out_position = Lambda(lambda x, low, high: tf.clip_by_value(x, low, high),
                              arguments={'low': low, 'high': high})(out_position)

EDIT:

Here's a more complete sample on testing this layer:

x = Input(shape=(100,))
out_duration = Dense(90)(x)
out_position = Dense(90)(x)
out_duration = Reshape((30, 3))(out_duration)
out_position = Reshape((30, 3))(out_position)

low = tf.constant(np.random.rand(30, 3).astype('float32'))
high = tf.constant(1 + np.random.rand(30, 3).astype('float32'))
clipped_out_position = Lambda(lambda x, low, high: tf.clip_by_value(x, low, high),
                              arguments={'low': low, 'high': high})(out_position)

model = Model(inputs=x, outputs=[out_duration, clipped_out_position])
model.compile(loss='mse', optimizer='adam')
model.fit(np.random.rand(5000, 100), [np.random.rand(5000, 30, 3), np.random.rand(5000, 30, 3)])

Post a Comment for "Keras: Tensor Object Has No Attribute "_keras_history""