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

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

我應該在 Keras 輸入類中使用什么形狀?

我應該在 Keras 輸入類中使用什么形狀?

POPMUISE 2023-08-15 17:25:33
我正在嘗試運行一個簡單的神經網絡,并且使用以下代碼已經達到了我的特征平坦的地步:training_dataset = (tf.data.Dataset.from_tensor_slices(    (        tf.cast(ballast_train[features].values, tf.float64),        tf.cast(ballast_train[target].values, tf.int32)    )))for features_tensor, target_tensor in training_dataset:    print(f'features:{features_tensor} target:{target_tensor}')features:[0.46029711 0.33290338 0.78302964 0.10295655 0.5890411 ] target:5features:[0.63530873 0.90712946 0.27781778 0.10295655 0.45988258] target:5features:[0.68413444 0.81390713 0.8448272  0.65073914 0.46771037] target:2現在,我嘗試運行以下代碼,但無法正確獲取代碼的 tf.keras.Input() 部分。`inputs = tf.keras.Input(shape=(5,))x = tf.keras.layers.Dense(100, activation=tf.nn.relu)(inputs)outputs = tf.keras.layers.Dense(15, activation=tf.nn.softmax)(x)model = tf.keras.Model(inputs=inputs, outputs=outputs)model.compile(optimizer='adam',              loss='mean_squared_error',              metrics=['accuracy'])model.fit(training_dataset, epochs=5)`當嘗試擬合模型時,會出現此錯誤:ValueError: Error when checking input: expected input_10 to have shape (5,) but got array with shape (1,)“形狀”參數中應該包含什么?我在這里缺少什么嗎?
查看完整描述

1 回答

?
當年話下

TA貢獻1890條經驗 獲得超9個贊

嘗試以下方法看看是否有效:

model.fit(training_dataset.batch(batch_size),?epoch=5)

您需要提供一個值batch_size

如果這不起作用,我總是傾向于將我的功能和示例提供給單獨的參數xytf.keras.Model.fit?。您可以嘗試修改代碼來執行此操作,而不是將它們合并到數據集中。


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

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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