{"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":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.read_csv('../input/siim-covid19-detection/train_image_level.csv')","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df1 = pd.read_csv('../input/siim-covid19-resized-to-256px-jpg/meta.csv')","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df1 = df1[df1['split'] == 'train'].reset_index(drop=True)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in range(df1.shape[0]):\n    df1.loc[i, 'image_id'] = df1.loc[i, 'image_id'] + '_image'","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df1.columns = ['id','dim0','dim1', 'split']","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.merge(df, df1, on = 'id', how = 'left')","metadata":{"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":{"trusted":true},"execution_count":null,"outputs":[]}]}