{"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 pandas as pd, numpy as np\nimport os, shutil\nfrom glob import glob\nfrom tqdm import tqdm\nimport cv2\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nfrom colorama import Fore, Back, Style\nsns.set(style='dark')","metadata":{"execution":{"iopub.status.busy":"2023-02-19T06:40:19.002331Z","iopub.execute_input":"2023-02-19T06:40:19.002763Z","iopub.status.idle":"2023-02-19T06:40:20.288821Z","shell.execute_reply.started":"2023-02-19T06:40:19.002723Z","shell.execute_reply":"2023-02-19T06:40:20.287569Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset_dir = '/kaggle/input/cbis-ddsm-breast-cancer-image-dataset'","metadata":{"execution":{"iopub.status.busy":"2023-02-19T06:40:20.29172Z","iopub.execute_input":"2023-02-19T06:40:20.292248Z","iopub.status.idle":"2023-02-19T06:40:20.298009Z","shell.execute_reply.started":"2023-02-19T06:40:20.292194Z","shell.execute_reply":"2023-02-19T06:40:20.296784Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## dicom_info.csv","metadata":{}},{"cell_type":"code","source":"df = pd.read_csv(f'{dataset_dir}/csv/dicom_info.csv')\ndf['image_path'] = df.image_path.apply(lambda x: x.replace('CBIS-DDSM', dataset_dir))\ndf.head()","metadata":{"execution":{"iopub.status.busy":"2023-02-19T06:40:20.300426Z","iopub.execute_input":"2023-02-19T06:40:20.301059Z","iopub.status.idle":"2023-02-19T06:40:20.650653Z","shell.execute_reply.started":"2023-02-19T06:40:20.301017Z","shell.execute_reply":"2023-02-19T06:40:20.649488Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.SeriesDescription.unique(),len(df.SeriesDescription)","metadata":{"execution":{"iopub.status.busy":"2023-02-19T06:40:20.652321Z","iopub.execute_input":"2023-02-19T06:40:20.652791Z","iopub.status.idle":"2023-02-19T06:40:20.661706Z","shell.execute_reply.started":"2023-02-19T06:40:20.652743Z","shell.execute_reply":"2023-02-19T06:40:20.660273Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# sum(df.SeriesDescription == 'cropped images')\n# sum(df.SeriesDescription == 'ROI mask images')\nsum(df.SeriesDescription == 'full mammogram images')","metadata":{"execution":{"iopub.status.busy":"2023-02-19T06:40:20.66721Z","iopub.execute_input":"2023-02-19T06:40:20.667741Z","iopub.status.idle":"2023-02-19T06:40:20.679739Z","shell.execute_reply.started":"2023-02-19T06:40:20.667692Z","shell.execute_reply":"2023-02-19T06:40:20.678595Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_full_image = df[df.SeriesDescription == 'full mammogram images'].reset_index(drop=True)\ndf_full_image.shape","metadata":{"execution":{"iopub.status.busy":"2023-02-19T06:40:20.682872Z","iopub.execute_input":"2023-02-19T06:40:20.683544Z","iopub.status.idle":"2023-02-19T06:40:20.708283Z","shell.execute_reply.started":"2023-02-19T06:40:20.683496Z","shell.execute_reply":"2023-02-19T06:40:20.707091Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_full_image.columns","metadata":{"execution":{"iopub.status.busy":"2023-02-19T06:40:20.710642Z","iopub.execute_input":"2023-02-19T06:40:20.711182Z","iopub.status.idle":"2023-02-19T06:40:20.720389Z","shell.execute_reply.started":"2023-02-19T06:40:20.711121Z","shell.execute_reply":"2023-02-19T06:40:20.719109Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# df_full_image.PatientID[1].split('_')\ndef split_patient_message(s):\n    parts = s.split('_')\n    patient_id = 'P_{}'.format(parts[2])\n    return pd.Series([parts[0],patient_id,parts[3],parts[4]])\nsplit_patient_message(df_full_image.PatientID[1])","metadata":{"execution":{"iopub.status.busy":"2023-02-19T06:40:20.722463Z","iopub.execute_input":"2023-02-19T06:40:20.72295Z","iopub.status.idle":"2023-02-19T06:40:20.737101Z","shell.execute_reply.started":"2023-02-19T06:40:20.722902Z","shell.execute_reply":"2023-02-19T06:40:20.735446Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_full_image[['dataset_two','patient_id','laterality','view']] = df_full_image.PatientID.apply(split_patient_message)","metadata":{"execution":{"iopub.status.busy":"2023-02-19T06:40:20.738992Z","iopub.execute_input":"2023-02-19T06:40:20.7395Z","iopub.status.idle":"2023-02-19T06:40:21.542544Z","shell.execute_reply.started":"2023-02-19T06:40:20.739454Z","shell.execute_reply":"2023-02-19T06:40:21.541371Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_full_image.head()","metadata":{"execution":{"iopub.status.busy":"2023-02-19T06:40:21.544264Z","iopub.execute_input":"2023-02-19T06:40:21.544655Z","iopub.status.idle":"2023-02-19T06:40:21.579208Z","shell.execute_reply.started":"2023-02-19T06:40:21.544609Z","shell.execute_reply":"2023-02-19T06:40:21.577905Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_full_image.patient_id.duplicated()","metadata":{"execution":{"iopub.status.busy":"2023-02-19T06:40:21.580721Z","iopub.execute_input":"2023-02-19T06:40:21.581104Z","iopub.status.idle":"2023-02-19T06:40:21.590057Z","shell.execute_reply.started":"2023-02-19T06:40:21.58107Z","shell.execute_reply":"2023-02-19T06:40:21.589016Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(df_full_image.patient_id.unique())","metadata":{"execution":{"iopub.status.busy":"2023-02-19T06:40:21.591651Z","iopub.execute_input":"2023-02-19T06:40:21.591981Z","iopub.status.idle":"2023-02-19T06:40:21.605435Z","shell.execute_reply.started":"2023-02-19T06:40:21.591937Z","shell.execute_reply":"2023-02-19T06:40:21.604332Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 其他csv文件，汇总所有有病无病病例","metadata":{}},{"cell_type":"code","source":"def csv_trans(s):\n    df = pd.read_csv(f'{dataset_dir}/csv/{s}')\n    df = df[['patient_id','left or right breast','image view','pathology']]  # 取一部分列\n    df = df.rename(columns = {'left or right breast':'laterality','image view':'view','pathology':'BIRADS'}) # 改列名\n    #sum(df['BIRADS'] != 'BENIGN'),df.shape\n    df['BIRADS'] = df['BIRADS'].replace({'BENIGN':2,'BENIGN_WITHOUT_CALLBACK':0,'MALIGNANT':0}) # 更改数据形式\n    df['cancer'] = df['BIRADS']\n    df.loc[df.cancer == 0,'cancer'] = 1\n    df.loc[df.cancer == 2,'cancer'] = 0\n    return df\n","metadata":{"execution":{"iopub.status.busy":"2023-02-19T06:40:21.607063Z","iopub.execute_input":"2023-02-19T06:40:21.607558Z","iopub.status.idle":"2023-02-19T06:40:21.617396Z","shell.execute_reply.started":"2023-02-19T06:40:21.607523Z","shell.execute_reply":"2023-02-19T06:40:21.616153Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"csv_1 = csv_trans('calc_case_description_test_set.csv')\ncsv_1.head(),csv_1.shape","metadata":{"execution":{"iopub.status.busy":"2023-02-19T06:40:21.619052Z","iopub.execute_input":"2023-02-19T06:40:21.619393Z","iopub.status.idle":"2023-02-19T06:40:21.680049Z","shell.execute_reply.started":"2023-02-19T06:40:21.619361Z","shell.execute_reply":"2023-02-19T06:40:21.679117Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"csv_2 = csv_trans('calc_case_description_train_set.csv')\ncsv_2.head(),csv_2.shape","metadata":{"execution":{"iopub.status.busy":"2023-02-19T06:40:21.681395Z","iopub.execute_input":"2023-02-19T06:40:21.681918Z","iopub.status.idle":"2023-02-19T06:40:21.751369Z","shell.execute_reply.started":"2023-02-19T06:40:21.681884Z","shell.execute_reply":"2023-02-19T06:40:21.750155Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"csv_3 = csv_trans('mass_case_description_test_set.csv')\ncsv_3.head(),csv_3.shape","metadata":{"execution":{"iopub.status.busy":"2023-02-19T06:40:21.752665Z","iopub.execute_input":"2023-02-19T06:40:21.75303Z","iopub.status.idle":"2023-02-19T06:40:21.787693Z","shell.execute_reply.started":"2023-02-19T06:40:21.75299Z","shell.execute_reply":"2023-02-19T06:40:21.786653Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"csv_4 = csv_trans('mass_case_description_train_set.csv')\ncsv_4.head(),csv_4.shape","metadata":{"execution":{"iopub.status.busy":"2023-02-19T06:40:21.789084Z","iopub.execute_input":"2023-02-19T06:40:21.789424Z","iopub.status.idle":"2023-02-19T06:40:21.840786Z","shell.execute_reply.started":"2023-02-19T06:40:21.789392Z","shell.execute_reply":"2023-02-19T06:40:21.83983Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"csv_all = pd.concat([csv_1,csv_2,csv_3,csv_4])\ncsv_all.head(),csv_all.shape","metadata":{"execution":{"iopub.status.busy":"2023-02-19T06:40:21.842402Z","iopub.execute_input":"2023-02-19T06:40:21.842872Z","iopub.status.idle":"2023-02-19T06:40:21.857225Z","shell.execute_reply.started":"2023-02-19T06:40:21.842823Z","shell.execute_reply":"2023-02-19T06:40:21.855756Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(csv_all.patient_id.unique()),len(csv_all.cancer == 1) # patient 去重和所有的image数量","metadata":{"execution":{"iopub.status.busy":"2023-02-19T06:40:21.859055Z","iopub.execute_input":"2023-02-19T06:40:21.859463Z","iopub.status.idle":"2023-02-19T06:40:21.870319Z","shell.execute_reply.started":"2023-02-19T06:40:21.859421Z","shell.execute_reply":"2023-02-19T06:40:21.869362Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 核对两个表格内的patient id 是否对应\ncsv_all.loc[csv_all.patient_id =='P_00038',]","metadata":{"execution":{"iopub.status.busy":"2023-02-19T06:40:21.871699Z","iopub.execute_input":"2023-02-19T06:40:21.872174Z","iopub.status.idle":"2023-02-19T06:40:21.892736Z","shell.execute_reply.started":"2023-02-19T06:40:21.872134Z","shell.execute_reply":"2023-02-19T06:40:21.891497Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_full_image.loc[df_full_image.patient_id == 'P_00038',]","metadata":{"execution":{"iopub.status.busy":"2023-02-19T06:40:21.894388Z","iopub.execute_input":"2023-02-19T06:40:21.894802Z","iopub.status.idle":"2023-02-19T06:40:21.922218Z","shell.execute_reply.started":"2023-02-19T06:40:21.894759Z","shell.execute_reply":"2023-02-19T06:40:21.921091Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"csv_patient = csv_all.patient_id\nimage_patient = df_full_image.patient_id\ncsv_patient.shape,image_patient.shape","metadata":{"execution":{"iopub.status.busy":"2023-02-19T06:40:21.923373Z","iopub.execute_input":"2023-02-19T06:40:21.923669Z","iopub.status.idle":"2023-02-19T06:40:21.93542Z","shell.execute_reply.started":"2023-02-19T06:40:21.923642Z","shell.execute_reply":"2023-02-19T06:40:21.934121Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"inter = set(csv_patient) & set(image_patient)\nlen(inter)","metadata":{"execution":{"iopub.status.busy":"2023-02-19T06:40:21.938588Z","iopub.execute_input":"2023-02-19T06:40:21.939001Z","iopub.status.idle":"2023-02-19T06:40:21.949113Z","shell.execute_reply.started":"2023-02-19T06:40:21.938951Z","shell.execute_reply":"2023-02-19T06:40:21.948148Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"csv_all[csv_all['patient_id'].isin(inter) & csv_all['cancer'] == 1]","metadata":{"execution":{"iopub.status.busy":"2023-02-19T06:40:21.950714Z","iopub.execute_input":"2023-02-19T06:40:21.951052Z","iopub.status.idle":"2023-02-19T06:40:21.971991Z","shell.execute_reply.started":"2023-02-19T06:40:21.95102Z","shell.execute_reply":"2023-02-19T06:40:21.970874Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_full_image[df_full_image['patient_id'].isin(inter)]","metadata":{"execution":{"iopub.status.busy":"2023-02-19T06:40:21.973664Z","iopub.execute_input":"2023-02-19T06:40:21.974157Z","iopub.status.idle":"2023-02-19T06:40:22.044447Z","shell.execute_reply.started":"2023-02-19T06:40:21.974104Z","shell.execute_reply":"2023-02-19T06:40:22.043045Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_full_image.columns","metadata":{"execution":{"iopub.status.busy":"2023-02-19T06:40:22.04637Z","iopub.execute_input":"2023-02-19T06:40:22.046876Z","iopub.status.idle":"2023-02-19T06:40:22.056119Z","shell.execute_reply.started":"2023-02-19T06:40:22.046826Z","shell.execute_reply":"2023-02-19T06:40:22.05477Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"image_df = df_full_image[['image_path','dataset_two', 'patient_id', 'laterality', 'view']]\nimage_df.shape","metadata":{"execution":{"iopub.status.busy":"2023-02-19T06:40:22.057608Z","iopub.execute_input":"2023-02-19T06:40:22.058202Z","iopub.status.idle":"2023-02-19T06:40:22.072333Z","shell.execute_reply.started":"2023-02-19T06:40:22.058162Z","shell.execute_reply":"2023-02-19T06:40:22.070777Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"image_df.head(5)","metadata":{"execution":{"iopub.status.busy":"2023-02-19T06:40:22.074286Z","iopub.execute_input":"2023-02-19T06:40:22.074713Z","iopub.status.idle":"2023-02-19T06:40:22.09019Z","shell.execute_reply.started":"2023-02-19T06:40:22.07467Z","shell.execute_reply":"2023-02-19T06:40:22.089097Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"merged_df = pd.merge(csv_all, image_df, on=['patient_id', 'laterality', 'view'])\nmerged_df.shape,csv_all.shape,image_df.shape","metadata":{"execution":{"iopub.status.busy":"2023-02-19T07:04:18.229574Z","iopub.execute_input":"2023-02-19T07:04:18.230127Z","iopub.status.idle":"2023-02-19T07:04:18.249278Z","shell.execute_reply.started":"2023-02-19T07:04:18.230092Z","shell.execute_reply":"2023-02-19T07:04:18.24816Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"merged_df.drop_duplicates(subset=['image_path'],inplace = True)  # inplace 以后在本身上修改，返回None\ndf_less = merged_df.reset_index(drop= True)\ndf_less.shape","metadata":{"execution":{"iopub.status.busy":"2023-02-19T07:04:19.355442Z","iopub.execute_input":"2023-02-19T07:04:19.355845Z","iopub.status.idle":"2023-02-19T07:04:19.369947Z","shell.execute_reply.started":"2023-02-19T07:04:19.355812Z","shell.execute_reply":"2023-02-19T07:04:19.368588Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 检查路径是否存在\nimage_path = df_less.image_path\n\nexits = [os.path.exists(path) for path in image_path]\nprint(f'{sum(exits)} paths exits')\nprint(f'{len(exits)-sum(exits)} paths do not exits')","metadata":{"execution":{"iopub.status.busy":"2023-02-19T06:56:48.770785Z","iopub.execute_input":"2023-02-19T06:56:48.771251Z","iopub.status.idle":"2023-02-19T06:57:08.143473Z","shell.execute_reply.started":"2023-02-19T06:56:48.771211Z","shell.execute_reply":"2023-02-19T06:57:08.142475Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df = pd.read_csv('/kaggle/input/rsna-breast-cancer-detection/train.csv')\ntrain_df.head()","metadata":{"execution":{"iopub.status.busy":"2023-02-19T07:09:25.227794Z","iopub.execute_input":"2023-02-19T07:09:25.228313Z","iopub.status.idle":"2023-02-19T07:09:25.357738Z","shell.execute_reply.started":"2023-02-19T07:09:25.228272Z","shell.execute_reply":"2023-02-19T07:09:25.356356Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# mer_full = pd.merge(train_df, df_less,on=['patient_id', 'laterality', 'view','BIRADS','cancer'])\nmer_full = pd.concat([train_df,df_less],axis = 0,ignore_index = True)\nmer_full.head()","metadata":{"execution":{"iopub.status.busy":"2023-02-19T07:32:03.999305Z","iopub.execute_input":"2023-02-19T07:32:03.999824Z","iopub.status.idle":"2023-02-19T07:32:04.043491Z","shell.execute_reply.started":"2023-02-19T07:32:03.999792Z","shell.execute_reply":"2023-02-19T07:32:04.04223Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mer_full = mer_full.drop(columns = ['image_path','dataset_two'])","metadata":{"execution":{"iopub.status.busy":"2023-02-19T07:36:35.780449Z","iopub.execute_input":"2023-02-19T07:36:35.780856Z","iopub.status.idle":"2023-02-19T07:36:35.79584Z","shell.execute_reply.started":"2023-02-19T07:36:35.780817Z","shell.execute_reply":"2023-02-19T07:36:35.794781Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mer_full.head()","metadata":{"execution":{"iopub.status.busy":"2023-02-19T07:36:38.85475Z","iopub.execute_input":"2023-02-19T07:36:38.855569Z","iopub.status.idle":"2023-02-19T07:36:38.879622Z","shell.execute_reply.started":"2023-02-19T07:36:38.855497Z","shell.execute_reply":"2023-02-19T07:36:38.878351Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mer_full.shape,train_df.shape,df_less.shape","metadata":{"execution":{"iopub.status.busy":"2023-02-19T07:32:49.66449Z","iopub.execute_input":"2023-02-19T07:32:49.665318Z","iopub.status.idle":"2023-02-19T07:32:49.673611Z","shell.execute_reply.started":"2023-02-19T07:32:49.66526Z","shell.execute_reply":"2023-02-19T07:32:49.672306Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_less.to_csv('/kaggle/working/ddsm.csv',index = False)\nmer_full.to_csv('/kaggle/working/train+ddsm.csv',index = False)","metadata":{"execution":{"iopub.status.busy":"2023-02-19T07:37:54.967581Z","iopub.execute_input":"2023-02-19T07:37:54.968133Z","iopub.status.idle":"2023-02-19T07:37:56.098474Z","shell.execute_reply.started":"2023-02-19T07:37:54.967994Z","shell.execute_reply":"2023-02-19T07:37:56.097438Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 检查名字一样的img是否都一样\n# dir1 =  '/kaggle/input/cbis-ddsm-breast-cancer-image-dataset/jpeg/1.3.6.1.4.1.9590.100.1.2.68869081913580462902008969550178812228/1-189.jpg'\n# dir2 = '/kaggle/input/cbis-ddsm-breast-cancer-image-dataset/jpeg/1.3.6.1.4.1.9590.100.1.2.343898858112495672123446933853650418949/1-189.jpg'\n# dir3 = '/kaggle/input/cbis-ddsm-breast-cancer-image-dataset/jpeg/1.3.6.1.4.1.9590.100.1.2.193388471412891665142148097280465355326/1-189.jpg'","metadata":{"execution":{"iopub.status.busy":"2023-02-19T07:00:30.800874Z","iopub.execute_input":"2023-02-19T07:00:30.801314Z","iopub.status.idle":"2023-02-19T07:00:30.806707Z","shell.execute_reply.started":"2023-02-19T07:00:30.801279Z","shell.execute_reply":"2023-02-19T07:00:30.80532Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# def show_img(path):\n#     img = cv2.imread(path,0)\n#     plt.figure(figsize=(10,10))\n#     plt.imshow(img,cmap='bone')\n# show_img(dir1)\n# show_img(dir2)\n# show_img(dir3)","metadata":{"execution":{"iopub.status.busy":"2023-02-19T07:02:11.879798Z","iopub.execute_input":"2023-02-19T07:02:11.880275Z","iopub.status.idle":"2023-02-19T07:02:11.885277Z","shell.execute_reply.started":"2023-02-19T07:02:11.88024Z","shell.execute_reply":"2023-02-19T07:02:11.884017Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 重新保存数据","metadata":{}},{"cell_type":"code","source":"# shutil.rmtree('/kaggle/working/full_image_1/')","metadata":{"execution":{"iopub.status.busy":"2023-02-19T08:10:01.131464Z","iopub.execute_input":"2023-02-19T08:10:01.131949Z","iopub.status.idle":"2023-02-19T08:10:02.174688Z","shell.execute_reply.started":"2023-02-19T08:10:01.131915Z","shell.execute_reply":"2023-02-19T08:10:02.17315Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import shutil\nimport os\nnew_file_path = '/kaggle/working/full_image/'\nos.mkdir(new_file_path)\nimage_path = df_less['image_path']","metadata":{"execution":{"iopub.status.busy":"2023-02-19T08:04:56.959806Z","iopub.execute_input":"2023-02-19T08:04:56.960559Z","iopub.status.idle":"2023-02-19T08:04:56.968188Z","shell.execute_reply.started":"2023-02-19T08:04:56.960501Z","shell.execute_reply":"2023-02-19T08:04:56.966713Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for file_name in image_path:\n    names_dir = file_name.split('/')[-2]\n    names = file_name.split('/')[-1]\n    if file_name.endswith('.jpg') or file_name.endswith('.png'):\n        names_1 = os.path.join(new_file_path,names_dir)\n        new_file_name = os.path.join(names_1,names)\n        os.mkdir(names_1)\n        shutil.copyfile(file_name,new_file_name)","metadata":{"execution":{"iopub.status.busy":"2023-02-19T08:06:04.977261Z","iopub.execute_input":"2023-02-19T08:06:04.977717Z","iopub.status.idle":"2023-02-19T08:07:44.015413Z","shell.execute_reply.started":"2023-02-19T08:06:04.977674Z","shell.execute_reply":"2023-02-19T08:07:44.012894Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## image show","metadata":{}},{"cell_type":"code","source":"# def show_img(path):\n#     img = cv2.imread(path,0)\n#     plt.figure(figsize=(10,10))\n#     plt.imshow(img,cmap='bone')","metadata":{"execution":{"iopub.status.busy":"2023-02-16T14:24:57.664434Z","iopub.execute_input":"2023-02-16T14:24:57.664794Z","iopub.status.idle":"2023-02-16T14:24:57.670822Z","shell.execute_reply.started":"2023-02-16T14:24:57.664764Z","shell.execute_reply":"2023-02-16T14:24:57.669538Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# df.image_path.iloc[7]","metadata":{"execution":{"iopub.status.busy":"2023-02-16T14:25:08.082852Z","iopub.execute_input":"2023-02-16T14:25:08.083237Z","iopub.status.idle":"2023-02-16T14:25:08.090194Z","shell.execute_reply.started":"2023-02-16T14:25:08.083205Z","shell.execute_reply":"2023-02-16T14:25:08.08908Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# show_img(df.image_path.iloc[7])","metadata":{"execution":{"iopub.status.busy":"2023-02-16T14:25:00.634791Z","iopub.execute_input":"2023-02-16T14:25:00.635152Z","iopub.status.idle":"2023-02-16T14:25:01.090452Z","shell.execute_reply.started":"2023-02-16T14:25:00.635112Z","shell.execute_reply":"2023-02-16T14:25:01.089504Z"},"trusted":true},"execution_count":null,"outputs":[]}]}