我的代碼中出現以下錯誤
WARNING:tensorflow:Model was constructed with shape (None, 3) for input KerasTensor(type_spec=TensorSpec(shape=(None, 3), dtype=tf.float32, name='dense_input'), name='dense_input', description="created by layer 'dense_input'"), but it was called on an input with incompatible shape (None,).
這是我的代碼
import numpy as np
import tensorflow as tf
inum = np.array([[1,1,2],[2,25,6],[32,4,7],[8,9,0]], dtype="float")
onum = np.array([3,56,135,72],dtype="float")
l0 = tf.keras.layers.Dense(units=4, input_shape=(3,))
l1 = tf.keras.layers.Dense(units=4)
l2 = tf.keras.layers.Dense(units=4)
l3 = tf.keras.layers.Dense(units=1)
model = tf.keras.Sequential([l0,l1,l2,l3])
model.compile(loss="mean_squared_error",optimizer=tf.keras.optimizers.Adam(0.1))
history = model.fit(inum,onum,epochs=1200,verbose=False)
model.predict([2,2,4])
我對機器學習很陌生,現在知道該怎么做。
任何幫助是極大的贊賞。
uj5u.com熱心網友回復:
利用
Model.predict([[2,2,4]])
因為 keras 模型將輸入視為一批資料。因此,即使您只想輸入一個具有形狀 [3] 的資料,您也應該像我一樣將其包裝為 [1,3] 資料。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/524643.html
