{"cells":[
 {
  "cell_type": "code",
  "execution_count": null,
  "metadata": {
   "collapsed": false
  },
  "outputs": [],
  "source": "import os, glob, math, cv2, time\n\nimport numpy as np\nfrom joblib import Parallel, delayed"
 },
 {
  "cell_type": "code",
  "execution_count": null,
  "metadata": {
   "collapsed": false
  },
  "outputs": [],
  "source": "img_size = 50\nsz = (img_size, img_size)\n\nnprocs = 2"
 },
 {
  "cell_type": "code",
  "execution_count": null,
  "metadata": {
   "collapsed": false
  },
  "outputs": [],
  "source": "def process_image(img_file):\n    img = cv2.imread(img_file)\n    img = cv2.resize(img, sz).transpose((2,0,1)).astype('float32') / 255.0\n    \n    return img"
 },
 {
  "cell_type": "code",
  "execution_count": null,
  "metadata": {
   "collapsed": false
  },
  "outputs": [],
  "source": "start = time.time()\n\nX_train = []\nY_train = []\n\nfor j in range(10):\n    print('Load folder c{}'.format(j))\n    path = os.path.join('../input/train', 'c' + str(j), '*.jpg')\n    files = glob.glob(path)\n    X_train.extend(Parallel(n_jobs=nprocs)(delayed(process_image)(im_file) for im_file in files))\n    Y_train.extend([j]*len(files))\n    \nend = time.time() - start\nprint(\"Time: %.2f seconds\" % end)"
 },
 {
  "cell_type": "code",
  "execution_count": null,
  "metadata": {
   "collapsed": false
  },
  "outputs": [],
  "source": "a = cv2.imread('../input/train/c9/img_48026.jpg')\nprint(np.size(X_train,0))\nprint(np.size(cv2.resize(a, sz).transpose((2,0,1)),1))\nprint(np.size(cv2.resize(a, sz).transpose((2,0,1)),2))\ndef process_test_image(img_file):\n    return process_image(img_file), os.path.basename(img_file)"
 },
 {
  "cell_type": "code",
  "execution_count": null,
  "metadata": {
   "collapsed": false
  },
  "outputs": [],
  "source": "start = time.time()\n\nX_test    = []\nX_test_id = []\n\n\npath  = os.path.join('../input/test', '*.jpg')\nfiles = glob.glob(path)\n\nresults = Parallel(n_jobs=nprocs)(delayed(process_test_image)(im_file) for im_file in files)\nX_test, X_test_id = zip(*results)\n\nend = time.time() - start\nprint(\"Time: %.2f seconds\" % end)\n\nprint(len(X_test))"
 }
],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"}}, "nbformat": 4, "nbformat_minor": 0}