text_plain_output_1.png
from joblib import Parallel, delayed

import os

img_size = 32

def process_image(img_file):
    img = cv2.imread(img_file, cv2.IMREAD_GRAYSCALE)
    img = cv2.resize(img, (img_size, img_size))
    return img

start = time.time()
X_data = []
Y_data = []
for j in range(10):
    print('Load folder c{}'.format(j))
    path = os.path.join('../input/state-farm-distracted-driver-detection/imgs/train', 'c' + str(j), '*.jpg')
    files = glob.glob(path)
    X_data.extend(Parallel(n_jobs=2)((delayed(process_image)(im_file) for im_file in files)))
    Y_data.extend([j] * len(files))
end = time.time() - start
print('Time: %.2f seconds' % end)