{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"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 in \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 \"../input/\" directory.\n# For example, running this (by clicking run or pressing Shift+Enter) will list the files in the input directory\n\nimport os\nprint(os.listdir(\"/tmp/input/train\"))\n\n# Any results you write to the current directory are saved as output.","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":true},"cell_type":"code","source":"%reload_ext autoreload\n%autoreload 2\n%matplotlib inline\nfrom fastai import *\nfrom fastai.vision import *\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"c6709dc7e982d24605b3782cc62c8d81cdb03917"},"cell_type":"code","source":"path_images=\"/tmp/input/train/\"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"774526e7f74922e5f1f7331a0bbea88c73d28d02"},"cell_type":"code","source":"path_images","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"1906924b2bd89aea5e56eebc7274f4574c825413"},"cell_type":"markdown","source":""},{"metadata":{"trusted":true,"_uuid":"020ffb8aeaa8ca2139d0907ae76e6163703e9fae"},"cell_type":"code","source":"fnames = get_image_files(path_images)\nfnames","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"79dd9e2df4083a30d44caae596435466946c206f"},"cell_type":"code","source":"np.random.seed(2)\npat = re.compile(r'/([a-z]+).\\d+.jpg$')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"d8eee02ed4c9cad863f099bbf0dfa56da9a2fd6a"},"cell_type":"code","source":"pat","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"4e3b8f66e68400d2086b236bd6b66049db3be59a"},"cell_type":"code","source":"bs=64\ndata = ImageDataBunch.from_name_re(path_images, fnames, pat, ds_tfms=get_transforms(), size=224, bs=bs, num_workers=0\n                                  ).normalize(imagenet_stats)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"10865b8b17505211b72d6cae1e1f0278c0270d3f"},"cell_type":"code","source":"data.show_batch(rows=3, figsize=(7,6))\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"998b75d6d36d0fb018715d1e5e87a90548822f51"},"cell_type":"code","source":"print(data.classes)\nlen(data.classes),data.c","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"af21f3aba7757c9db34017ad749f545e3c1398c5"},"cell_type":"code","source":"learn = create_cnn(data, models.resnet34, metrics=error_rate)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"265b46e684c71a4aaa14f87116c1066db0d37023"},"cell_type":"code","source":"learn.fit_one_cycle(5)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"c4a176b7bf8c135e81a7e34c3dfbefa5ac1eddf3"},"cell_type":"code","source":"learn.save('stage-1')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"c20157bd737b6e3fecf2330de9419eb441a23d88"},"cell_type":"code","source":"interp = ClassificationInterpretation.from_learner(learn)\n\nlosses,idxs = interp.top_losses()\n\nlen(data.valid_ds)==len(losses)==len(idxs)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"53a7ba6cbc9958b93909920cf42b100293e4c98b"},"cell_type":"code","source":"interp.plot_top_losses(9, figsize=(15,11))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"695e9bd973fd3903a0cacd98a05f07a28c91817c"},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.6.6","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat":4,"nbformat_minor":1}