{"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":"markdown","source":"This notebook describe the steps to quick start with FastAI. The dataset is based on the fatastic work by Jonathan [here](https://www.kaggle.com/c/rsna-miccai-brain-tumor-radiogenomic-classification/discussion/253000) ","metadata":{}},{"cell_type":"code","source":"from fastai.vision.all import *","metadata":{"execution":{"iopub.status.busy":"2021-07-28T13:28:01.171365Z","iopub.execute_input":"2021-07-28T13:28:01.171721Z","iopub.status.idle":"2021-07-28T13:28:03.671694Z","shell.execute_reply.started":"2021-07-28T13:28:01.171685Z","shell.execute_reply":"2021-07-28T13:28:03.670876Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from fastai import test_utils\ntest_utils.show_install()","metadata":{"execution":{"iopub.status.busy":"2021-07-28T13:28:59.112233Z","iopub.execute_input":"2021-07-28T13:28:59.112576Z","iopub.status.idle":"2021-07-28T13:28:59.189853Z","shell.execute_reply.started":"2021-07-28T13:28:59.112544Z","shell.execute_reply":"2021-07-28T13:28:59.188944Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def seed_everything(seed=0):\n    random.seed(seed)\n    os.environ['PYTHONHASHSEED'] = str(seed)\n    np.random.seed(seed)\n    torch.manual_seed(seed)\n    torch.cuda.manual_seed(seed)\n    torch.backends.cudnn.deterministic = True\n\nseed_everything()","metadata":{"execution":{"iopub.status.busy":"2021-07-28T10:29:04.827214Z","iopub.execute_input":"2021-07-28T10:29:04.827524Z","iopub.status.idle":"2021-07-28T10:29:04.832745Z","shell.execute_reply.started":"2021-07-28T10:29:04.827492Z","shell.execute_reply":"2021-07-28T10:29:04.832005Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"path = Path('../input/rsna-miccai-png/'); path.ls()","metadata":{"execution":{"iopub.status.busy":"2021-07-28T10:29:04.834726Z","iopub.execute_input":"2021-07-28T10:29:04.83537Z","iopub.status.idle":"2021-07-28T10:29:04.858022Z","shell.execute_reply.started":"2021-07-28T10:29:04.83533Z","shell.execute_reply":"2021-07-28T10:29:04.856995Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dls = ImageDataLoaders.from_folder(path, train='train',\n                                   item_tfms=Resize(224),valid_pct=0.2,\n                                   bs=64,seed=0)","metadata":{"execution":{"iopub.status.busy":"2021-07-28T10:29:04.859791Z","iopub.execute_input":"2021-07-28T10:29:04.860177Z","iopub.status.idle":"2021-07-28T10:31:09.044586Z","shell.execute_reply.started":"2021-07-28T10:29:04.86014Z","shell.execute_reply":"2021-07-28T10:31:09.043779Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dls.show_batch()","metadata":{"execution":{"iopub.status.busy":"2021-07-28T10:31:09.045839Z","iopub.execute_input":"2021-07-28T10:31:09.046161Z","iopub.status.idle":"2021-07-28T10:31:10.951218Z","shell.execute_reply.started":"2021-07-28T10:31:09.046126Z","shell.execute_reply":"2021-07-28T10:31:10.950303Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(dls.vocab); print(dls.c)","metadata":{"execution":{"iopub.status.busy":"2021-07-28T10:31:10.952264Z","iopub.execute_input":"2021-07-28T10:31:10.952575Z","iopub.status.idle":"2021-07-28T10:31:10.958555Z","shell.execute_reply.started":"2021-07-28T10:31:10.952541Z","shell.execute_reply":"2021-07-28T10:31:10.957637Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"learn = cnn_learner(dls, resnet34, metrics=[error_rate, accuracy], model_dir=\"/tmp/model/\").to_fp16()","metadata":{"execution":{"iopub.status.busy":"2021-07-28T10:31:10.959773Z","iopub.execute_input":"2021-07-28T10:31:10.960351Z","iopub.status.idle":"2021-07-28T10:31:13.540299Z","shell.execute_reply.started":"2021-07-28T10:31:10.960311Z","shell.execute_reply":"2021-07-28T10:31:13.539425Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"learn.lr_find()","metadata":{"execution":{"iopub.status.busy":"2021-07-28T10:31:13.542535Z","iopub.execute_input":"2021-07-28T10:31:13.542965Z","iopub.status.idle":"2021-07-28T10:31:57.034856Z","shell.execute_reply.started":"2021-07-28T10:31:13.542927Z","shell.execute_reply":"2021-07-28T10:31:57.034037Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"learn.fit_one_cycle(1, lr_max=1e-2, cbs=ShortEpochCallback())","metadata":{"execution":{"iopub.status.busy":"2021-07-28T10:46:08.759449Z","iopub.execute_input":"2021-07-28T10:46:08.759793Z","iopub.status.idle":"2021-07-28T10:46:33.080902Z","shell.execute_reply.started":"2021-07-28T10:46:08.759741Z","shell.execute_reply":"2021-07-28T10:46:33.080004Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"learn.show_results()","metadata":{"execution":{"iopub.status.busy":"2021-07-28T10:47:04.179334Z","iopub.execute_input":"2021-07-28T10:47:04.179667Z","iopub.status.idle":"2021-07-28T10:47:11.538907Z","shell.execute_reply.started":"2021-07-28T10:47:04.179632Z","shell.execute_reply":"2021-07-28T10:47:11.537961Z"},"trusted":true},"execution_count":null,"outputs":[]}]}