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

Moh*_*afa 16 python machine-learning deep-learning keras tensorflow

我正在尝试使用 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
Run Code Online (Sandbox Code Playgroud)

但是当我打电话给模型时

model = load_model((120,))
Run Code Online (Sandbox Code Playgroud)

我有这个错误

'Dense' object has no attribute 'op'
Run Code Online (Sandbox Code Playgroud)

我怎样才能解决这个问题?

rik*_*tti 30

(x)在输出层之后丢失了。尝试

output = Dense(10 , activation = 'softmax')(x)
Run Code Online (Sandbox Code Playgroud)

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