{"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","metadata":{"execution":{"iopub.status.busy":"2021-07-16T09:38:57.986142Z","iopub.execute_input":"2021-07-16T09:38:57.986571Z","iopub.status.idle":"2021-07-16T09:38:57.996522Z","shell.execute_reply.started":"2021-07-16T09:38:57.986491Z","shell.execute_reply":"2021-07-16T09:38:57.995122Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.read_csv('../input/siim-covid19-detection/train_image_level.csv')","metadata":{"execution":{"iopub.status.busy":"2021-07-16T09:38:58.184452Z","iopub.execute_input":"2021-07-16T09:38:58.184781Z","iopub.status.idle":"2021-07-16T09:38:58.238855Z","shell.execute_reply.started":"2021-07-16T09:38:58.184755Z","shell.execute_reply":"2021-07-16T09:38:58.238073Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df1 = pd.read_csv('../input/siim-covid19-resized-to-256px-jpg/meta.csv')","metadata":{"execution":{"iopub.status.busy":"2021-07-16T09:38:59.077537Z","iopub.execute_input":"2021-07-16T09:38:59.077884Z","iopub.status.idle":"2021-07-16T09:38:59.098907Z","shell.execute_reply.started":"2021-07-16T09:38:59.077856Z","shell.execute_reply":"2021-07-16T09:38:59.098119Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df1 = df1[df1['split'] == 'train'].reset_index(drop=True)","metadata":{"execution":{"iopub.status.busy":"2021-07-16T09:39:00.053936Z","iopub.execute_input":"2021-07-16T09:39:00.054282Z","iopub.status.idle":"2021-07-16T09:39:00.072580Z","shell.execute_reply.started":"2021-07-16T09:39:00.054252Z","shell.execute_reply":"2021-07-16T09:39:00.071569Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df1.head()","metadata":{"execution":{"iopub.status.busy":"2021-07-16T09:39:01.035123Z","iopub.execute_input":"2021-07-16T09:39:01.035541Z","iopub.status.idle":"2021-07-16T09:39:01.052537Z","shell.execute_reply.started":"2021-07-16T09:39:01.035507Z","shell.execute_reply":"2021-07-16T09:39:01.051669Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df1.columns = ['id','dim0','dim1', 'split']","metadata":{"execution":{"iopub.status.busy":"2021-07-16T09:39:22.077104Z","iopub.execute_input":"2021-07-16T09:39:22.077504Z","iopub.status.idle":"2021-07-16T09:39:22.081742Z","shell.execute_reply.started":"2021-07-16T09:39:22.077470Z","shell.execute_reply":"2021-07-16T09:39:22.080872Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2021-07-16T09:39:24.369184Z","iopub.execute_input":"2021-07-16T09:39:24.369709Z","iopub.status.idle":"2021-07-16T09:39:24.379589Z","shell.execute_reply.started":"2021-07-16T09:39:24.369659Z","shell.execute_reply":"2021-07-16T09:39:24.378901Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['id'] = df['id'].str[:-6]","metadata":{"execution":{"iopub.status.busy":"2021-07-16T09:39:25.556927Z","iopub.execute_input":"2021-07-16T09:39:25.557451Z","iopub.status.idle":"2021-07-16T09:39:25.566114Z","shell.execute_reply.started":"2021-07-16T09:39:25.557397Z","shell.execute_reply":"2021-07-16T09:39:25.565163Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.merge(df, df1, on = 'id', how = 'left')","metadata":{"execution":{"iopub.status.busy":"2021-07-16T09:39:29.739572Z","iopub.execute_input":"2021-07-16T09:39:29.739949Z","iopub.status.idle":"2021-07-16T09:39:29.759762Z","shell.execute_reply.started":"2021-07-16T09:39:29.739916Z","shell.execute_reply":"2021-07-16T09:39:29.758834Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2021-07-16T09:39:30.433352Z","iopub.execute_input":"2021-07-16T09:39:30.433750Z","iopub.status.idle":"2021-07-16T09:39:30.447260Z","shell.execute_reply.started":"2021-07-16T09:39:30.433719Z","shell.execute_reply":"2021-07-16T09:39:30.446244Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in range(df.shape[0]):\n    a = df.loc[i,'id']\n    f = open(f'{a}.txt', 'w')\n    b = df.loc[i, 'label'].split()\n    b_len = int(len(b) / 6)\n    if b[0] == 'none':\n        f.close()\n        continue   \n    dim1 = df.loc[i,'dim1']\n    dim0 = df.loc[i,'dim0']\n    for j in range(b_len):\n        x_mid = str((float(b[6*j+2]) + float(b[6*j+4])) / 2 / dim1)\n        y_mid = str((float(b[6*j+3]) + float(b[6*j+5])) / 2 / dim0)\n        w = str((float(b[6*j+4]) - float(b[6*j+2])) / dim1)\n        h = str((float(b[6*j+5]) - float(b[6*j+3])) / dim0)\n        f.write('0'+' '+x_mid +' '+y_mid+' '+w+' '+h+' ')\n        f.write('\\n')\n\n    f.close()","metadata":{"execution":{"iopub.status.busy":"2021-07-16T09:39:42.189120Z","iopub.execute_input":"2021-07-16T09:39:42.189685Z","iopub.status.idle":"2021-07-16T09:39:43.048727Z","shell.execute_reply.started":"2021-07-16T09:39:42.189632Z","shell.execute_reply":"2021-07-16T09:39:43.047950Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}