I was trying to build a CNN model using Keras. Here is my code:
import keras
import tensorflow as tf
from keras.layers import Dense
from keras.models import Sequential
from keras.models import load_model
from keras.callbacks import EarlyStopping
from sklearn.model_selection import train_test_split
from __future__ import print_function
import pandas as pd
import numpy as np
from keras.datasets import cifar10
from keras.models import Sequential
from keras.layers import Dense, Dropout, Activation, Flatten
from keras.layers import Conv2D
from google.colab import drive
drive.mount('/content/drive')
...
# Define x_train...data
x_data=df.iloc[:,1:10084].values-25
# x_data = np.array(x_data).tolist()
y_data=df[['type1','type2']].values
X_train, X_test, y_train, y_test = train_test_split(x_data, y_data,test_size=0.2)
model.fit(X_train, y_train,
batch_size=100,
epochs=100,
verbose=1,
validation_data=(X_test, y_test),
callbacks=[history])
It returned the error
ValueError: Error when checking input: expected conv2d_1_input to have 4 dimensions, but got array with shape (595, 10083)
After referring to other questions I tried to reshape the dimension of the data array using
X_train = X_train[np.newaxis, :, :, :]
which changed it to 3-dimentional and returned the error:
ValueError: Error when checking input: expected conv2d_1_input to have 4 dimensions, but got array with shape (1, 595, 10083)
How should I increase the dimension of the data to 4?
CNN
– nilsinelaboreConv2D
toConv1D
and had thisValueError: Error when checking input: expected conv2d_1_input to have shape (744, 10183, 1) but got array with shape (595, 10083, 1)
– nilsinelabore