{"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":"# Introduction\n\nSample training images and test masks, so I can easily download them locally to play with them.","metadata":{}},{"cell_type":"code","source":"import os\nimport glob","metadata":{"execution":{"iopub.status.busy":"2022-04-13T21:51:25.065202Z","iopub.execute_input":"2022-04-13T21:51:25.065526Z","iopub.status.idle":"2022-04-13T21:51:25.070937Z","shell.execute_reply.started":"2022-04-13T21:51:25.065491Z","shell.execute_reply":"2022-04-13T21:51:25.069815Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"NUM_TRAIN_IMAGES=50\nNUM_TEST_MASKS=50","metadata":{"execution":{"iopub.status.busy":"2022-04-13T21:51:25.176212Z","iopub.execute_input":"2022-04-13T21:51:25.176482Z","iopub.status.idle":"2022-04-13T21:51:25.180314Z","shell.execute_reply.started":"2022-04-13T21:51:25.176454Z","shell.execute_reply":"2022-04-13T21:51:25.179487Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_folder = \"/kaggle/input/hotel-id-to-combat-human-trafficking-2022-fgvc9/\"\ntrain_folder = os.path.join(data_folder, 'train_images')\n# yep, test masks are in the \"train_masks\" folder\n# see https://www.kaggle.com/competitions/hotel-id-to-combat-human-trafficking-2022-fgvc9/discussion/313547\ntest_mask_folder = os.path.join(data_folder, 'train_masks')","metadata":{"papermill":{"duration":0.225587,"end_time":"2021-04-16T01:53:14.982769","exception":false,"start_time":"2021-04-16T01:53:14.757182","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-04-13T21:51:25.287235Z","iopub.execute_input":"2022-04-13T21:51:25.287511Z","iopub.status.idle":"2022-04-13T21:51:25.293278Z","shell.execute_reply.started":"2022-04-13T21:51:25.287481Z","shell.execute_reply":"2022-04-13T21:51:25.292175Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_image_paths = glob.glob(train_folder + \"/*/*\")\ntest_mask_paths = glob.glob(test_mask_folder + \"/*\")","metadata":{"execution":{"iopub.status.busy":"2022-04-13T21:51:25.405076Z","iopub.execute_input":"2022-04-13T21:51:25.405653Z","iopub.status.idle":"2022-04-13T21:51:27.907862Z","shell.execute_reply.started":"2022-04-13T21:51:25.405600Z","shell.execute_reply":"2022-04-13T21:51:27.907049Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(len(train_image_paths))\nprint(len(test_mask_paths))","metadata":{"execution":{"iopub.status.busy":"2022-04-13T21:51:27.909840Z","iopub.execute_input":"2022-04-13T21:51:27.910235Z","iopub.status.idle":"2022-04-13T21:51:27.917421Z","shell.execute_reply.started":"2022-04-13T21:51:27.910171Z","shell.execute_reply":"2022-04-13T21:51:27.916363Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import random\n\ntrain_image_paths_sample = random.sample(train_image_paths, NUM_TRAIN_IMAGES)\ntest_mask_paths_sample = random.sample(test_mask_paths, NUM_TEST_MASKS)","metadata":{"execution":{"iopub.status.busy":"2022-04-13T21:51:27.919080Z","iopub.execute_input":"2022-04-13T21:51:27.919571Z","iopub.status.idle":"2022-04-13T21:51:27.934839Z","shell.execute_reply.started":"2022-04-13T21:51:27.919529Z","shell.execute_reply":"2022-04-13T21:51:27.933906Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(len(train_image_paths_sample))\nprint(len(test_mask_paths_sample))\n\n# print(train_image_paths_sample)\n# print(test_mask_paths_sample)","metadata":{"execution":{"iopub.status.busy":"2022-04-13T21:51:27.936672Z","iopub.execute_input":"2022-04-13T21:51:27.937388Z","iopub.status.idle":"2022-04-13T21:51:27.948148Z","shell.execute_reply.started":"2022-04-13T21:51:27.937347Z","shell.execute_reply":"2022-04-13T21:51:27.947404Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!cd /kaggle/working\n!rm -rf train_sample\n!rm -rf test_mask_sample\n!mkdir train_sample\n!mkdir test_mask_sample","metadata":{"papermill":{"duration":401.161771,"end_time":"2021-04-16T02:41:50.796691","exception":false,"start_time":"2021-04-16T02:35:09.63492","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-04-13T21:51:27.949092Z","iopub.execute_input":"2022-04-13T21:51:27.949868Z","iopub.status.idle":"2022-04-13T21:51:31.728952Z","shell.execute_reply.started":"2022-04-13T21:51:27.949833Z","shell.execute_reply":"2022-04-13T21:51:31.727848Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pathlib\nimport shutil","metadata":{"execution":{"iopub.status.busy":"2022-04-13T21:51:31.730506Z","iopub.execute_input":"2022-04-13T21:51:31.730773Z","iopub.status.idle":"2022-04-13T21:51:31.735169Z","shell.execute_reply.started":"2022-04-13T21:51:31.730730Z","shell.execute_reply":"2022-04-13T21:51:31.734554Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"root_destdir = '/kaggle/working/train_sample'\n\nfor path in train_image_paths_sample:\n    the_path = pathlib.PurePath(path)\n    the_chain = the_path.parts[-2]\n    destdir = root_destdir + '/' + the_chain\n    if not os.path.isdir(destdir):\n        # print(f\"make {destdir}\")\n        os.mkdir(destdir)\n    shutil.copy(path, destdir)","metadata":{"execution":{"iopub.status.busy":"2022-04-13T21:51:31.736237Z","iopub.execute_input":"2022-04-13T21:51:31.736557Z","iopub.status.idle":"2022-04-13T21:51:32.326787Z","shell.execute_reply.started":"2022-04-13T21:51:31.736531Z","shell.execute_reply":"2022-04-13T21:51:32.325746Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"destdir = '/kaggle/working/test_mask_sample'\n\nfor path in test_mask_paths_sample:\n    # print(f\"copy {path} to {destdir}\")\n    shutil.copy(path, destdir)","metadata":{"execution":{"iopub.status.busy":"2022-04-13T21:51:32.328316Z","iopub.execute_input":"2022-04-13T21:51:32.328533Z","iopub.status.idle":"2022-04-13T21:51:32.751003Z","shell.execute_reply.started":"2022-04-13T21:51:32.328507Z","shell.execute_reply":"2022-04-13T21:51:32.749923Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!cd /kaggle/working && find . -name \"*.zip\" -delete\n\n!cd /kaggle/working && zip -r train_sample.zip train_sample\n!cd /kaggle/working && zip -r test_mask_sample.zip test_mask_sample\n\n!cd /kaggle/working && find . -name \"*.jpg\" -o -name \"*.png\" -delete","metadata":{"execution":{"iopub.status.busy":"2022-04-13T21:51:32.753110Z","iopub.execute_input":"2022-04-13T21:51:32.753676Z","iopub.status.idle":"2022-04-13T21:51:36.571530Z","shell.execute_reply.started":"2022-04-13T21:51:32.753629Z","shell.execute_reply":"2022-04-13T21:51:36.570507Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# !ls /kaggle/working/train_sample\n# !ls /kaggle/working/test_mask_sample\n!ls /kaggle/working/*.zip\n!unzip -l train_sample.zip\n!unzip -l test_mask_sample.zip","metadata":{"execution":{"iopub.status.busy":"2022-04-13T21:51:36.573852Z","iopub.execute_input":"2022-04-13T21:51:36.574220Z","iopub.status.idle":"2022-04-13T21:51:38.844970Z","shell.execute_reply.started":"2022-04-13T21:51:36.574178Z","shell.execute_reply":"2022-04-13T21:51:38.843766Z"},"trusted":true},"execution_count":null,"outputs":[]}]}