首页 文章

将keras功能api与张量流相结合

提问于
浏览
0

将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 回答

  • 0

    您正在寻找的是函数API的Input layertensor 参数 .

    tensor:包含在Input层中的可选现有张量 . 如果设置,该图层将不会创建占位符张量 .

相关问题