Python Forum
Keras Dense layer with wrong input
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Keras Dense layer with wrong input
Hi everyone,

I'm building a simple CNN and can't seem to get it to work. The error I get is:
ValueError: Error when checking target: expected dense_1 to have 2 dimensions, but got array with shape (1, 70, 2)
Here's the code:

print("Defining training and testing sets...")
x_train, x_test = shuffling_set(x);
y_train = np.full((1, len(x_train)), 1);
y_test = np.full((1, len(x_test)), 1);
y_train = np_utils.to_categorical(y_train);
y_test = np_utils.to_categorical(y_test);

print("Creating neural network...")

## Building has begun...
model = Sequential();
# Adding 2 convolution layers
model.add(Conv2D(64, kernel_size=3, activation='relu', input_shape=(1024,1024,3)));
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(32, kernel_size=3, activation='relu'));
model.add(MaxPooling2D(pool_size=(2, 2)))

# Flatten layer doesn't accept the use of several image sizes, so we go for max pooling



# Adding the fully connected layer
model.add(Dense(2, activation="softmax"));
# Compiling the model
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy']);

print("Training..."), y_train, validation_data=(x_test, y_test), epochs=1);
There's some image processing before that. X_train is a list with 70 images (not the full dataset, just for testing if this runs) with image being 1024 by 1024 with 3 channels (RGB).

I know I'm missing something, but I don't know what it is.

Possibly Related Threads…
Thread Author Replies Views Last Post
  Understanding Keras and TensorFlow and how to use them bytecrunch 1 973 Mar-11-2021, 02:40 PM
Last Post: jefsummers
  Problems feeding live input from my microphone into a keras model (SegFault: 11) zeptozetta 1 1,303 Sep-14-2020, 03:08 AM
Last Post: zeptozetta
  Keras.Predict into Dataframe Finpyth 13 4,375 Aug-31-2020, 07:22 AM
Last Post: hussainmujtaba
  Making a Basic Keras Model - Input Shape and Parameters MattKahn13 0 1,142 Aug-16-2020, 04:36 PM
Last Post: MattKahn13
  Single layer perceptron not outputting correct results mberge 0 744 Apr-29-2020, 10:17 PM
Last Post: mberge
  Error when import Keras Azadfalah 1 1,366 Apr-29-2020, 04:45 AM
Last Post: buran
  Keras + Matplotlib causing crash spearced 3 2,450 Feb-06-2020, 04:54 PM
Last Post: zljt3216
  Keras: Time series classification midarq 0 1,149 Sep-25-2019, 09:03 AM
Last Post: midarq
  Keras. ModuleNotFoundError: No module named 'error' agatte 1 5,298 Sep-18-2019, 12:27 PM
Last Post: shivani
  Keras Target Problem inco 1 1,940 May-05-2019, 10:47 AM
Last Post: scidam

Forum Jump:

User Panel Messages

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