{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":71549,"databundleVersionId":8561470,"sourceType":"competition"},{"sourceId":9195731,"sourceType":"datasetVersion","datasetId":5559249},{"sourceId":193161758,"sourceType":"kernelVersion"}],"dockerImageVersionId":30746,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import os\nimport pandas as pd\nimport numpy as np\nimport pydicom\nfrom tqdm.auto import tqdm\nimport matplotlib.pyplot as plt\nimport cv2\nimport glob","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-08-27T03:58:48.463968Z","iopub.execute_input":"2024-08-27T03:58:48.464390Z","iopub.status.idle":"2024-08-27T03:58:49.560053Z","shell.execute_reply.started":"2024-08-27T03:58:48.464352Z","shell.execute_reply":"2024-08-27T03:58:49.558838Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"IMG_DIR = \"/kaggle/input/rsna-2024-lumbar-spine-degenerative-classification/train_images\"","metadata":{"execution":{"iopub.status.busy":"2024-08-27T03:58:49.561937Z","iopub.execute_input":"2024-08-27T03:58:49.562398Z","iopub.status.idle":"2024-08-27T03:58:49.567549Z","shell.execute_reply.started":"2024-08-27T03:58:49.562368Z","shell.execute_reply":"2024-08-27T03:58:49.566365Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"FOLDS = [0,1,2,3,4]\nOD_INPUT_SIZE = 384\nSTD_BOX_SIZE = 20\nSAMPLE = None\nCONDITIONS = ['Left Neural Foraminal Narrowing', 'Right Neural Foraminal Narrowing']\nSEVERITIES = ['Normal/Mild', 'Moderate', 'Severe']\nLEVELS = ['l1_l2', 'l2_l3', 'l3_l4', 'l4_l5', 'l5_s1']","metadata":{"execution":{"iopub.status.busy":"2024-08-27T03:58:49.569148Z","iopub.execute_input":"2024-08-27T03:58:49.569592Z","iopub.status.idle":"2024-08-27T03:58:49.582129Z","shell.execute_reply.started":"2024-08-27T03:58:49.569538Z","shell.execute_reply":"2024-08-27T03:58:49.580840Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# rm -rf val_fold0","metadata":{"execution":{"iopub.status.busy":"2024-08-27T03:58:49.585599Z","iopub.execute_input":"2024-08-27T03:58:49.586141Z","iopub.status.idle":"2024-08-27T03:58:49.594099Z","shell.execute_reply.started":"2024-08-27T03:58:49.586097Z","shell.execute_reply":"2024-08-27T03:58:49.592769Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_val_df = pd.read_csv('/kaggle/input/rsna-2024-lumbar-spine-degenerative-classification/train.csv')\ntrain_xy = pd.read_csv('/kaggle/input/rsna-2024-lumbar-spine-degenerative-classification/train_label_coordinates.csv')\ntrain_des = pd.read_csv('/kaggle/input/rsna-2024-lumbar-spine-degenerative-classification/train_series_descriptions.csv')","metadata":{"execution":{"iopub.status.busy":"2024-08-27T03:58:49.595968Z","iopub.execute_input":"2024-08-27T03:58:49.597082Z","iopub.status.idle":"2024-08-27T03:58:49.790174Z","shell.execute_reply.started":"2024-08-27T03:58:49.597047Z","shell.execute_reply":"2024-08-27T03:58:49.788995Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"if SAMPLE:\n    train_val_df = train_val_df.sample(SAMPLE, random_state=2698)","metadata":{"execution":{"iopub.status.busy":"2024-08-27T03:58:49.791952Z","iopub.execute_input":"2024-08-27T03:58:49.792304Z","iopub.status.idle":"2024-08-27T03:58:49.805785Z","shell.execute_reply.started":"2024-08-27T03:58:49.792272Z","shell.execute_reply":"2024-08-27T03:58:49.804499Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fold_df = pd.read_csv('/kaggle/input/lsdc-fold-split/5folds.csv')","metadata":{"execution":{"iopub.status.busy":"2024-08-27T03:58:49.807259Z","iopub.execute_input":"2024-08-27T03:58:49.807624Z","iopub.status.idle":"2024-08-27T03:58:49.826127Z","shell.execute_reply.started":"2024-08-27T03:58:49.807587Z","shell.execute_reply":"2024-08-27T03:58:49.824637Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_xy.head(3)","metadata":{"execution":{"iopub.status.busy":"2024-08-27T03:58:49.827628Z","iopub.execute_input":"2024-08-27T03:58:49.828096Z","iopub.status.idle":"2024-08-27T03:58:49.855491Z","shell.execute_reply.started":"2024-08-27T03:58:49.828050Z","shell.execute_reply":"2024-08-27T03:58:49.854421Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def get_level(text):\n    for lev in ['l1_l2', 'l2_l3', 'l3_l4', 'l4_l5', 'l5_s1']:\n        if lev in text:\n            split = lev.split('_')\n            split[0] = split[0].capitalize()\n            split[1] = split[1].capitalize()\n            return '/'.join(split)\n    raise ValueError('Level not found '+ lev)\n    \ndef get_condition(text):\n    split = text.split('_')\n    for i in range(len(split)):\n        split[i] = split[i].capitalize()\n    split = split[:-2]\n    return ' '.join(split)\n#     raise ValueError('Condition not found '+ lev)","metadata":{"execution":{"iopub.status.busy":"2024-08-27T03:58:49.856719Z","iopub.execute_input":"2024-08-27T03:58:49.857105Z","iopub.status.idle":"2024-08-27T03:58:49.866308Z","shell.execute_reply.started":"2024-08-27T03:58:49.857062Z","shell.execute_reply":"2024-08-27T03:58:49.864994Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_xy['condition'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-08-27T03:58:49.871134Z","iopub.execute_input":"2024-08-27T03:58:49.872119Z","iopub.status.idle":"2024-08-27T03:58:49.889425Z","shell.execute_reply.started":"2024-08-27T03:58:49.872079Z","shell.execute_reply":"2024-08-27T03:58:49.888226Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# train_df = train_df.dropna()","metadata":{"execution":{"iopub.status.busy":"2024-08-27T03:58:49.890919Z","iopub.execute_input":"2024-08-27T03:58:49.891286Z","iopub.status.idle":"2024-08-27T03:58:49.897572Z","shell.execute_reply.started":"2024-08-27T03:58:49.891254Z","shell.execute_reply":"2024-08-27T03:58:49.896261Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"label_df = {'study_id':[], 'condition': [], 'level':[], 'label':[]}\n\nfor i, row in train_val_df.iterrows():\n    study_id = row['study_id']\n    for k, label in row.iloc[1:].to_dict().items():\n        level = get_level(k)\n        condition = get_condition(k)\n        label_df['study_id'].append(study_id)\n        label_df['condition'].append(condition)\n        label_df['level'].append(level)\n        label_df['label'].append(label)\n#         break\n#     break\n\nlabel_df = pd.DataFrame(label_df)\nlabel_df = label_df.merge(fold_df, on='study_id')","metadata":{"execution":{"iopub.status.busy":"2024-08-27T03:58:49.898967Z","iopub.execute_input":"2024-08-27T03:58:49.899312Z","iopub.status.idle":"2024-08-27T03:58:49.923769Z","shell.execute_reply.started":"2024-08-27T03:58:49.899281Z","shell.execute_reply":"2024-08-27T03:58:49.922262Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_xy = train_xy.merge(train_des, how='inner', on=['study_id', 'series_id'])\nlabel_df = label_df.merge(train_xy, how='inner', on=['study_id', 'condition', 'level'])","metadata":{"execution":{"iopub.status.busy":"2024-08-27T03:58:49.925360Z","iopub.execute_input":"2024-08-27T03:58:49.925779Z","iopub.status.idle":"2024-08-27T03:58:49.984574Z","shell.execute_reply.started":"2024-08-27T03:58:49.925725Z","shell.execute_reply":"2024-08-27T03:58:49.983352Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# label_df[label_df.series_id.isna()]","metadata":{"execution":{"iopub.status.busy":"2024-08-27T03:58:49.986122Z","iopub.execute_input":"2024-08-27T03:58:49.986451Z","iopub.status.idle":"2024-08-27T03:58:49.991482Z","shell.execute_reply.started":"2024-08-27T03:58:49.986423Z","shell.execute_reply":"2024-08-27T03:58:49.990322Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# cnt = train_xy.groupby(['study_id', 'series_id', 'instance_number'])['condition'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-08-27T03:58:49.993033Z","iopub.execute_input":"2024-08-27T03:58:49.993452Z","iopub.status.idle":"2024-08-27T03:58:50.002580Z","shell.execute_reply.started":"2024-08-27T03:58:49.993415Z","shell.execute_reply":"2024-08-27T03:58:50.001401Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# cnt[cnt>1]","metadata":{"execution":{"iopub.status.busy":"2024-08-27T03:58:50.004140Z","iopub.execute_input":"2024-08-27T03:58:50.004520Z","iopub.status.idle":"2024-08-27T03:58:50.015309Z","shell.execute_reply.started":"2024-08-27T03:58:50.004489Z","shell.execute_reply":"2024-08-27T03:58:50.014062Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def query_train_xy_row(study_id, series_id=None, instance_num=None):\n    if series_id is not None and instance_num is not None:\n        return label_df[(label_df.study_id==study_id) & (label_df.series_id==series_id) &\n            (label_df.instance_number==instance_num)]\n    elif series_id is None and instance_num is None:\n        return label_df[(label_df.study_id==study_id)]\n    else:\n        return label_df[(train_xy.study_id==study_id) & (label_df.series_id==series_id)]","metadata":{"execution":{"iopub.status.busy":"2024-08-27T03:58:50.016825Z","iopub.execute_input":"2024-08-27T03:58:50.017205Z","iopub.status.idle":"2024-08-27T03:58:50.029299Z","shell.execute_reply.started":"2024-08-27T03:58:50.017174Z","shell.execute_reply":"2024-08-27T03:58:50.028046Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# import os\n\n# def count_dcm_files(directory):\n#     dcm_count = 0\n#     for root, dirs, files in os.walk(directory):\n#         for file in files:\n#             if file.endswith('.dcm'):\n#                 dcm_count += 1\n#     return dcm_count\n\n# dcm_files_count = count_dcm_files(IMG_DIR)\n\n# print(f\"Number of .dcm files: {dcm_files_count}\")","metadata":{"execution":{"iopub.status.busy":"2024-08-27T03:58:50.031120Z","iopub.execute_input":"2024-08-27T03:58:50.032283Z","iopub.status.idle":"2024-08-27T03:58:50.044135Z","shell.execute_reply.started":"2024-08-27T03:58:50.032239Z","shell.execute_reply":"2024-08-27T03:58:50.042636Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def read_dcm(src_path):\n    dicom_data = pydicom.dcmread(src_path)\n    image = dicom_data.pixel_array\n    image = (image - image.min()) / (image.max() - image.min() +1e-6) * 255\n    image = np.stack([image]*3, axis=-1).astype('uint8')\n    return image\n\ndef get_accronym(text):\n    split = text.split(' ')\n    return ''.join([x[0] for x in split])","metadata":{"execution":{"iopub.status.busy":"2024-08-27T03:58:50.045670Z","iopub.execute_input":"2024-08-27T03:58:50.046157Z","iopub.status.idle":"2024-08-27T03:58:50.056393Z","shell.execute_reply.started":"2024-08-27T03:58:50.046120Z","shell.execute_reply":"2024-08-27T03:58:50.055267Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# study_id = 4003253 \n# series_id = 2448190387\n# instance_num = 28\n\nex = label_df.sample(1).iloc[0]\nstudy_id = ex.study_id\nseries_id = ex.series_id\ninstance_num = ex.instance_number\n\nWIDTH = 10\n\npath = os.path.join(IMG_DIR, str(study_id), str(series_id), f'{instance_num}.dcm')","metadata":{"execution":{"iopub.status.busy":"2024-08-27T03:58:50.058640Z","iopub.execute_input":"2024-08-27T03:58:50.059582Z","iopub.status.idle":"2024-08-27T03:58:50.074262Z","shell.execute_reply.started":"2024-08-27T03:58:50.059549Z","shell.execute_reply":"2024-08-27T03:58:50.073083Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img = read_dcm(path)\n\ntmp_df = query_train_xy_row(study_id, series_id, instance_num)\nfor i, row in tmp_df.iterrows():\n    lbl = f\"{get_accronym(row['condition'])}_{row['level']}\"\n    x, y = row['x'], row['y']\n    x1 = int(x - WIDTH)\n    x2 = int(x + WIDTH)\n    y1 = int(y - WIDTH)\n    y2 = int(y + WIDTH)\n    color = None\n    if row['label'] == 'Normal/Mild':\n        color =  (0, 255, 0)\n    elif row['label'] == 'Moderate':\n        color = (255,255,0) \n    elif row['label'] == 'Severe':\n        color = (255,0,0)\n        \n    fontFace = cv2.FONT_HERSHEY_SIMPLEX\n    fontScale = 0.5\n    thickness = 1\n    cv2.rectangle(img, (x1,y1), (x2,y2), color, 2)\n    cv2.putText(img, lbl, (x1,y1), fontFace, fontScale, color, thickness, cv2.LINE_AA)\n\ntmp_df","metadata":{"execution":{"iopub.status.busy":"2024-08-27T03:58:50.075919Z","iopub.execute_input":"2024-08-27T03:58:50.076326Z","iopub.status.idle":"2024-08-27T03:58:50.136596Z","shell.execute_reply.started":"2024-08-27T03:58:50.076288Z","shell.execute_reply":"2024-08-27T03:58:50.135475Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(img)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-08-27T03:58:50.137987Z","iopub.execute_input":"2024-08-27T03:58:50.138329Z","iopub.status.idle":"2024-08-27T03:58:50.458331Z","shell.execute_reply.started":"2024-08-27T03:58:50.138299Z","shell.execute_reply":"2024-08-27T03:58:50.457104Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# label_df[['study_id', 'series_id']].drop_duplicates()","metadata":{"execution":{"iopub.status.busy":"2024-08-27T03:58:50.459813Z","iopub.execute_input":"2024-08-27T03:58:50.460179Z","iopub.status.idle":"2024-08-27T03:58:50.464861Z","shell.execute_reply.started":"2024-08-27T03:58:50.460147Z","shell.execute_reply":"2024-08-27T03:58:50.463618Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def read_dcm(src_path):\n    dicom_data = pydicom.dcmread(src_path)\n    image = dicom_data.pixel_array\n    image = (image - image.min()) / (image.max() - image.min() +1e-6) * 255\n    image = np.stack([image]*3, axis=-1).astype('uint8')\n    return image","metadata":{"execution":{"iopub.status.busy":"2024-08-27T03:58:50.466513Z","iopub.execute_input":"2024-08-27T03:58:50.466906Z","iopub.status.idle":"2024-08-27T03:58:50.478716Z","shell.execute_reply.started":"2024-08-27T03:58:50.466875Z","shell.execute_reply":"2024-08-27T03:58:50.477549Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"filtered_df = label_df[label_df.condition.map(lambda x: x in CONDITIONS)]","metadata":{"execution":{"iopub.status.busy":"2024-08-27T03:58:50.480132Z","iopub.execute_input":"2024-08-27T03:58:50.480505Z","iopub.status.idle":"2024-08-27T03:58:50.492717Z","shell.execute_reply.started":"2024-08-27T03:58:50.480473Z","shell.execute_reply":"2024-08-27T03:58:50.491433Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"label2id = {}\nid2label = {}\ni = 0\nfor cond in CONDITIONS:\n    for level in LEVELS:\n        for severity in SEVERITIES:\n            cls_ = f\"{cond.lower().replace(' ', '_')}_{level}_{severity.lower()}\"\n            label2id[cls_] = i\n            id2label[i] = cls_\n            i+=1","metadata":{"execution":{"iopub.status.busy":"2024-08-27T03:58:50.494381Z","iopub.execute_input":"2024-08-27T03:58:50.494768Z","iopub.status.idle":"2024-08-27T03:58:50.508601Z","shell.execute_reply.started":"2024-08-27T03:58:50.494716Z","shell.execute_reply":"2024-08-27T03:58:50.507276Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"id2label","metadata":{"execution":{"iopub.status.busy":"2024-08-27T03:58:50.510144Z","iopub.execute_input":"2024-08-27T03:58:50.510478Z","iopub.status.idle":"2024-08-27T03:58:50.528787Z","shell.execute_reply.started":"2024-08-27T03:58:50.510451Z","shell.execute_reply":"2024-08-27T03:58:50.527513Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def gen_yolo_format(ann_df, phase='train'):\n    for name, group in tqdm(ann_df.groupby(['study_id', 'series_id', 'instance_number'])):\n        study_id, series_id, instance_num = name[0], name[1], name[2]\n        path = f'{IMG_DIR}/{study_id}/{series_id}/{instance_num}.dcm'\n        img = read_dcm(path)\n        H, W = img.shape[:2]\n\n        img_dir = os.path.join(OUT_DIR, 'images', phase)\n        os.makedirs(img_dir, exist_ok=True)\n        img_path = os.path.join(img_dir, f'{study_id}_{series_id}_{instance_num}.jpg')\n        cv2.imwrite(img_path, img)\n\n        ann_dir = os.path.join(OUT_DIR, 'labels', phase)\n        os.makedirs(ann_dir, exist_ok=True)\n        ann_path = os.path.join(ann_dir, f'{study_id}_{series_id}_{instance_num}.txt')\n        \n        contain_nulls = False\n        \n        with open(ann_path, 'w') as f:\n            for i, row in group.iterrows():\n                cond = row['condition']\n                level = row['level']\n                severity = row['label']\n                if pd.isnull(severity):\n                    contain_nulls = True\n                    break\n                class_label = f\"{cond.lower().replace(' ', '_')}_{level.lower().replace('/', '_')}_{severity.lower()}\"\n                class_id = label2id[class_label]\n                x_center = row['x'] / W\n                y_center = row['y'] / H\n                width = W / OD_INPUT_SIZE * STD_BOX_SIZE / W\n                height = H /  OD_INPUT_SIZE * STD_BOX_SIZE / H\n                f.write(f'{class_id} {x_center} {y_center} {width} {height}\\n')\n        \n        if not contain_nulls:\n            cv2.imwrite(img_path, img)\n#         break","metadata":{"execution":{"iopub.status.busy":"2024-08-27T03:58:50.535016Z","iopub.execute_input":"2024-08-27T03:58:50.535442Z","iopub.status.idle":"2024-08-27T03:58:50.550449Z","shell.execute_reply.started":"2024-08-27T03:58:50.535398Z","shell.execute_reply":"2024-08-27T03:58:50.549064Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for FOLD in FOLDS:\n    print('Gen data fold', FOLD)\n    OUT_DIR = f'data_fold{FOLD}'\n    os.makedirs(OUT_DIR, exist_ok=True)\n    \n    train_df = filtered_df[filtered_df.fold != FOLD]\n    val_df = filtered_df[filtered_df.fold == FOLD]\n    \n    gen_yolo_format(train_df, phase='train')\n    gen_yolo_format(val_df, phase='val')","metadata":{"execution":{"iopub.status.busy":"2024-08-27T03:58:50.552065Z","iopub.execute_input":"2024-08-27T03:58:50.552573Z","iopub.status.idle":"2024-08-27T03:58:52.477600Z","shell.execute_reply.started":"2024-08-27T03:58:50.552518Z","shell.execute_reply":"2024-08-27T03:58:52.476406Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ls data_fold0","metadata":{"execution":{"iopub.status.busy":"2024-08-27T03:58:52.479067Z","iopub.execute_input":"2024-08-27T03:58:52.479412Z","iopub.status.idle":"2024-08-27T03:58:53.670245Z","shell.execute_reply.started":"2024-08-27T03:58:52.479382Z","shell.execute_reply":"2024-08-27T03:58:53.668499Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# # test generated annotations\n\n_IM_DIR = f'{OUT_DIR}/images/train'\n_ANN_DIR = f'{OUT_DIR}/labels/train'\nname = np.random.choice(os.listdir(_IM_DIR))[:-4]\n\nim = plt.imread(os.path.join(_IM_DIR, name+'.jpg')).copy()\nH,W = im.shape[:2]\nanns = np.loadtxt(os.path.join(_ANN_DIR, name+'.txt')).reshape(-1, 5)\n\nfor _cls, x,y,w,h in anns.tolist():\n    x *= W\n    y *= H\n    w *= W\n    h *= H\n    x1 = int(x-w/2)\n    x2 = int(x+w/2)\n    y1 = int(y-h/2)\n    y2 = int(y+h/2)\n    label = id2label[_cls]\n    \n#     if _cls == 0:\n#         c = (255,0,0)\n#     elif _cls == 1:\n#         c = (0,255,0)\n#     else:\n#         c = (255,255,0)\n    c = (0,255,255)\n\n    im = cv2.rectangle(im, (x1,y1), (x2,y2), c, 2)\n    cv2.putText(im, label, (x1,y1), fontFace, 0.3, c, 1, cv2.LINE_AA)\n\n\nplt.imshow(im)","metadata":{"execution":{"iopub.status.busy":"2024-08-27T03:58:53.672219Z","iopub.execute_input":"2024-08-27T03:58:53.672636Z","iopub.status.idle":"2024-08-27T03:58:54.153280Z","shell.execute_reply.started":"2024-08-27T03:58:53.672599Z","shell.execute_reply":"2024-08-27T03:58:54.152008Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# ls data_fold0/labels/val","metadata":{"execution":{"iopub.status.busy":"2024-08-27T03:58:54.154772Z","iopub.execute_input":"2024-08-27T03:58:54.155168Z","iopub.status.idle":"2024-08-27T03:58:54.160574Z","shell.execute_reply.started":"2024-08-27T03:58:54.155135Z","shell.execute_reply":"2024-08-27T03:58:54.159310Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# os.path.join(_ANN_DIR, name+'.txt')","metadata":{"execution":{"iopub.status.busy":"2024-08-27T03:58:54.161738Z","iopub.execute_input":"2024-08-27T03:58:54.162192Z","iopub.status.idle":"2024-08-27T03:58:54.175123Z","shell.execute_reply.started":"2024-08-27T03:58:54.162151Z","shell.execute_reply":"2024-08-27T03:58:54.173837Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# cat 'train_fold0/labels/404602713_1230697721_12.txt'","metadata":{"execution":{"iopub.status.busy":"2024-08-27T03:58:54.176875Z","iopub.execute_input":"2024-08-27T03:58:54.177393Z","iopub.status.idle":"2024-08-27T03:58:54.184843Z","shell.execute_reply.started":"2024-08-27T03:58:54.177357Z","shell.execute_reply":"2024-08-27T03:58:54.183519Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for k, v in id2label.items():\n    print(f'{k}: {v}')","metadata":{"execution":{"iopub.status.busy":"2024-08-27T03:58:54.187043Z","iopub.execute_input":"2024-08-27T03:58:54.187468Z","iopub.status.idle":"2024-08-27T03:58:54.200508Z","shell.execute_reply.started":"2024-08-27T03:58:54.187435Z","shell.execute_reply":"2024-08-27T03:58:54.199300Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!zip -r -q data_fold0.zip data_fold0\n!zip -r -q data_fold1.zip data_fold1\n!zip -r -q data_fold2.zip data_fold2\n!zip -r -q data_fold3.zip data_fold3\n!zip -r -q data_fold4.zip data_fold4","metadata":{"execution":{"iopub.status.busy":"2024-08-27T03:58:54.201777Z","iopub.execute_input":"2024-08-27T03:58:54.202731Z","iopub.status.idle":"2024-08-27T03:59:00.155042Z","shell.execute_reply.started":"2024-08-27T03:58:54.202678Z","shell.execute_reply":"2024-08-27T03:59:00.153399Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ls","metadata":{"execution":{"iopub.status.busy":"2024-08-27T03:59:00.156941Z","iopub.execute_input":"2024-08-27T03:59:00.157325Z","iopub.status.idle":"2024-08-27T03:59:01.336425Z","shell.execute_reply.started":"2024-08-27T03:59:00.157291Z","shell.execute_reply":"2024-08-27T03:59:01.334891Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!rm -rf data_fold0\n!rm -rf data_fold1\n!rm -rf data_fold2\n!rm -rf data_fold3\n!rm -rf data_fold4","metadata":{"execution":{"iopub.status.busy":"2024-08-27T03:59:01.338245Z","iopub.execute_input":"2024-08-27T03:59:01.338805Z","iopub.status.idle":"2024-08-27T03:59:07.138333Z","shell.execute_reply.started":"2024-08-27T03:59:01.338743Z","shell.execute_reply":"2024-08-27T03:59:07.136762Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ls","metadata":{"execution":{"iopub.status.busy":"2024-08-27T03:59:10.050389Z","iopub.execute_input":"2024-08-27T03:59:10.050910Z","iopub.status.idle":"2024-08-27T03:59:11.209896Z","shell.execute_reply.started":"2024-08-27T03:59:10.050868Z","shell.execute_reply":"2024-08-27T03:59:11.208558Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}