AttributeError:’Tensor’对象没有属性’_keras_history’

Aux_input = Input(shape=(wrd_temp.shape[1],1), dtype='float32')#shape (,200)Main_input = Input(shape=(wrdvec.shape[1],),dtype='float32')#shape(,367)X = Bidirectional(LSTM(20,return_sequences=True))(Aux_input)X = Dropout(0.2)(X)X = Bidirectional(LSTM(28,return_sequences=True))(X)X = Dropout(0.2)(X)X = Bidirectional(LSTM(28,return_sequences=False))(X)Aux_Output = Dense(Opt_train.shape[1], activation= 'softmax' )(X)#total 22 classesx = keras.layers.concatenate([Main_input,Aux_Output],axis=1)x = tf.reshape(x,[1,389,1])#here 389 is the shape of the new input i.e.(Main_input+Aux_Output)x = Bidirectional(LSTM(20,return_sequences=True))(x)x = Dropout(0.2)(x)x = Bidirectional(LSTM(28,return_sequences=True))(x)x = Dropout(0.2)(x)x = Bidirectional(LSTM(28,return_sequences=False))(x)Main_Output = Dense(Opt_train.shape[1], activation= 'softmax' )(x)model = Model(inputs=[Aux_input,Main_input], outputs=    [Aux_Output,Main_Output])

错误发生在声明模型的行,即 model = Model(),在这里发生了属性错误。如果我的实现中有其他错误,请在评论部分记录并通知我。


回答:

问题在于,每次使用tf操作时都应该被以下之一封装:

  1. 使用keras.backend函数,
  2. Lambda层,
  3. 具有相同行为的指定keras函数。

当你使用tf操作时,你会得到tf张量对象,而这个对象没有history字段。当你使用keras函数时,你会得到keras.tensor

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中创建了一个多类分类项目。该项目可以对…

发表回复

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