How to read csv file for training model (CNN)?

Viewed 439

I'm new to machine learning and facing problem while loading data. The provided dataset is in CSV format where images(224 x 224) pixel's value is place is rows, images are grayscaled while the first column of each row indicates the label or class to which that image corresponds to and CSV doesn't have any header information(data starts from very top row). How can I read such a CSV file so that I can split my data into (x_train, y_train) and (x_test,y_test) as I need to use sklearn's function (train_split) but can't figure out for this CSV file what will be initial x and y?

My current implementation is as follow but I want to split it and can't find any reasonable answer.

batch_size = 128
num_classes = 11
img_rows, img_cols = 224, 224
def prep_data(raw):
    y = raw[:, 0]
    print(y)
    out_y = keras.utils.to_categorical(y, num_classes)
    x = raw[:,1:]
    num_images = raw.shape[0]
    out_x = x.reshape(num_images, img_rows, img_cols, 1)
    out_x = out_x / 255
    return out_x, out_y
file = "/dataset.csv"
data=pd.read_csv(file, header=None)
x,y=prep_data(data.values)
0 Answers
Related