B
B
BitNeBolt2020-07-16 13:25:36
Python
BitNeBolt, 2020-07-16 13:25:36

Why can't NumPy specify the correct size?

In the network, the input layer must have 4 neurons. The input must be 1 list, the length of which is 4, each element is a number.

Here is the first layer:

self.model.add(layers.Dense(4, activation = "sigmoid", input_shape=(4, )))


Here is the input:
print("SHAPE:", np.array([1, 1, 1, 1]).shape)

self.model.fit(np.array([1, 1, 1, 1]),
self.rightAnswer, 
epochs = 1,
batch_size = 1)


Here is the output:
SHAPE: (4,)

ValueError: Error when checking input: expected dense_1_input to have shape (4,) but got array with shape (1,)


Why is this happening, how to fix it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2020-07-16
@LazyTalent

Because I didn't read the documentation


# as first layer in a sequential model:
model = Sequential()
model.add(Dense(32, input_shape=(16,)))
# now the model will take as input arrays of shape (*, 16)
# and output arrays of shape (*, 32)

# after the first layer, you don't need to specify
# the size of the input anymore:
model.add(Dense(32))


https://www.tensorflow.org/api_docs/python/tf/kera...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question