{"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\n\ndf = pd.read_csv(\"../input/siim-covid19-detection/train_image_level.csv\")\ndf_meta = pd.read_csv(\"../input/second/metadf.csv\")","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2021-07-20T06:25:42.654170Z","iopub.execute_input":"2021-07-20T06:25:42.654587Z","iopub.status.idle":"2021-07-20T06:25:42.735872Z","shell.execute_reply.started":"2021-07-20T06:25:42.654506Z","shell.execute_reply":"2021-07-20T06:25:42.735104Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df","metadata":{"execution":{"iopub.status.busy":"2021-07-20T06:25:42.737139Z","iopub.execute_input":"2021-07-20T06:25:42.737620Z","iopub.status.idle":"2021-07-20T06:25:42.766775Z","shell.execute_reply.started":"2021-07-20T06:25:42.737587Z","shell.execute_reply":"2021-07-20T06:25:42.765889Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_meta","metadata":{"execution":{"iopub.status.busy":"2021-07-20T06:25:42.768225Z","iopub.execute_input":"2021-07-20T06:25:42.768447Z","iopub.status.idle":"2021-07-20T06:25:42.782472Z","shell.execute_reply.started":"2021-07-20T06:25:42.768417Z","shell.execute_reply":"2021-07-20T06:25:42.781927Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_meta.loc[:, \"id\"] += \"_image\"\ndf_meta","metadata":{"execution":{"iopub.status.busy":"2021-07-20T06:25:42.783471Z","iopub.execute_input":"2021-07-20T06:25:42.783982Z","iopub.status.idle":"2021-07-20T06:25:42.824745Z","shell.execute_reply.started":"2021-07-20T06:25:42.783907Z","shell.execute_reply":"2021-07-20T06:25:42.823269Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_meta.columns = ['id','dim0','dim1', 'split']\ndf = pd.merge(df, df_meta, on = \"id\", how = \"left\")\ndf","metadata":{"execution":{"iopub.status.busy":"2021-07-20T06:25:42.825823Z","iopub.execute_input":"2021-07-20T06:25:42.826090Z","iopub.status.idle":"2021-07-20T06:25:42.857270Z","shell.execute_reply.started":"2021-07-20T06:25:42.826066Z","shell.execute_reply":"2021-07-20T06:25:42.856122Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in range(len(df)):\n    \n    id = df.loc[i, 'id']\n    f = open(f\"{id}.txt\", 'w')\n    x = df.loc[i, 'label'].split(\" \")\n    \n    if x[0] == \"none\":\n        continue\n\n    dim0 = df.loc[i, \"dim0\"]\n    dim1 = df.loc[i, \"dim1\"]\n    label_len = int(len(x)/6)\n    for j in range(label_len):\n        x_mid = str((float(x[6*j+2]) + float(x[6*j+4]))/2/dim1)\n        y_mid = str((float(x[6*j+3]) + float(x[6*j+5]))/2/dim0)\n        width = str((float(x[6*j+4]) - float(x[6*j+2]))/dim1)\n        height = str((float(x[6*j+5]) - float(x[6*j+3]))/dim0)\n        f.write('0'+' '+x_mid+' '+y_mid+' '+width+' '+height+' ')\n        f.write('\\n')\n    f.close()","metadata":{"execution":{"iopub.status.busy":"2021-07-20T06:25:42.858683Z","iopub.execute_input":"2021-07-20T06:25:42.859127Z","iopub.status.idle":"2021-07-20T06:25:43.544340Z","shell.execute_reply.started":"2021-07-20T06:25:42.859094Z","shell.execute_reply":"2021-07-20T06:25:43.543789Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!cat /kaggle/working/000a312787f2_image.txt","metadata":{"execution":{"iopub.status.busy":"2021-07-20T06:25:43.545239Z","iopub.execute_input":"2021-07-20T06:25:43.545688Z","iopub.status.idle":"2021-07-20T06:25:43.828981Z","shell.execute_reply.started":"2021-07-20T06:25:43.545653Z","shell.execute_reply":"2021-07-20T06:25:43.827838Z"},"trusted":true},"execution_count":null,"outputs":[]}]}