The problem is that your process_image()
function is returning a scalar instead of the processed image (i.e. a 3D array of shape (168,252,3)
). So, the variable im
is just a scalar. Because of this, you get the array train_images2
to be 1D array. Below is a contrived example which illustrates this:
In [59]: train_2 = range(1008)
In [65]: train_images2 = []
In [66]: for i in range(len(train_2)):
...: im = np.random.random_sample()
...: train_images2.append(im)
...: train_images2 = np.asarray(train_images2)
...:
In [67]: train_images2.shape
Out[67]: (1008,)
So, the fix is that you should make sure that process_image()
function returns a 3D array as in the below contrived example:
In [58]: train_images2 = []
In [59]: train_2 = range(1008)
In [60]: for i in range(len(train_2)):
...: im = np.random.random_sample((168,252,3))
...: train_images2.append(im)
...: train_images2 = np.asarray(train_images2)
...:
# indeed a 4D array as you expected
In [61]: train_images2.shape
Out[61]: (1008, 168, 252, 3)