I have a data set I loaded with cv2, but when I try to format it I get the above error. I start by moving the data into X_train
and X_test
(the loaded data is in x_train
and x_test
).
X_train = []
X_test = []
# Image matrices are different sizes so I am making them the same size
for i in range(len(x_train)-1):
resized = cv2.resize(x_train[i], (img_width, img_height))
X_train.append(resized)
for i in range(len(x_test)-1):
resized = cv2.resize(x_test[i], (img_width, img_height))
X_test.append(resized)
# Convert to numpy arrays
X_test = np.array(X_test)
X_train = np.array(X_train)
# Gather statistics
print(X_train.shape) # -> (2734, 132, 126, 3)
print(X_train.size) # -> 136415664
print(len(X_train)) # -> 2734
# Convert to black and white
X_train = X_train/ 255.
X_test = X_test/ 255.
# First line throws error
X_train = np.reshape(X_train, (len(X_train), img_height, img_width, 1))
X_test = np.reshape(X_test, (len(X_test), img_height, img_width, 1))
What am I doing wrong?