Python Forum
Making a Basic Keras Model - Input Shape and Parameters
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Making a Basic Keras Model - Input Shape and Parameters
#1
Hey Guys!

I am currently trying to build a simple model which I plan to use to make predictions. The idea for this model is to have each of the 202-dimensional vectors in an array (300 in total) be fitted (using model.fit) to a 1 dimensional vector containing a single integer (also 300 in total). Currently, I have two numpy arrays with the following dimensions: [300,202] and [300,]. I am really having difficulty constructing this model. Here is the current code that I have:

model = tf.keras.Sequential()

model.add(tf.keras.layers.Flatten(input_shape=(202,)))
model.add(tf.keras.layers.Dense(128, activation="relu"))
model.add(tf.keras.layers.Dense(1))

model.compile(loss = "mean_squared_error", optimizer=tf.keras.optimizers.Adam(0.1))
print(model.summary())

#"states" has shape [300,202] and "actions" has shape[300,]

history = model.fit(states, actions, epochs = 1, verbose=False)
print("Finished")

print(model.predict([states[0]]))
Here is the error message that I keep getting:
Error:
"ValueError: Error when checking input: expected input_1 to have shape (202,) but got array with shape (1,)"
Any help that you guys could provide would be great! I'd be more than happy to clarify anything!
Matt
Reply


Messages In This Thread
Making a Basic Keras Model - Input Shape and Parameters - by MattKahn13 - Aug-16-2020, 04:36 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  1st layer tf.keras output shape set at multiple - need help! Afrodizzyjack 0 1,784 Jun-07-2022, 04:53 PM
Last Post: Afrodizzyjack
  issue displaying summary of whole keras CNN model on TensorFlow with python Afrodizzyjack 0 1,619 Oct-27-2021, 04:07 PM
Last Post: Afrodizzyjack
  Issues with Shape/Reshape for CNN moddy10 0 1,428 Oct-12-2021, 03:54 PM
Last Post: moddy10
  Understanding Keras and TensorFlow and how to use them bytecrunch 1 2,052 Mar-11-2021, 02:40 PM
Last Post: jefsummers
  Problems feeding live input from my microphone into a keras model (SegFault: 11) zeptozetta 1 2,541 Sep-14-2020, 03:08 AM
Last Post: zeptozetta
  Keras.Predict into Dataframe Finpyth 13 9,564 Aug-31-2020, 07:22 AM
Last Post: hussainmujtaba
  cannot reshape array of size 0 into shape Roro 2 6,193 Jun-14-2020, 11:28 AM
Last Post: Roro
  Error when import Keras Azadfalah 1 2,753 Apr-29-2020, 04:45 AM
Last Post: buran
  Keras + Matplotlib causing crash spearced 3 4,435 Feb-06-2020, 04:54 PM
Last Post: zljt3216
  Keras Dense layer with wrong input d1r4c 0 1,737 Jan-02-2020, 02:35 PM
Last Post: d1r4c

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020