{"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 fastai timm nbdev -q --upgrade","metadata":{"execution":{"iopub.status.busy":"2021-08-15T11:50:57.158594Z","iopub.execute_input":"2021-08-15T11:50:57.159198Z","iopub.status.idle":"2021-08-15T11:52:19.971033Z","shell.execute_reply.started":"2021-08-15T11:50:57.15908Z","shell.execute_reply":"2021-08-15T11:52:19.970022Z"},"collapsed":true,"jupyter":{"outputs_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from fastai.vision.all import *\nimport timm\nimport pandas","metadata":{"execution":{"iopub.status.busy":"2021-08-15T11:52:19.972726Z","iopub.execute_input":"2021-08-15T11:52:19.973007Z","iopub.status.idle":"2021-08-15T11:52:22.560232Z","shell.execute_reply.started":"2021-08-15T11:52:19.972978Z","shell.execute_reply":"2021-08-15T11:52:22.55919Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df = pd.read_csv('../input/landmark-recognition-2021/train.csv')","metadata":{"execution":{"iopub.status.busy":"2021-08-15T11:52:22.562681Z","iopub.execute_input":"2021-08-15T11:52:22.563372Z","iopub.status.idle":"2021-08-15T11:52:23.998718Z","shell.execute_reply.started":"2021-08-15T11:52:22.563323Z","shell.execute_reply":"2021-08-15T11:52:23.997851Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.head()","metadata":{"execution":{"iopub.status.busy":"2021-08-15T11:52:24.000679Z","iopub.execute_input":"2021-08-15T11:52:24.001459Z","iopub.status.idle":"2021-08-15T11:52:24.027509Z","shell.execute_reply.started":"2021-08-15T11:52:24.001411Z","shell.execute_reply":"2021-08-15T11:52:24.026553Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"path = Path('../input/landmark-recognition-2021')\nimg_files_train = get_image_files(path/'train')\nlen(img_files_train)","metadata":{"execution":{"iopub.status.busy":"2021-08-15T11:52:24.028879Z","iopub.execute_input":"2021-08-15T11:52:24.029518Z","iopub.status.idle":"2021-08-15T11:58:04.163564Z","shell.execute_reply.started":"2021-08-15T11:52:24.029466Z","shell.execute_reply":"2021-08-15T11:58:04.162601Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# l = []\n# x_size = []\n# y_size = []\n# for img_file_train in img_files_train :\n#     img = PILImage.create(img_file_train)\n#     l.append(img.shape)\n# for x, y in l :\n#     x_size.append(x)\n#     y_size.append(y)\n# x_size.max(), y_size.max(), x_size.min(), y_size.min()","metadata":{"execution":{"iopub.status.busy":"2021-08-15T11:58:04.165452Z","iopub.execute_input":"2021-08-15T11:58:04.166444Z","iopub.status.idle":"2021-08-15T12:54:35.789503Z","shell.execute_reply.started":"2021-08-15T11:58:04.166366Z","shell.execute_reply":"2021-08-15T12:54:35.787349Z"},"collapsed":true,"jupyter":{"outputs_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in range(100) :\n    file = img_files_train[i]\n    img = PILImage.create(file)\n    print(img.shape)","metadata":{"execution":{"iopub.status.busy":"2021-08-15T12:56:37.964053Z","iopub.execute_input":"2021-08-15T12:56:37.964543Z","iopub.status.idle":"2021-08-15T12:56:39.485034Z","shell.execute_reply.started":"2021-08-15T12:56:37.964497Z","shell.execute_reply":"2021-08-15T12:56:39.483907Z"},"collapsed":true,"jupyter":{"outputs_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"item_tfms = Resize(size = 460)\nbatch_tfms = [*aug_transforms(size = 224, min_scale = 0.35), Normalize.from_stats(*imagenet_stats)]","metadata":{"execution":{"iopub.status.busy":"2021-08-15T12:57:40.868724Z","iopub.execute_input":"2021-08-15T12:57:40.869177Z","iopub.status.idle":"2021-08-15T12:57:41.045624Z","shell.execute_reply.started":"2021-08-15T12:57:40.869141Z","shell.execute_reply":"2021-08-15T12:57:41.044388Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bs = 8","metadata":{"execution":{"iopub.status.busy":"2021-08-15T12:57:43.048037Z","iopub.execute_input":"2021-08-15T12:57:43.048472Z","iopub.status.idle":"2021-08-15T12:57:43.053503Z","shell.execute_reply.started":"2021-08-15T12:57:43.048437Z","shell.execute_reply":"2021-08-15T12:57:43.052163Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"get_x = lambda x: path/'train'/f'{x[0][0]}'/f'{x[0][1]}'/f'{x[0][2]}'/f'{x[0]}.jpg'","metadata":{"execution":{"iopub.status.busy":"2021-08-15T13:21:59.617051Z","iopub.execute_input":"2021-08-15T13:21:59.617487Z","iopub.status.idle":"2021-08-15T13:21:59.623422Z","shell.execute_reply.started":"2021-08-15T13:21:59.61745Z","shell.execute_reply":"2021-08-15T13:21:59.621789Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"get_y = lambda x: x[1]\n# get_y(train_df.values[4])","metadata":{"execution":{"iopub.status.busy":"2021-08-15T13:22:00.907404Z","iopub.execute_input":"2021-08-15T13:22:00.907882Z","iopub.status.idle":"2021-08-15T13:22:00.913099Z","shell.execute_reply.started":"2021-08-15T13:22:00.907838Z","shell.execute_reply":"2021-08-15T13:22:00.911569Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"landmark_dataset = DataBlock(blocks = (ImageBlock, CategoryBlock),\n                             get_x = get_x,\n                             splitter = RandomSplitter(),\n                             get_y = get_y,\n                             item_tfms = item_tfms,\n                             batch_tfms = batch_tfms)","metadata":{"execution":{"iopub.status.busy":"2021-08-15T13:22:56.940101Z","iopub.execute_input":"2021-08-15T13:22:56.941297Z","iopub.status.idle":"2021-08-15T13:22:56.948829Z","shell.execute_reply.started":"2021-08-15T13:22:56.941226Z","shell.execute_reply":"2021-08-15T13:22:56.947738Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dls = landmark_dataset.dataloaders(train_df, bs = bs)","metadata":{"execution":{"iopub.status.busy":"2021-08-15T13:22:58.356993Z","iopub.execute_input":"2021-08-15T13:22:58.357602Z","iopub.status.idle":"2021-08-15T13:27:42.959107Z","shell.execute_reply.started":"2021-08-15T13:22:58.357563Z","shell.execute_reply":"2021-08-15T13:27:42.958051Z"},"collapsed":true,"jupyter":{"outputs_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dls.show_batch(max_n = 8)","metadata":{"execution":{"iopub.status.busy":"2021-08-15T13:29:28.830878Z","iopub.execute_input":"2021-08-15T13:29:28.831319Z","iopub.status.idle":"2021-08-15T13:29:31.437413Z","shell.execute_reply.started":"2021-08-15T13:29:28.831284Z","shell.execute_reply":"2021-08-15T13:29:31.436278Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}