{"cells":[{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"3ce38e58-c9d3-d3ef-d986-b828d64509bd"},"outputs":[],"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 \nimport os\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\nfrom keras.models import Model\nfrom keras.layers import Input, Dense\n\nfrom scipy.ndimage import imread\n\nimport matplotlib.pyplot as plt\n# Input data files are available in the \"../input/\" directory.\n\n# Any results you write to the current directory are saved as output."},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"a260c695-47f0-df62-28f3-5980283fb4cd"},"outputs":[],"source":"batch_size=128\ntrain_path = '../input/train/'\ntest_path = '../input/test/'\nimage_x, image_y = 375, 499"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"e0f331c1-f7bc-f0a3-968f-3611f2b8dbde"},"outputs":[],"source":"train_x_1 = [train_path + entry for entry in os.listdir('../input/train/') if 'dog' in entry]\ntrain_x_2 = [train_path + entry for entry in os.listdir('../input/train/') if 'cat' in entry]\n\ntrain_x = [test_path + entry for entry in os.listdir('../input/test/')]"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"2951646c-556e-ad6c-f68c-9bd5ec1b1ef8"},"outputs":[],"source":"image = imread(train_x_1[0])\nplt.imshow(image.reshape((3,image_x,image_y)))\nimage.shape"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"93466d98-f395-b411-67a6-d91f354abcd3"},"outputs":[],"source":"def train_generator():\n    batch = np.array(shape=(batch_size, 3, image_x, image_y))\n    offset = 0\n    sample_size = batch_size//2\n    while True:\n        batch[:sample_size] =  np.array([imread(x) for x in train_x_1[offset:offset+sample_size]])\n              .reshape((sample_size, 3, image_x, image_y))\n        batch[sample_size:] =  np.array([imread(x) for x in train_x_2[offset:offset+sample_size]])\n              .reshape(((sample_size, 3, image_x, image_y)))\n        offset += sample_size\n        yield ()                                  "}],"metadata":{"_change_revision":0,"_is_fork":false,"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.5.2"}},"nbformat":4,"nbformat_minor":0}