{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","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\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2021-10-29T19:41:49.876403Z","iopub.execute_input":"2021-10-29T19:41:49.876734Z","iopub.status.idle":"2021-10-29T19:41:49.889263Z","shell.execute_reply.started":"2021-10-29T19:41:49.876701Z","shell.execute_reply":"2021-10-29T19:41:49.888006Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"! unzip /kaggle/input/dogs-vs-cats/test1.zip","metadata":{"execution":{"iopub.status.busy":"2021-10-29T19:41:52.123417Z","iopub.execute_input":"2021-10-29T19:41:52.123835Z","iopub.status.idle":"2021-10-29T19:42:06.022565Z","shell.execute_reply.started":"2021-10-29T19:41:52.123798Z","shell.execute_reply":"2021-10-29T19:42:06.021594Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"! unzip /kaggle/input/dogs-vs-cats/train.zip","metadata":{"execution":{"iopub.status.busy":"2021-10-29T19:03:37.270257Z","iopub.execute_input":"2021-10-29T19:03:37.271295Z","iopub.status.idle":"2021-10-29T19:03:50.708231Z","shell.execute_reply.started":"2021-10-29T19:03:37.271235Z","shell.execute_reply":"2021-10-29T19:03:50.706581Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport random\nimport tensorflow as tf\nimport os\nimport shutil\nimport glob","metadata":{"execution":{"iopub.status.busy":"2021-10-29T19:42:10.241228Z","iopub.execute_input":"2021-10-29T19:42:10.241537Z","iopub.status.idle":"2021-10-29T19:42:10.246307Z","shell.execute_reply.started":"2021-10-29T19:42:10.241504Z","shell.execute_reply":"2021-10-29T19:42:10.245692Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_path='./train'\ntest_path='./test1'","metadata":{"execution":{"iopub.status.busy":"2021-10-29T19:42:33.942887Z","iopub.execute_input":"2021-10-29T19:42:33.943191Z","iopub.status.idle":"2021-10-29T19:42:33.948340Z","shell.execute_reply.started":"2021-10-29T19:42:33.943158Z","shell.execute_reply":"2021-10-29T19:42:33.947197Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def plot_imgs(item_dir, top=10):\n    all_item_dirs = os.listdir(item_dir)\n    item_files = [os.path.join(item_dir, file) for file in all_item_dirs][100:106]\n  \n    plt.figure(figsize=(10, 10))\n  \n    for idx, img_path in enumerate(item_files):\n        plt.subplot(1, 6, idx+1)        \n        img = plt.imread(img_path)\n        plt.tight_layout() \n        plt.axis('off')\n        plt.imshow(img, cmap='gray')","metadata":{"execution":{"iopub.status.busy":"2021-10-29T19:42:37.007702Z","iopub.execute_input":"2021-10-29T19:42:37.008619Z","iopub.status.idle":"2021-10-29T19:42:37.015600Z","shell.execute_reply.started":"2021-10-29T19:42:37.008578Z","shell.execute_reply":"2021-10-29T19:42:37.014751Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img_height = 224\nimg_width = 224\n\ntraining_data_gen = tf.keras.preprocessing.image.ImageDataGenerator(\n                                                                    rescale=1/255.0,\n                                                                    validation_split=0.15)\n\ntrain_generator = training_data_gen.flow_from_directory(train_path,\n                                                        target_size=(img_height, img_width),\n                                                        batch_size=64,\n                                                        shuffle=True,\n                                                        class_mode='categorical',\n                                                        subset='training') # set as training data\n\nvalidation_generator = training_data_gen.flow_from_directory(train_path, # same directory as training data\n                                                             target_size=(img_height, img_width),\n                                                             batch_size=64,\n                                                             shuffle=True,\n                                                             class_mode='categorical',\n                                                             subset='validation') # set as validation data\n \n\ntesting_data_gen = tf.keras.preprocessing.image.ImageDataGenerator(rescale=1/255.0)\n\ntest_generator = testing_data_gen.flow_from_directory(test_path,\n                                                      target_size=(img_height, img_width),\n                                                      batch_size=60,\n                                                      seed=0,\n                                                      shuffle=False,\n                                                      class_mode='categorical') ","metadata":{"execution":{"iopub.status.busy":"2021-10-29T19:42:41.150596Z","iopub.execute_input":"2021-10-29T19:42:41.150912Z","iopub.status.idle":"2021-10-29T19:42:41.898048Z","shell.execute_reply.started":"2021-10-29T19:42:41.150878Z","shell.execute_reply":"2021-10-29T19:42:41.897037Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}