{"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\nfrom PIL import Image\nimport numpy as np\nfrom tqdm import tqdm\nimport shutil\nfrom joblib import Parallel, delayed\n","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-02-12T01:44:43.884056Z","iopub.execute_input":"2023-02-12T01:44:43.884695Z","iopub.status.idle":"2023-02-12T01:44:43.922694Z","shell.execute_reply.started":"2023-02-12T01:44:43.884461Z","shell.execute_reply":"2023-02-12T01:44:43.921855Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = pd.read_csv('/kaggle/input/rsna-breast-cancer-detection/train.csv')\nfolders = os.listdir(\"/kaggle/input/rsna-mammography-images-as-pngs/images_as_pngs_cv2_vl_768/train_images_processed_cv2_vl_768\")","metadata":{"execution":{"iopub.status.busy":"2023-02-12T01:44:44.656804Z","iopub.execute_input":"2023-02-12T01:44:44.657225Z","iopub.status.idle":"2023-02-12T01:44:44.749607Z","shell.execute_reply.started":"2023-02-12T01:44:44.657191Z","shell.execute_reply":"2023-02-12T01:44:44.748397Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"base = '/kaggle/input/rsna-mammography-images-as-pngs/images_as_pngs_cv2_vl_768/train_images_processed_cv2_vl_768'\npath_save = \"rsna_mammography_768_vl_perclass\"\n","metadata":{"execution":{"iopub.status.busy":"2023-02-12T01:44:51.397122Z","iopub.execute_input":"2023-02-12T01:44:51.397996Z","iopub.status.idle":"2023-02-12T01:44:51.401843Z","shell.execute_reply.started":"2023-02-12T01:44:51.397954Z","shell.execute_reply":"2023-02-12T01:44:51.401131Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"if not os.path.exists(path_save):\n    os.mkdir(path_save)\n    os.mkdir(os.path.join(path_save, '0'))\n    os.mkdir(os.path.join(path_save, '1'))\n\n\ndef transfer_data(folder, base, path_save):\n    files = os.listdir(os.path.join(base, folder))\n    for file in files:\n        path = os.path.join(base, folder, file)\n        if train.loc[(train.patient_id == int(folder)) & (train.image_id== int(file[:-4])),'cancer'].values == 0:\n            shutil.copy(path, os.path.join(path_save, '0'))\n            \n        elif train.loc[(train.patient_id == int(folder)) & (train.image_id==int(file[:-4])),'cancer'].values == 1:\n            shutil.copy(path, os.path.join(path_save, '1'))\n            \n        else:\n            print('problem!')\n        \n           \nresults = Parallel(n_jobs=8)(delayed(transfer_data)(folder, base, path_save) for folder in tqdm(folders))","metadata":{"execution":{"iopub.status.busy":"2023-02-12T01:45:12.554341Z","iopub.execute_input":"2023-02-12T01:45:12.554795Z","iopub.status.idle":"2023-02-12T01:45:20.900977Z","shell.execute_reply.started":"2023-02-12T01:45:12.554749Z","shell.execute_reply":"2023-02-12T01:45:20.899585Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}