0

hi i tried to bulid the simplest possible regression model in tensorflow but this error appearanced. tensorflow ver: 2.7.0

import tensorflow as tf
X_train = tf.cast(tf.constant([1,2,3]), dtype=tf.float32)
y_train = tf.cast(tf.constant([2,3,4]), dtype=tf.float32)

model = tf.keras.Sequential([tf.keras.layers.Dense(1)])
model.compile()
model.fit(X_train, y_train, epochs=10) 

ValueError: Exception encountered when calling layer "sequential_7" (type Sequential). Input 0 of layer "dense_5" is incompatible with the layer: expected min_ndim=2, found ndim=1. Full shape received: (None,)

1 Answer 1

0

You didn't specify an input shape, a loss function, and an optimizer.

import tensorflow as tf

X_train = tf.cast(tf.constant([1, 2, 3]), dtype=tf.float32)
y_train = tf.cast(tf.constant([2, 3, 4]), dtype=tf.float32)

model = tf.keras.Sequential([
    tf.keras.Input(shape=(1, )),
    tf.keras.layers.Dense(1)
    ])
model.compile(optimizer="Adam", loss="binary_crossentropy")
model.fit(X_train, y_train, epochs=10)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.