Best way to create an image dataset for CNN
I found this solution and will be happy about any improvements or suggestions:

First, I create a random dataset of images, which are 28x28 pixels, and corresponding random labels (just for sake of clarification, I have another image dataset, this is just for explaining). Then I use a sklearn module for splitting the data:

import numpy as np
from sklearn.model_selection import train_test_split


# create the data and labels
def pixel_dataset(n_data=10, dpi = 28):

    ary = np.zeros((n_data, dpi, dpi))
    label = [] 

    for i in np.arange(n_data):
        labels =['a', 'b', 'c']
        ary[i,::] = np.reshape(np.array(np.random.randint(0, 255, 28*28)),(28,28))
        label.append(np.random.choice(labels, 1)[0])

    return ary, label 


# create the test train split    
def mydata(test_size=0.3):

    X, y = pixel_dataset()       
    X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = test_size) 
    return (X_train, y_train), (X_test, y_test)