ValueError while trying model.predict (5:09:41 in Part 1/2) #330
Replies: 2 comments 2 replies
-
I have met this error last week.:::)). pleasezzzzz |
Beta Was this translation helpful? Give feedback.
-
All of this is active with me Creating some datas to view and fitimport numpy as np Create featuresX = np.array([-7.0, -4.0, -1.0, 2.0, 5.0, 8.0, 11.0, 14.0]) Create labelsy = np.array([3.0, 6.0, 9.0, 12.0, 15.0, 18.0, 21.0, 24.0]) Visualizeplt.scatter(X,y) Create a demo tensor for our housing price prediction problemhouse_info = tf.constant(["bedroom", "bathroom", "garage"]) input_shape = X.shape Turn out Numpy arrays into tensorsX = tf.cast(tf.constant(X), dtype = tf.float32) Set random seedtf.random.set_seed(42) 1. Create a model using the Sequential APImodel = tf.keras.Sequential() 2. Compile the modelmodel.compile(loss=tf.keras.losses.mae, #mae is short for mean absolute error 3. fit the modelmodel.fit(X, y, epochs = 5) #Check out X and y c = np.array([17]) model.predict(c) |
Beta Was this translation helpful? Give feedback.
-
There was a question about the dimensions of X and y, that for some reason need to be changed with the commands:
X = tf.expand_dims(X, axis=1)
y = tf.expand_dims(y, axis=1)
That works fine for the model.fit command.
But afterwards, there is another issue when I try to use the model.predict command. It results in the same error as described above, stating:
ValueError: Exception encountered when calling layer "sequential_19" (type Sequential).
So I tried this:
T = tf.constant(17.0)
T = tf.cast(tf.constant(T), dtype=tf.float32)
T = tf.expand_dims(T, axis=1)
model.predict([T])
but it didn't work.
Can you please help me solving the issue? I really want to follow along all the way through this wonderful course of yours, Mr. Bourke! Thank you very much for the effort you put into these lessons!
Beta Was this translation helpful? Give feedback.
All reactions