{"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-05-26T14:47:55.77366Z","iopub.execute_input":"2021-05-26T14:47:55.774008Z","iopub.status.idle":"2021-05-26T14:47:55.78012Z","shell.execute_reply.started":"2021-05-26T14:47:55.773979Z","shell.execute_reply":"2021-05-26T14:47:55.779214Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from fastai import *\nfrom fastai.vision.all import *","metadata":{"execution":{"iopub.status.busy":"2021-05-26T14:48:47.231487Z","iopub.execute_input":"2021-05-26T14:48:47.231833Z","iopub.status.idle":"2021-05-26T14:48:50.529358Z","shell.execute_reply.started":"2021-05-26T14:48:47.2318Z","shell.execute_reply":"2021-05-26T14:48:50.528556Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"os.chdir(\"/kaggle/working\")\n!ls\n#! unzip ../input/dogs-vs-cats/test1.zip -d ../working\n#! unzip ../input/dogs-vs-cats/train.zip -d ../working\ntrain_path= \"/kaggle/working/train\"\ntest_path= \"/kaggle/working/test1\"\n\ntrain_im= get_image_files(\"/kaggle/working/train\")\ntest_im= get_image_files(\"/kaggle/working/test1\")\nlen(train_im)","metadata":{"execution":{"iopub.status.busy":"2021-05-26T14:57:47.767944Z","iopub.execute_input":"2021-05-26T14:57:47.768276Z","iopub.status.idle":"2021-05-26T14:57:48.814581Z","shell.execute_reply.started":"2021-05-26T14:57:47.768244Z","shell.execute_reply":"2021-05-26T14:57:48.813682Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def label(f): \n    return f[0]==\"c\"","metadata":{"execution":{"iopub.status.busy":"2021-05-26T14:57:51.838453Z","iopub.execute_input":"2021-05-26T14:57:51.838792Z","iopub.status.idle":"2021-05-26T14:57:51.842579Z","shell.execute_reply.started":"2021-05-26T14:57:51.83876Z","shell.execute_reply":"2021-05-26T14:57:51.841758Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dls = ImageDataLoaders.from_name_func(train_path, train_im, label, item_tfms=Resize(224))","metadata":{"execution":{"iopub.status.busy":"2021-05-26T14:58:27.729578Z","iopub.execute_input":"2021-05-26T14:58:27.730062Z","iopub.status.idle":"2021-05-26T14:58:34.117941Z","shell.execute_reply.started":"2021-05-26T14:58:27.730014Z","shell.execute_reply":"2021-05-26T14:58:34.116964Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dls.show_batch()","metadata":{"execution":{"iopub.status.busy":"2021-05-26T14:58:48.102268Z","iopub.execute_input":"2021-05-26T14:58:48.102605Z","iopub.status.idle":"2021-05-26T14:58:49.431895Z","shell.execute_reply.started":"2021-05-26T14:58:48.102574Z","shell.execute_reply":"2021-05-26T14:58:49.431025Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"learn = cnn_learner(dls, resnet34, metrics=error_rate)\nlearn.model","metadata":{"execution":{"iopub.status.busy":"2021-05-26T14:58:58.605713Z","iopub.execute_input":"2021-05-26T14:58:58.606053Z","iopub.status.idle":"2021-05-26T14:59:03.172923Z","shell.execute_reply.started":"2021-05-26T14:58:58.606023Z","shell.execute_reply":"2021-05-26T14:59:03.1718Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"learn.fine_tune(1)","metadata":{"execution":{"iopub.status.busy":"2021-05-26T14:59:15.054205Z","iopub.execute_input":"2021-05-26T14:59:15.054556Z","iopub.status.idle":"2021-05-26T15:03:06.269269Z","shell.execute_reply.started":"2021-05-26T14:59:15.054525Z","shell.execute_reply":"2021-05-26T15:03:06.268534Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"learn.predict(test_im[0])","metadata":{"execution":{"iopub.status.busy":"2021-05-26T15:03:12.566581Z","iopub.execute_input":"2021-05-26T15:03:12.566956Z","iopub.status.idle":"2021-05-26T15:03:12.790445Z","shell.execute_reply.started":"2021-05-26T15:03:12.566924Z","shell.execute_reply":"2021-05-26T15:03:12.789609Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"learn.show_results()","metadata":{"execution":{"iopub.status.busy":"2021-05-26T15:03:28.50292Z","iopub.execute_input":"2021-05-26T15:03:28.503252Z","iopub.status.idle":"2021-05-26T15:03:29.65887Z","shell.execute_reply.started":"2021-05-26T15:03:28.503222Z","shell.execute_reply":"2021-05-26T15:03:29.657851Z"},"trusted":true},"execution_count":null,"outputs":[]}]}