0
$\begingroup$

In the below code:

  1. I get an error when I do not specify the input shape in the $1^{st}$ layer. I thought that TensorFlow can infer the shape for the dense layer. For some code I have seen, TensorFlow works without the input shape specified.

  2. What is the input shape I should specify? X is (9, ). By default, am I supposed to omit the sample size for the input shape?

import numpy as np from numpy import array import pandas as pd from tensorflow.keras.layers import Activation, Dense, SimpleRNN, GRU, LSTM, Conv1D, Conv2D, MaxPool2D, RepeatVector, TimeDistributed X = [1, 2, 3, 4, 5, 6, 8, 9, 10] Y = [10, 15,20, 25, 30, 35, 45, 50, 55] sample_size=len(X) X = np.array(X).reshape(9, ) Y = np.array(Y).reshape(9, ) print(X.shape) model = Sequential() #model.add(Dense(100,input_shape=[1])) model.add(Dense(100)) model.add(Dense(1)) model.compile(loss='mean_squared_error', optimizer='adam') model.fit(X, Y, epochs=500, batch_size=sample_size, verbose=1) ```
$\endgroup$
1
  • $\begingroup$The first layer in every Sequential model requires an input_shape argument, so that it can infer the shapes of the trainable parameters like weights and biases.$\endgroup$CommentedJan 22, 2022 at 7:40

1 Answer 1

0
$\begingroup$
  1. My TensorFlow 2.6 can infer the input_shape in .fit().
  2. Yes, omit the sample size, (1, ) is your input_shape.

P.S. if you do not specify your input_shape, you cannot call .summary() before .fit()

$\endgroup$

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.