Python Forum

Full Version: Keras Dense layer with wrong input
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi everyone,

I'm building a simple CNN and can't seem to get it to work. The error I get is:
Output:
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);
print(x_train.shape)
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

model.add(Flatten())

model.add(Dropout(0.2))

# 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...")
model.fit(x_train, 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.