我正在尝试使用tensorflow.keras创建一个全连接模型,以下是我的代码
from tensorflow.keras.models import Modelfrom tensorflow.keras.layers import Input, Dense, Flattendef 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'对象没有属性'op'
我该如何修复这个问题?
回答:
你缺少了输出层的(x)
。请尝试
output = Dense(10 , activation = 'softmax')(x)