{"metadata":{"kernelspec":{"name":"python3","display_name":"Python 3","language":"python"},"language_info":{"file_extension":".py","mimetype":"text/x-python","pygments_lexer":"ipython3","name":"python","codemirror_mode":{"name":"ipython","version":3},"version":"3.6.3","nbconvert_exporter":"python"}},"nbformat_minor":1,"nbformat":4,"cells":[{"metadata":{"_cell_guid":"330bc36f-cde8-4615-9d35-4913904edbc3","_uuid":"29be19dc67ba37a7410845d8065ec7eeb27208af"},"source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load in \n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport matplotlib.pyplot as plt\nimport sklearn\nfrom sklearn.cross_validation import train_test_split\n\nfrom PIL import Image\nfrom scipy import ndimage\nimport scipy\n# Input data files are available in the \"../input/\" directory.\n# For example, running this (by clicking run or pressing Shift+Enter) will list the files in the input directory\nimport os\nfrom subprocess import check_output\nprint(check_output([\"ls\", \"../input\"]).decode(\"utf8\"))\n\n# Any results you write to the current directory are saved as output.","execution_count":null,"cell_type":"code","outputs":[]},{"metadata":{"_cell_guid":"b12f9682-90d4-42f5-9e07-f5c9a703956e","_uuid":"d1864ebe599bbfddb1c6dd53eb8b6269f5151dd9"},"source":"# get the list of pic file in train and test dir.\nTrain_filelist = os.listdir(\"../input/train\")\nTest_filelist = os.listdir(\"../input/test\")\n\n# read the image.\nTrain_pic_num = 0\ny_orig = [] \nsize_pic = 64\nImage_Data = np.ones((size_pic*size_pic*3, 0))\nfor pic_file in Train_filelist:\n    if pic_file.endswith('.jpg'):\n        Train_pic_num += 1\n        if Train_pic_num % 1000 == 0:\n            print (Train_pic_num)\n        fname = \"../input/train/\"+ pic_file\n        try:\n            image = np.array(ndimage.imread(fname, flatten=False))\n            sample_image = scipy.misc.imresize(image, size=(size_pic, size_pic)).reshape((size_pic*size_pic*3, 1))\n            if pic_file.startswith(\"dog\"):\n                y_orig.append(1)\n            else:\n                y_orig.append(0)\n            Image_Data = np.c_[Image_Data, sample_image]\n        except:\n            print(pic_file)\n\n# show the image\nshow_index = 11\nprint (len(y_orig))\nprint (Image_Data.shape)\nplt.imshow(Image_Data[:, show_index].reshape(size_pic, size_pic, 3))\nprint (y_orig[show_index])","execution_count":null,"cell_type":"code","outputs":[]},{"metadata":{"_cell_guid":"8965b6d9-ca01-4d7f-bf96-a22e6ce2c8ba","collapsed":true,"_uuid":"9bca8caf58bafb3e1d83697985091edee8b352b9"},"source":"y_nd = np.array(y_orig)","execution_count":null,"cell_type":"code","outputs":[]}]}