“密集”对象没有“op”属性。

23

我正在尝试使用tensorflow.keras创建一个完全连接的模型,以下是我的代码

from tensorflow.keras.models import Model
from tensorflow.keras.layers import Input, Dense, Flatten

def load_model(input_shape):
  input = Input(shape = input_shape)
  dense_shape = input_shape[0]
  x = Flatten()(input)
  x = Dense(dense_shape, activation='relu')(x)
  x = Dense(dense_shape, activation='relu')(x)
  x = Dense(dense_shape, activation='relu')(x)
  x = Dense(dense_shape, activation='relu')(x)
  x = Dense(dense_shape, activation='relu')(x)
  output = Dense(10, activation='softmax')

  model  = Model(input , output)
  model.summary()
  return model

但是当我调用该模型时

model = load_model((120,))

我遇到了这个错误

'Dense' object has no attribute 'op'

我该怎么修复这个问题?


3
请提供完整的回溯信息。 - Dr. Snoopy
1个回答

44
你的输出层后缺少 (x)。请尝试添加。
output = Dense(10 , activation = 'softmax')(x)

5
该死,我刚刚犯了同样的错误。我想当我更改我的激活时删除了(x),而我永远不会发现它。 - Mark

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接