{"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":"import os\nimport pandas as pd\nimport numpy as np","metadata":{"execution":{"iopub.status.busy":"2022-03-30T13:47:57.036526Z","iopub.execute_input":"2022-03-30T13:47:57.036912Z","iopub.status.idle":"2022-03-30T13:47:57.041947Z","shell.execute_reply.started":"2022-03-30T13:47:57.036872Z","shell.execute_reply":"2022-03-30T13:47:57.040904Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"species = ['beluga', 'gray_whale', 'southern_right_whale']","metadata":{"execution":{"iopub.status.busy":"2022-03-30T13:46:01.350057Z","iopub.execute_input":"2022-03-30T13:46:01.350622Z","iopub.status.idle":"2022-03-30T13:46:01.358882Z","shell.execute_reply.started":"2022-03-30T13:46:01.350543Z","shell.execute_reply":"2022-03-30T13:46:01.358042Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"t2 = pd.read_csv('../input/happy-whale-and-dolphin/train.csv')\nimgs = t2[t2['species'].isin(species)]['image'].values","metadata":{"execution":{"iopub.status.busy":"2022-03-30T13:46:01.360892Z","iopub.execute_input":"2022-03-30T13:46:01.361276Z","iopub.status.idle":"2022-03-30T13:46:01.457871Z","shell.execute_reply.started":"2022-03-30T13:46:01.36123Z","shell.execute_reply":"2022-03-30T13:46:01.456988Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!mkdir train_imgs","metadata":{"execution":{"iopub.status.busy":"2022-03-30T13:46:01.459236Z","iopub.execute_input":"2022-03-30T13:46:01.459516Z","iopub.status.idle":"2022-03-30T13:46:02.215554Z","shell.execute_reply.started":"2022-03-30T13:46:01.459477Z","shell.execute_reply":"2022-03-30T13:46:02.214611Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from shutil import copyfile\nfrom tqdm import tqdm\nfor img in tqdm(imgs):\n    copyfile('../input/happy-whale-and-dolphin/train_images/' + img, './train_imgs/'+img)","metadata":{"execution":{"iopub.status.busy":"2022-03-30T13:46:02.217104Z","iopub.execute_input":"2022-03-30T13:46:02.217388Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os, zipfile\n#打包目录为zip文件（未压缩）\ndef make_zip(source_dir, output_filename):\n  zipf = zipfile.ZipFile(output_filename, 'w')\n  pre_len = len(os.path.dirname(source_dir))\n  for parent, dirnames, filenames in os.walk(source_dir):\n    for filename in filenames:\n      pathfile = os.path.join(parent, filename)\n      arcname = pathfile[pre_len:].strip(os.path.sep)   #相对路径\n      zipf.write(pathfile, arcname)\n  zipf.close()","metadata":{"execution":{"iopub.status.busy":"2022-03-30T13:47:59.891732Z","iopub.execute_input":"2022-03-30T13:47:59.892673Z","iopub.status.idle":"2022-03-30T13:47:59.899929Z","shell.execute_reply.started":"2022-03-30T13:47:59.892622Z","shell.execute_reply":"2022-03-30T13:47:59.898971Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"make_zip('./train_imgs', 'train_imgs.zip')","metadata":{"execution":{"iopub.status.busy":"2022-03-30T13:48:01.667425Z","iopub.execute_input":"2022-03-30T13:48:01.667733Z","iopub.status.idle":"2022-03-30T13:48:41.703629Z","shell.execute_reply.started":"2022-03-30T13:48:01.667698Z","shell.execute_reply":"2022-03-30T13:48:41.702597Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!rm ./train_imgs/*.jpg","metadata":{},"execution_count":null,"outputs":[]}]}