亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

ValueError:沒有為任何變量提供漸變:

ValueError:沒有為任何變量提供漸變:

人到中年有點甜 2023-12-29 16:32:29
我是 Tensorflow 2 的新手,我想在 keras/tensorflow 中訓練多輸入神經網絡。這是我的示例代碼:First_inputs = Input(shape=(2000, ),name="first")Second_inputs = Input(shape=(4, ),name="second")embedding_layer = Embedding(3,3,  input_length=2000,)(First_inputs)flatten = Flatten()(embedding_layer)first_dense = Dense(neuronCount,kernel_initializer=initializer, )(flatten)merge = concatenate([first_dense, Second_inputs])drop = Dropout(dropout)(merge)output = Dense(1, )(drop)model = Model(inputs=[First_inputs, Second_inputs], outputs=output)x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.1,shuffle=True,  random_state=42)First_inputs =x_train[:,0:2000]Second_inputs =x_train[:,2000:2004]model.fit(([First_inputs, Second_inputs], y_train),validation_data=([First_inputs, Second_inputs], y_train),verbose=1,epochs=100,steps_per_epoch=209)但是,我收到此錯誤:ValueError: No gradients provided for any variable: ['embedding/embeddings:0', 'dense/kernel:0', 'dense/bias:0', 'dense_1/kernel:0'].有人知道問題是什么嗎?謝謝!
查看完整描述

1 回答

?
鴻蒙傳說

TA貢獻1865條經驗 獲得超7個贊

您的數據是 numpy 數組,您必須為 fit() 方法提供兩個單獨的參數,np.arrays 列表作為輸入,np.array 作為標簽。(刪除元組作為輸入):


First_inputs = Input(shape=(2000, ),name="first")

Second_inputs = Input(shape=(4, ),name="second")

embedding_layer = Embedding(3,3,  input_length=2000,)(First_inputs)

flatten = Flatten()(embedding_layer)

first_dense = Dense(neuronCount,kernel_initializer=initializer, )(flatten)

merge = concatenate([first_dense, Second_inputs])

drop = Dropout(dropout)(merge)

output = Dense(1, )(drop)

model = Model(inputs=[First_inputs, Second_inputs], outputs=output)

x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.1,shuffle=True,  

random_state=42)

First_inputs =x_train[:,0:2000]

Second_inputs =x_train[:,2000:2004]

model.fit([First_inputs, Second_inputs], y_train,validation_data=([First_inputs, 

Second_inputs], y_train),verbose=1,epochs=100,steps_per_epoch=209)


查看完整回答
反對 回復 2023-12-29
  • 1 回答
  • 0 關注
  • 152 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號