‘Dense’对象没有属性’op’

我正在尝试使用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)

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注