将tensorflow与keras序列模型结合起来是可能的:(source)
from keras.models import Sequential, Model
model = Sequential()
model.add(Dense(32, activation='relu', input_dim=784))
model.add(Dense(10, activation='softmax'))
# this works!
x = tf.placeholder(tf.float32, shape=(None, 784))
y = model(x)
但是,我想使用这样的功能API:
x = tf.placeholder(tf.float32, shape=(None, 784))
y = Dense(10)(x)
model = Model(inputs=x, outputs=y)
但当我尝试这样做时,我得到这些错误:
TypeError:模型的输入张量必须是Keras张量 . 找到:Tensor("Placeholder_2:0",shape =(?,784),dtype = float32)(缺少Keras元数据) .
1 回答
您正在寻找的是函数API的Input layer的
tensor
参数 .