繁体   English   中英

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

[英]AttributeError:'Tensor' object has no attribute '_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 classes

x = 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(),这里发生了属性错误。如果在我的实现中有任何其他错误,请在评论部分中取消并通知我。

问题在于使用每个tf操作应该通过以下任一方式封装:

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM