Convert image data to grayscale from npy file in pylearn2

828 Views Asked by At

I'm training a simple convolution neural network using pylearn2. I have my RGB image data stored in a npy file. Is there anyway to convert that data directly to grayscale data directly from the npy file?

1

There are 1 best solutions below

0
On BEST ANSWER

If this is a standalone file then load the file using numpy.load then convert the content using something like this:

def rgb2gray(rgb):
    return np.dot(rgb[...,:3], [0.299, 0.587, 0.144])

If the file is part of a pylearn2 dataset (resulted from use_design_loc()), then load the dataset

from pylearn2.utils import serial
serial.load("file.pkl")

and apply rgb2gray() function to X member (I assume a DenseDesignMatrix).