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


Possibly Related Threads…
Thread Author Replies Views Last Post
  Understanding Keras and TensorFlow and how to use them bytecrunch 1 676 Mar-11-2021, 02:40 PM
Last Post: jefsummers
  Problems feeding live input from my microphone into a keras model (SegFault: 11) zeptozetta 1 981 Sep-14-2020, 03:08 AM
Last Post: zeptozetta
  Keras.Predict into Dataframe Finpyth 13 3,295 Aug-31-2020, 07:22 AM
Last Post: hussainmujtaba
  cannot reshape array of size 0 into shape Roro 2 3,447 Jun-14-2020, 11:28 AM
Last Post: Roro
  Error when import Keras Azadfalah 1 1,027 Apr-29-2020, 04:45 AM
Last Post: buran
  Keras + Matplotlib causing crash spearced 3 1,984 Feb-06-2020, 04:54 PM
Last Post: zljt3216
  Keras Dense layer with wrong input d1r4c 0 714 Jan-02-2020, 02:35 PM
Last Post: d1r4c
  Bad input shape for SVC Scott 1 2,810 Dec-07-2019, 08:03 AM
Last Post: scidam
  Keras: Time series classification midarq 0 1,007 Sep-25-2019, 09:03 AM
Last Post: midarq
  Keras. ModuleNotFoundError: No module named 'error' agatte 1 4,595 Sep-18-2019, 12:27 PM
Last Post: shivani

Forum Jump:

User Panel Messages

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