0

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.

Vallie
  • 689
  • 9
  • 19
  • It seems that you need to increase the size of new dimensions, since `227 * 227 * 3 = 154587`, which is smaller than `3021543`. Take a look [here](https://stackoverflow.com/questions/42947298/valueerror-cannot-reshape-array-of-size-30470400-into-shape-50-1104-104#42947459). – Vasilis G. Feb 15 '18 at 20:02
  • i changed a piece of code to **img.resize((227, 227), Image.ANTIALIAS** and now getting this error ValueError: cannot reshape array of size 2395575 into shape (3,227,227) .can you please tell me how to size of new dimensions although i followed the link but could not to get my answer to problem – Assad Rasheed Feb 16 '18 at 05:14
  • by changing the arr = array(img, dtype="float32") to np. array(img, dtype="float32") work for me – Assad Rasheed Feb 18 '18 at 05:43
  • @AssadRasheed whatever solution you got post it as an answer and accept it – Vallie Jun 05 '18 at 07:45
  • So training data has a batch size of 3, n_steps is 1, and the node has dimensionality 154587. You say your data has shape (3,227,227,3). So you should use the numpy reshape function to change your data to the correct shape (e.g., np.reshape(train_inputs, (3, 1, 154587))). – Assad Rasheed Jun 09 '18 at 18:01

0 Answers0