【发布时间】:2017-07-12 14:32:47
【问题描述】:
我正在尝试使用以下代码从Keras "first example" 构建模型:
from keras.models import Model
from tensorflow.contrib.keras.api.keras.layers import Dense, Input
# This returns a tensor
inputs = Input(shape=(784,))
# a layer instance is callable on a tensor, and returns a tensor
x = Dense(64, activation='relu')(inputs)
x = Dense(64, activation='relu')(x)
predictions = Dense(10, activation='softmax')(x)
# This creates a model that includes
# the Input layer and three Dense layers
model = Model(inputs=inputs, outputs=predictions)
不训练不跑步,只是建立一个模型。
在 Linux(Ubuntu 14.04LTS、Python 3.5、Tensorflow 1.2.1、Keras 2.0.6)下它会报错
TypeError:
Model的输入层必须是InputLayer对象。 接收到的输入:Tensor("input_1:0", shape=(?, 784), dtype=float32)。 输入 0(从 0 开始)源自图层类型InputLayer。
在 Windows 下(Windows 10、Anaconda Python 3.5、Tensorflow-gpu 1.1.0、Keras 2.0.4)它会抱怨
AttributeError: 'Tensor' 对象没有属性 '_keras_shape'
这些是错误,还是过时的文档,或两者兼而有之,还是什么?
如何从文档站点运行这个简单的示例?
更新
如果我将第一行更改为
inputs = InputLayer(input_shape=(784,))
然后两个操作系统开始抱怨:
AttributeError: 'InputLayer' object has no attribute 'get_shape'
【问题讨论】:
-
为什么要将 keras 模型与从 tensorflow 模块导入的图层混合在一起?
-
@Harwee 好问题 :)
标签: python linux windows keras