运行以下命令:
import tensorflow as tf
from tensorflow.keras import layers
from tensorflow import keras
feat_shape = (50, 66, 3)
inputs = layers.Input(shape=(None,) + feat_shape[1:], dtype=tf.float32)
x = inputs
shape = tf.shape(x)
b, t, f, c = x.get_shape().as_list()
x = layers.Lambda(tf.reshape, arguments=dict(shape=(shape[0], shape[1], shape[2] * shape[3])))(x)
x.set_shape((b, t, f * c))
x = layers.Dense(filters)(x)
lstm_out = layers.LSTM(lstm_units, return_sequences=True, return_state=True)(x)
x = lstm_out[0]
model = keras.Model(inputs=inputs, outputs=x)抛给我这个错误:
TypeError: Could not build a TypeSpec for <KerasTensor: shape=(None, None, None) dtype=float32 (created by layer 'tf.reshape')> with type KerasTensor我使用的Tensorflow版本是2.4.0,我非常确定这样的东西应该可以工作。
这里的问题是什么?我如何解决这个问题?
发布于 2021-02-10 18:39:09
def reshape_(t):
shape = tf.shape(t)
B, T, F, C = t.get_shape().as_list()
t = tf.reshape(t, shape=(shape[0], shape[1], shape[2] * shape[3]))
t.set_shape((B, T, F * C))
return t
inputs = layers.Input(shape=(None,) + feat_shape[1:], dtype=tf.float32)
x = inputs
x = layers.Lambda(reshape_)(x)
x = layers.Dense(filters)(x)
lstm_out = layers.LSTM(lstm_units, return_sequences=True, return_state=True)(x)
x = lstm_out[0]
model = keras.Model(inputs=inputs, outputs=x)

https://stackoverflow.com/questions/66135173
复制相似问题