Search code examples
pythonnumpykerastensorflow2

Converting RGB Dataset to Grayscale Dataset by averaging color channels with Numpy


I'm trying to convert a dataset of dimensions (32, 32, 3, 10000) dimension dataset to a grayscale dataset, where I would have (32, 32, 1, 10000) dimensions, but I need to have that 1 channel because I will input this to a Neural Network. I tried using numpy.average, but the shape becomes (32, 32, 10000) which the TensorFlow unit is not taking as an input. I even tried to manually average it, but it had the same result. Could you guys help me with this?


Solution

  • It is possible to add that extra dimension you need after getting (32, 32, 1000) as shape.

    You could try np.expand_dims with the axis parameter to define where you want that extra "1" to appear.