{"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":"%pip install -Uqq fastai","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from fastai.vision.all import *\nimport pandas as pd","metadata":{"execution":{"iopub.status.busy":"2022-03-16T09:50:19.007154Z","iopub.execute_input":"2022-03-16T09:50:19.007760Z","iopub.status.idle":"2022-03-16T09:50:22.185917Z","shell.execute_reply.started":"2022-03-16T09:50:19.007597Z","shell.execute_reply":"2022-03-16T09:50:22.184872Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"path = Path(\"/kaggle/input/ultramnist500px\")\npath.ls()","metadata":{"execution":{"iopub.status.busy":"2022-03-16T09:50:29.073322Z","iopub.execute_input":"2022-03-16T09:50:29.073612Z","iopub.status.idle":"2022-03-16T09:50:29.089426Z","shell.execute_reply.started":"2022-03-16T09:50:29.073579Z","shell.execute_reply":"2022-03-16T09:50:29.088284Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.read_csv(path/\"train.csv\")\ndf.head()","metadata":{"execution":{"iopub.status.busy":"2022-03-16T09:50:34.675479Z","iopub.execute_input":"2022-03-16T09:50:34.675796Z","iopub.status.idle":"2022-03-16T09:50:34.723892Z","shell.execute_reply.started":"2022-03-16T09:50:34.675763Z","shell.execute_reply":"2022-03-16T09:50:34.722872Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dls = ImageDataLoaders.from_df(df, path, folder='train', suff=\".jpeg\")","metadata":{"execution":{"iopub.status.busy":"2022-03-16T09:50:35.762173Z","iopub.execute_input":"2022-03-16T09:50:35.762476Z","iopub.status.idle":"2022-03-16T09:50:43.550731Z","shell.execute_reply.started":"2022-03-16T09:50:35.762443Z","shell.execute_reply":"2022-03-16T09:50:43.549735Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dls.show_batch()","metadata":{"execution":{"iopub.status.busy":"2022-03-16T09:50:43.552708Z","iopub.execute_input":"2022-03-16T09:50:43.553148Z","iopub.status.idle":"2022-03-16T09:50:45.359494Z","shell.execute_reply.started":"2022-03-16T09:50:43.553108Z","shell.execute_reply":"2022-03-16T09:50:45.358497Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"learn = cnn_learner(dls, resnet34, metrics=accuracy, model_dir=\"/kaggle/working\").to_fp16()","metadata":{"execution":{"iopub.status.busy":"2022-03-16T09:50:45.361004Z","iopub.execute_input":"2022-03-16T09:50:45.362985Z","iopub.status.idle":"2022-03-16T09:50:49.592869Z","shell.execute_reply.started":"2022-03-16T09:50:45.362939Z","shell.execute_reply":"2022-03-16T09:50:49.591861Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"learn.lr_find()","metadata":{"execution":{"iopub.status.busy":"2022-03-16T09:50:49.595103Z","iopub.execute_input":"2022-03-16T09:50:49.595530Z","iopub.status.idle":"2022-03-16T09:51:51.361006Z","shell.execute_reply.started":"2022-03-16T09:50:49.595480Z","shell.execute_reply":"2022-03-16T09:51:51.359787Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"learn.fine_tune(2, 0.003, cbs=SaveModelCallback(monitor=\"accuracy\"))","metadata":{"execution":{"iopub.status.busy":"2022-03-16T09:53:36.851642Z","iopub.execute_input":"2022-03-16T09:53:36.851981Z","iopub.status.idle":"2022-03-16T10:07:29.691018Z","shell.execute_reply.started":"2022-03-16T09:53:36.851942Z","shell.execute_reply":"2022-03-16T10:07:29.689895Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"learn.show_results()","metadata":{"execution":{"iopub.status.busy":"2022-03-16T10:11:09.917783Z","iopub.execute_input":"2022-03-16T10:11:09.918176Z","iopub.status.idle":"2022-03-16T10:11:12.168308Z","shell.execute_reply.started":"2022-03-16T10:11:09.918141Z","shell.execute_reply":"2022-03-16T10:11:12.167432Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_files = (path/'test').ls()\ntest_dl = learn.dls.test_dl(test_files)\npreds, _, decoded = learn.get_preds(dl=test_dl, with_decoded=True)\nfile_names = [file.name[:-5] for file in test_files]\nsubmission = pd.read_csv(path/'sample_submission.csv')\nsubmission[\"digit_sum\"] = decoded\nsubmission[\"id\"] = file_names","metadata":{"execution":{"iopub.status.busy":"2022-03-16T10:11:16.404362Z","iopub.execute_input":"2022-03-16T10:11:16.405085Z","iopub.status.idle":"2022-03-16T10:14:01.586278Z","shell.execute_reply.started":"2022-03-16T10:11:16.405050Z","shell.execute_reply":"2022-03-16T10:14:01.585161Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission.head()","metadata":{"execution":{"iopub.status.busy":"2022-03-16T10:14:16.141638Z","iopub.execute_input":"2022-03-16T10:14:16.141985Z","iopub.status.idle":"2022-03-16T10:14:16.153389Z","shell.execute_reply.started":"2022-03-16T10:14:16.141952Z","shell.execute_reply":"2022-03-16T10:14:16.152105Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission.to_csv(\"submission.csv\", index=False)","metadata":{"execution":{"iopub.status.busy":"2022-03-16T10:14:18.722640Z","iopub.execute_input":"2022-03-16T10:14:18.723345Z","iopub.status.idle":"2022-03-16T10:14:18.785491Z","shell.execute_reply.started":"2022-03-16T10:14:18.723309Z","shell.execute_reply":"2022-03-16T10:14:18.784406Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}