I am trying to run the following code in keras.
Dummy dataset have images of size 227x227x3
. There are 21 images in train folder and 7 images in test folder of jpg when i run the following code it gives the error:
ValueError: cannot reshape array of size 2395575 into shape (3,227,227)
I tried hard to get the results but failed any one who can suggest me the solutin to the problem:
def get_pixels(fnames,is_test):
imgs = loadImages(fnames, is_test)
pixel_list = []
for img in imgs:
img = img.resize((227, 227), Image.ANTIALIAS)
arr = array(img, dtype="float32")
pixel_list.append(list(arr))
return np.array(pixel_list)
(X_train, y_train), (X_test, y_test), label_names = ((X_train, iy_train),
(X_test, y_test),class_names)
X_train = X_train.reshape(-1, 3, 227, 227).astype('float32')
X_test = X_test.reshape(-1, 3, 227, 227).astype('float32')
n_classes = len(label_names)
X_train = X_train[:, :, 16:-16, 16:-16]
X_test = X_test[:, :, 16:-16, 16:-16]
data_mean = X_train.mean(axis=0)
X_train -= data_mean
X_test -= data_mean
The get_pixels
function get the images and resize them.