{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.7.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"gpu","dataSources":[{"sourceId":24800,"databundleVersionId":1831594,"sourceType":"competition"},{"sourceId":1799615,"sourceType":"datasetVersion","datasetId":1069544},{"sourceId":1800067,"sourceType":"datasetVersion","datasetId":1069810},{"sourceId":1800777,"sourceType":"datasetVersion","datasetId":1069787},{"sourceId":4098144,"sourceType":"datasetVersion","datasetId":2327088},{"sourceId":4258196,"sourceType":"datasetVersion","datasetId":2509170},{"sourceId":4260209,"sourceType":"datasetVersion","datasetId":2510427},{"sourceId":4788370,"sourceType":"datasetVersion","datasetId":2543618},{"sourceId":7571679,"sourceType":"datasetVersion","datasetId":4407914},{"sourceId":111700246,"sourceType":"kernelVersion"}],"dockerImageVersionId":30262,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"!git clone https://github.com/WongKinYiu/yolov7 # Downloading YOLOv7 repository and inst alling requirements","metadata":{"papermill":{"duration":2.582872,"end_time":"2022-10-11T05:31:15.024272","exception":false,"start_time":"2022-10-11T05:31:12.4414","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-02-11T15:22:30.430079Z","iopub.execute_input":"2024-02-11T15:22:30.430557Z","iopub.status.idle":"2024-02-11T15:22:31.428512Z","shell.execute_reply.started":"2024-02-11T15:22:30.430512Z","shell.execute_reply":"2024-02-11T15:22:31.427566Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# !pip install ultralytics\nimport pandas as pd\nimport os\nimport numpy as np\nimport shutil\nimport yaml\nimport matplotlib.pyplot as plt\nimport random\nimport cv2\n\nfrom sklearn import model_selection\nfrom tqdm import tqdm\nfrom glob import glob\n# from ultralytics import YOLO","metadata":{"_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","papermill":{"duration":0.968304,"end_time":"2022-10-11T05:31:16.019836","exception":false,"start_time":"2022-10-11T05:31:15.051532","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-02-11T15:22:31.430524Z","iopub.execute_input":"2024-02-11T15:22:31.43084Z","iopub.status.idle":"2024-02-11T15:22:32.166232Z","shell.execute_reply.started":"2024-02-11T15:22:31.430808Z","shell.execute_reply":"2024-02-11T15:22:32.165194Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n!pip install --upgrade -q wandb\n# from kaggle_secrets import UserSecretsClient\n\n# user_secrets = UserSecretsClient()\n\n!wandb.login(key=e5facd9412e5fd3991e6d9ad0c3e716b2fc97383)\n\n\nos.environ['WANDB_MODE'] = 'online'\n\n# Specify your wandb project name\nos.environ['WANDB_PROJECT'] = 'shubham-aagam'\n# os.environ['WANDB_API_KEY'] = 'e5facd9412e5fd3991e6d9ad0c3e716b2fc97383'\n\n!wandb login e5facd9412e5fd3991e6d9ad0c3e716b2fc97383","metadata":{"execution":{"iopub.status.busy":"2024-02-11T15:22:32.167831Z","iopub.execute_input":"2024-02-11T15:22:32.168161Z","iopub.status.idle":"2024-02-11T15:22:52.364791Z","shell.execute_reply.started":"2024-02-11T15:22:32.168132Z","shell.execute_reply":"2024-02-11T15:22:52.363601Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"size = 512\nTRAIN_LABELS_PATH = './vinbigdata/labels/train'\nVAL_LABELS_PATH = './vinbigdata/labels/val'\nTRAIN_IMAGES_PATH = './vinbigdata/images/train' #12000\nVAL_IMAGES_PATH = './vinbigdata/images/val' #3000\n#External_DIR = f'../input/vinbigdata-{size}-image-dataset/vinbigdata/train' # 15000\nExternal_DIR = '/kaggle/input/vinbigdata-competition-jpg-data-3x-downsampled/train/train'\nos.makedirs(TRAIN_LABELS_PATH, exist_ok = True)\nos.makedirs(VAL_LABELS_PATH, exist_ok = True)\nos.makedirs(TRAIN_IMAGES_PATH, exist_ok = True)\nos.makedirs(VAL_IMAGES_PATH, exist_ok = True)\n\noriginal_df = pd.read_csv(f'/kaggle/input/vinbigdata-{size}-image-dataset/vinbigdata/train.csv')\nnumber_of_imageids = len(original_df['image_id'].values)\nprint(f'Total number of image_ids (train + validation) {number_of_imageids}')\n\nnumber_of_images = len(os.listdir('/kaggle/input/vinbigdata-competition-jpg-data-3x-downsampled/train/train'))\nprint(f'Total number of images (train + validation) {number_of_images}')\n\nnumber_of_labels = len(os.listdir('/kaggle/input/vinbigdata-yolo-labels-dataset/labels'))\nprint(f'Total number of labels (train + validation) {number_of_labels}')\n\ndf = pd.read_csv(f'/kaggle/input/vinbigdata-{size}-image-dataset/vinbigdata/train.csv')\n\nnumber_of_images = len(df['image_id'].values)\nprint(f'Total number of image ids (train + validation) {number_of_images}')\n\nnumber_of_images = len(df['image_id'].values)\nprint(f'Total number of image ids (train + validation) {number_of_images}')\n\ndf.head()","metadata":{"papermill":{"duration":0.035276,"end_time":"2022-10-11T05:31:16.082148","exception":false,"start_time":"2022-10-11T05:31:16.046872","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-02-11T15:22:52.367551Z","iopub.execute_input":"2024-02-11T15:22:52.367881Z","iopub.status.idle":"2024-02-11T15:22:54.024789Z","shell.execute_reply.started":"2024-02-11T15:22:52.367846Z","shell.execute_reply":"2024-02-11T15:22:54.023835Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = df.drop(columns=['class_name', 'rad_id', 'x_min', 'x_max', 'y_min', 'y_max', 'width', 'height', 'class_id']) # we only need image ids, labels are pre-made\ndf.head()","metadata":{"papermill":{"duration":0.040306,"end_time":"2022-10-11T05:31:16.962341","exception":false,"start_time":"2022-10-11T05:31:16.922035","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-02-11T15:22:54.025905Z","iopub.execute_input":"2024-02-11T15:22:54.026183Z","iopub.status.idle":"2024-02-11T15:22:54.039008Z","shell.execute_reply.started":"2024-02-11T15:22:54.026158Z","shell.execute_reply":"2024-02-11T15:22:54.037961Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train, df_valid = model_selection.train_test_split(df, test_size=0.30, random_state=42, shuffle=True)\n\nnumber_of_images = len(df_train['image_id'].values)\nprint(f'Total number of training image_ids {number_of_images}')\n\nnumber_of_images = len(df_valid['image_id'].values)\nprint(f'Total number of validation image_ids {number_of_images}')\n","metadata":{"papermill":{"duration":0.037758,"end_time":"2022-10-11T05:31:17.027455","exception":false,"start_time":"2022-10-11T05:31:16.989697","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-02-11T15:22:54.040555Z","iopub.execute_input":"2024-02-11T15:22:54.040849Z","iopub.status.idle":"2024-02-11T15:22:54.054772Z","shell.execute_reply.started":"2024-02-11T15:22:54.040822Z","shell.execute_reply":"2024-02-11T15:22:54.053798Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"papermill":{"duration":0.070985,"end_time":"2022-10-11T05:31:17.270794","exception":false,"start_time":"2022-10-11T05:31:17.199809","status":"completed"},"tags":[],"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# need to delete duplicate image ids, len(labels) should be equal len(df.imageids.values), \nprint(f'Total number of training images {len(df_train.image_id.unique())}')\nprint(f'Total number of validation images {len(df_valid.image_id.unique())}')\nprint(len(df.image_id.unique()))","metadata":{"papermill":{"duration":0.075219,"end_time":"2022-10-11T05:31:17.40631","exception":false,"start_time":"2022-10-11T05:31:17.331091","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-02-11T15:22:54.056044Z","iopub.execute_input":"2024-02-11T15:22:54.056347Z","iopub.status.idle":"2024-02-11T15:22:54.084004Z","shell.execute_reply.started":"2024-02-11T15:22:54.056319Z","shell.execute_reply":"2024-02-11T15:22:54.083074Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# def preproccess_data(df, labels_path, images_path):\n#     for img_id in tqdm(df.image_id.unique()):\n#         shutil.copy(os.path.join('/kaggle/input/vinbigdata-yolo-labels-dataset/labels/', f\"{img_id}\"+'.txt'), labels_path)\n#         shutil.copy(os.path.join(f'/kaggle/input/vinbigdata-competition-jpg-data-3x-downsampled/train/train/', f\"{img_id}.jpg\"), images_path)","metadata":{"papermill":{"duration":0.051409,"end_time":"2022-10-11T05:31:17.500112","exception":false,"start_time":"2022-10-11T05:31:17.448703","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-02-11T15:22:54.085208Z","iopub.execute_input":"2024-02-11T15:22:54.085503Z","iopub.status.idle":"2024-02-11T15:22:54.089418Z","shell.execute_reply.started":"2024-02-11T15:22:54.085477Z","shell.execute_reply":"2024-02-11T15:22:54.088486Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def preproccess_data(df, labels_path, images_path):\n    for img_id in tqdm(df.image_id.unique()):\n        shutil.copy(os.path.join('/kaggle/input/vinbigdata-yolo-labels-dataset/labels/', f\"{img_id}\"+'.txt'), labels_path)\n        shutil.copy(os.path.join(f'/kaggle/input/vinbigdata-512-image-dataset/vinbigdata/train', f\"{img_id}.png\"), images_path)","metadata":{"execution":{"iopub.status.busy":"2024-02-11T15:22:54.090794Z","iopub.execute_input":"2024-02-11T15:22:54.091145Z","iopub.status.idle":"2024-02-11T15:22:54.099222Z","shell.execute_reply.started":"2024-02-11T15:22:54.091109Z","shell.execute_reply":"2024-02-11T15:22:54.098345Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"preproccess_data(df_train, TRAIN_LABELS_PATH, TRAIN_IMAGES_PATH)\npreproccess_data(df_valid, VAL_LABELS_PATH, VAL_IMAGES_PATH)","metadata":{"papermill":{"duration":41.656756,"end_time":"2022-10-11T05:31:59.198369","exception":false,"start_time":"2022-10-11T05:31:17.541613","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-02-11T15:22:54.103359Z","iopub.execute_input":"2024-02-11T15:22:54.103921Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# check that data was preprocessed correctly\nprint(len(os.listdir(TRAIN_LABELS_PATH)))\nprint(len(os.listdir(TRAIN_IMAGES_PATH)))\n\n\n\nprint(len(os.listdir(VAL_LABELS_PATH)))\nprint(len(os.listdir(VAL_IMAGES_PATH)))","metadata":{"papermill":{"duration":0.141303,"end_time":"2022-10-11T05:31:59.462139","exception":false,"start_time":"2022-10-11T05:31:59.320836","status":"completed"},"tags":[],"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"shutil.copy('/kaggle/input/fyaml6/vinbigdata.yaml','/kaggle/working/yolov7/data/')","metadata":{"papermill":{"duration":0.130515,"end_time":"2022-10-11T05:31:59.713454","exception":false,"start_time":"2022-10-11T05:31:59.582939","status":"completed"},"tags":[],"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"os.makedirs('/kaggle/working/yolov7/weights',exist_ok = True)\nshutil.copy('/kaggle/input/yolov7-280-epoch/best.pt', '/kaggle/working/yolov7/weights')","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#!pip install -q -U -r requirements.txt\n#!pip install -q pycocotools>=2.0 seaborn>=0.11.0 thop\n# os.chdir(\"..\")","metadata":{"papermill":{"duration":123.3629,"end_time":"2022-10-11T05:34:03.197244","exception":false,"start_time":"2022-10-11T05:31:59.834344","status":"completed"},"tags":[],"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# !cat yolov7/data/vinbigdata.yaml","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# !WANDB_MODE=\"dryrun\" python yolov7/train.py --workers 0 --device 0 --batch-size 20 --data yolov7/data/vinbigdata.yaml --img 512 512 --cfg yolov7/cfg/training/yolov7.yaml --weights 'yolov7/weights/best.pt' --name yolov7 --hyp yolov7/data/hyp.scratch.p5.yaml --epochs 1","metadata":{"papermill":{"duration":11220.973208,"end_time":"2022-10-11T08:41:04.294575","exception":false,"start_time":"2022-10-11T05:34:03.321367","status":"completed"},"tags":[],"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# ## THIS IS CODE FOR DIFFERENT TYPES OF WEIGHTS, PER EPOCH\n# print(\"YOLOV7-E6E\")\n# !python yolov7/train.py --workers 0 --device 0 --batch-size 20 --data yolov7/data/vinbigdata.yaml --img 512 512 --cfg yolov7/cfg/training/yolov7.yaml --weights '/kaggle/input/yolov7-weights/yolov7-e6e.pt' --name yolov7 --hyp yolov7/data/hyp.scratch.p5.yaml --epochs 20\n\n# print(\"\\n\\n\\nYOLOV7-D6\")\n# !python yolov7/train.py --workers 0 --device 0 --batch-size 20 --data yolov7/data/vinbigdata.yaml --img 512 512 --cfg yolov7/cfg/training/yolov7.yaml --weights '/kaggle/input/yolov7-weights/yolov7-d6.pt' --name yolov7 --hyp yolov7/data/hyp.scratch.p5.yaml --epochs 20\n\n# print(\"\\n\\n\\nYOLOV7-E6\")\n# !python yolov7/train.py --workers 0 --device 0 --batch-size 20 --data yolov7/data/vinbigdata.yaml --img 512 512 --cfg yolov7/cfg/training/yolov7.yaml --weights '/kaggle/input/yolov7-weights/yolov7-e6.pt' --name yolov7 --hyp yolov7/data/hyp.scratch.p5.yaml --epochs 20\n\n# print(\"\\n\\n\\nYOLOV7-W6\")\n# !python yolov7/train.py --workers 0 --device 0 --batch-size 20 --data yolov7/data/vinbigdata.yaml --img 512 512 --cfg yolov7/cfg/training/yolov7.yaml --weights '/kaggle/input/yolov7-weights/yolov7-w6.pt' --name yolov7 --hyp yolov7/data/hyp.scratch.p5.yaml --epochs 20\n\n# print(\"\\n\\n\\nYOLOV7-X\")\n# !python yolov7/train.py --workers 0 --device 0 --batch-size 20 --data yolov7/data/vinbigdata.yaml --img 512 512 --cfg yolov7/cfg/training/yolov7.yaml --weights '/kaggle/input/yolov7-weights/yolov7x.pt' --name yolov7 --hyp yolov7/data/hyp.scratch.p5.yaml --epochs 20\n\nprint(\"\\n\\n\\nYOLOV7\")\n!python yolov7/train.py --workers 0 --device 0 --batch-size 20 --data yolov7/data/vinbigdata.yaml --img 512 512 --cfg yolov7/cfg/training/yolov7.yaml --weights '/kaggle/input/yolov7-weights/yolov7.pt' --name yolov7 --hyp yolov7/data/hyp.scratch.p5.yaml --epochs 280\n","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# #TESTING CODE\n\n# !WANDB_MODE=\"dryrun\" python yolov7/test.py --data yolov7/data/vinbigdata.yaml --img 512 --batch 32 --conf 0.001 --iou 0.65 --device 0 --weights '/kaggle/input/yolov7-weights/yolov7-e6e.pt' --name yolov7_512_val","metadata":{"execution":{"iopub.status.busy":"2024-02-10T14:43:10.530403Z","iopub.execute_input":"2024-02-10T14:43:10.531346Z","iopub.status.idle":"2024-02-10T14:44:20.898894Z","shell.execute_reply.started":"2024-02-10T14:43:10.531293Z","shell.execute_reply":"2024-02-10T14:44:20.897768Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# !pip install ultralytics\n# # !pip install clearml\n# from ultralytics import YOLO\n\n\n# # Load a model\n# # model = YOLO('yolo8m.yaml')  # build a new model from YAML\n# model = YOLO('/kaggle/input/yolov8m-pt/yolov8m.pt')  # load a pretrained model (recommended for training)\n# # model = YOLO('yolov8m.yaml').load('yolov8m.pt')  # build from YAML and transfer weights\n\n# results = model.train(data='/kaggle/working/yolov7/data/vinbigdata.yaml', epochs=100, imgsz=640)\n","metadata":{"execution":{"iopub.status.busy":"2024-02-06T14:06:05.427749Z","iopub.execute_input":"2024-02-06T14:06:05.428241Z","iopub.status.idle":"2024-02-06T14:06:05.433374Z","shell.execute_reply.started":"2024-02-06T14:06:05.4282Z","shell.execute_reply":"2024-02-06T14:06:05.432428Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df = pd.read_csv(f'/kaggle/input/vinbigdata-{size}-image-dataset/vinbigdata/test.csv')\ntest_dir = f'/kaggle/input/vinbigdata-512-image-dataset/vinbigdata/test'\nweights_dir = './runs/train/yolov7/weights/best.pt'","metadata":{"papermill":{"duration":8.717897,"end_time":"2022-10-11T08:41:21.079277","exception":false,"start_time":"2022-10-11T08:41:12.36138","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-02-06T14:38:41.843939Z","iopub.execute_input":"2024-02-06T14:38:41.844958Z","iopub.status.idle":"2024-02-06T14:38:41.877334Z","shell.execute_reply.started":"2024-02-06T14:38:41.844911Z","shell.execute_reply":"2024-02-06T14:38:41.876557Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# !python yolov7/detect.py --weights $weights_dir\\\n# --img 640\\\n# --conf 0.005\\\n# --iou 0.45\\\n# --source $test_dir\\\n# --save-txt --save-conf --exist-ok","metadata":{"papermill":{"duration":273.846798,"end_time":"2022-10-11T08:46:35.572687","exception":false,"start_time":"2022-10-11T08:42:01.725889","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-02-06T14:41:14.549424Z","iopub.execute_input":"2024-02-06T14:41:14.550375Z","iopub.status.idle":"2024-02-06T14:45:26.127094Z","shell.execute_reply.started":"2024-02-06T14:41:14.550334Z","shell.execute_reply":"2024-02-06T14:45:26.125982Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# # credit / source https://www.kaggle.com/awsaf49/vinbigdata-cxr-ad-yolov5-14-class-infer\n# def yolo2voc(image_height, image_width, bboxes):\n#     \"\"\"\n#     yolo => [xmid, ymid, w, h] (normalized)\n#     voc  => [x1, y1, x2, y1]\n    \n#     \"\"\" \n#     bboxes = bboxes.copy().astype(float) # otherwise all value will be 0 as voc_pascal dtype is np.int\n    \n#     bboxes[..., [0, 2]] = bboxes[..., [0, 2]]* image_width\n#     bboxes[..., [1, 3]] = bboxes[..., [1, 3]]* image_height\n    \n#     bboxes[..., [0, 1]] = bboxes[..., [0, 1]] - bboxes[..., [2, 3]]/2\n#     bboxes[..., [2, 3]] = bboxes[..., [0, 1]] + bboxes[..., [2, 3]]\n    \n#     return bboxes","metadata":{"papermill":{"duration":8.940757,"end_time":"2022-10-11T08:46:53.229911","exception":false,"start_time":"2022-10-11T08:46:44.289154","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-02-06T14:47:17.058232Z","iopub.execute_input":"2024-02-06T14:47:17.059275Z","iopub.status.idle":"2024-02-06T14:47:17.06863Z","shell.execute_reply.started":"2024-02-06T14:47:17.059221Z","shell.execute_reply":"2024-02-06T14:47:17.067473Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# # credit / source https://www.kaggle.com/awsaf49/vinbigdata-cxr-ad-yolov5-14-class-infer\n# image_ids = []\n# PredictionStrings = []\n\n# def process_submission():\n#     for file_path in tqdm(glob('runs/detect/exp/labels/*txt')):\n#         image_id = file_path.split('/')[-1].split('.')[0] # extract image id\n#         w, h = test_df.loc[test_df.image_id==image_id,['width', 'height']].values[0] #  get the weight & height from  the test df\n#         f = open(file_path, 'r')  # open the label text file\n#         data = np.array(f.read().replace('\\n', ' ').strip().split(' ')).astype(np.float32).reshape(-1, 6) # move all the labels to the same line..?\n#         data = data[:, [0, 5, 1, 2, 3, 4]]\n#         bboxes = list(np.round(np.concatenate((data[:, :2], np.round(yolo2voc(h, w, data[:, 2:]))), axis =1).reshape(-1), 1).astype(str))\n#         for idx in range(len(bboxes)):\n#             bboxes[idx] = str(int(float(bboxes[idx]))) if idx%6!=1 else bboxes[idx] # 6 is the length of  the prediction string, so..?\n#         image_ids.append(image_id)\n#         PredictionStrings.append(' '.join(bboxes))\n\n#     # credit / source: https://www.kaggle.com/awsaf49/vinbigdata-cxr-ad-yolov5-14-class-infer\n#     pred_df = pd.DataFrame({'image_id':image_ids,\n#                             'PredictionString':PredictionStrings})\n#     sub_df = pd.merge(test_df, pred_df, on = 'image_id', how = 'left').fillna(\"14 1 0 0 1 1\")\n#     sub_df = sub_df[['image_id', 'PredictionString']]\n#     sub_df.to_csv('/kaggle/working/submission_3.csv',index = False)\n#     sub_df.tail()\n    \n#     process_submission()","metadata":{"papermill":{"duration":8.865591,"end_time":"2022-10-11T08:47:29.006301","exception":false,"start_time":"2022-10-11T08:47:20.14071","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-02-06T14:47:20.809943Z","iopub.execute_input":"2024-02-06T14:47:20.810329Z","iopub.status.idle":"2024-02-06T14:47:20.824507Z","shell.execute_reply.started":"2024-02-06T14:47:20.810294Z","shell.execute_reply":"2024-02-06T14:47:20.823389Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# # !pip uninstall pandas\n# !pip install --upgrade pip\n# !pip install matplotlib==3.1.1\n# !pip install pandas==1.3.0\n# !pip install matplotlib==3.3","metadata":{"papermill":{"duration":19.164559,"end_time":"2022-10-11T08:47:57.475424","exception":false,"start_time":"2022-10-11T08:47:38.310865","status":"completed"},"tags":[],"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# plt.figure(figsize=(30,15))\n# plt.axis('off')\n# plt.imshow('./runs/detect/exp/13db1898f2d711db4aaf0b2a9a4059cd.png')","metadata":{"execution":{"iopub.status.busy":"2024-02-10T15:40:24.213974Z","iopub.execute_input":"2024-02-10T15:40:24.214425Z","iopub.status.idle":"2024-02-10T15:40:24.503012Z","shell.execute_reply.started":"2024-02-10T15:40:24.214389Z","shell.execute_reply":"2024-02-10T15:40:24.500753Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# plt.figure(figsize=(30,15))\n# plt.axis('off')\n# plt.imshow(plt.imread('./runs/train/yolov7/R_curve.png'));","metadata":{"execution":{"iopub.status.busy":"2024-02-06T14:48:00.896768Z","iopub.execute_input":"2024-02-06T14:48:00.897225Z","iopub.status.idle":"2024-02-06T14:48:02.166073Z","shell.execute_reply.started":"2024-02-06T14:48:00.897187Z","shell.execute_reply":"2024-02-06T14:48:02.164991Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# plt.figure(figsize=(30,15))\n# plt.axis('off')\n# plt.imshow(plt.imread('./runs/train/yolov7/R_curve.png'));","metadata":{"papermill":{"duration":9.711617,"end_time":"2022-10-11T08:51:25.433123","exception":false,"start_time":"2022-10-11T08:51:15.721506","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-02-06T14:48:11.38618Z","iopub.execute_input":"2024-02-06T14:48:11.386896Z","iopub.status.idle":"2024-02-06T14:48:12.557891Z","shell.execute_reply.started":"2024-02-06T14:48:11.386854Z","shell.execute_reply":"2024-02-06T14:48:12.556959Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# plt.figure(figsize=(30,15))\n# plt.axis('off')\n# plt.imshow(plt.imread('./runs/train/yolov7/confusion_matrix.png'));","metadata":{"papermill":{"duration":10.125256,"end_time":"2022-10-11T08:51:44.117308","exception":false,"start_time":"2022-10-11T08:51:33.992052","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-02-06T14:48:12.55993Z","iopub.execute_input":"2024-02-06T14:48:12.56034Z","iopub.status.idle":"2024-02-06T14:48:14.503307Z","shell.execute_reply.started":"2024-02-06T14:48:12.560302Z","shell.execute_reply":"2024-02-06T14:48:14.502383Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# plt.figure(figsize=(30,15))\n# plt.axis('off')\n# plt.imshow(plt.imread('./runs/train/yolov7/results.png'));","metadata":{"papermill":{"duration":9.87953,"end_time":"2022-10-11T08:52:03.112146","exception":false,"start_time":"2022-10-11T08:51:53.232616","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-02-06T14:48:14.504449Z","iopub.execute_input":"2024-02-06T14:48:14.504728Z","iopub.status.idle":"2024-02-06T14:48:15.643552Z","shell.execute_reply.started":"2024-02-06T14:48:14.504702Z","shell.execute_reply":"2024-02-06T14:48:15.642647Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"papermill":{"duration":10.354444,"end_time":"2022-10-11T08:52:22.220993","exception":false,"start_time":"2022-10-11T08:52:11.866549","status":"completed"},"tags":[],"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# # load yolo submission\n# yolo = pd.read_csv('../submission_3.csv')\n# yolo = yolo.drop_duplicates()\n# effnetb6 = pd.read_csv('/kaggle/input/preds123/Vgg and resnet.csv') # AUC:0.98\n# pred = pd.merge(yolo, effnetb6, on = 'image_id', how = 'left')\n# low_thr  = 0.08\n# high_thr = 0.95","metadata":{"papermill":{"duration":8.789437,"end_time":"2022-10-11T08:52:39.872961","exception":false,"start_time":"2022-10-11T08:52:31.083524","status":"completed"},"tags":[],"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# def filter_2cls(row, low_thr=low_thr, high_thr=high_thr):\n#     prob = row['target']\n#     if prob<low_thr:\n#         ## Less chance of having any disease\n#         row['PredictionString'] = '14 1 0 0 1 1'\n#     elif low_thr<=prob<high_thr:\n#         ## More change of having any diesease\n#         row['PredictionString']+=f' 14 {prob} 0 0 1 1'\n#     elif high_thr<=prob:\n#         ## Good chance of having any disease so believe in object detection model\n#         row['PredictionString'] = row['PredictionString']\n#     else:\n#         raise ValueError('Prediction must be from [0-1]')\n#     return row","metadata":{"papermill":{"duration":8.802349,"end_time":"2022-10-11T08:52:57.918641","exception":false,"start_time":"2022-10-11T08:52:49.116292","status":"completed"},"tags":[],"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# sub = pred.apply(filter_2cls, axis=1)\n# sub[['image_id', 'PredictionString']].to_csv('../submission.csv',index = False)","metadata":{"papermill":{"duration":9.066841,"end_time":"2022-10-11T08:53:15.814609","exception":false,"start_time":"2022-10-11T08:53:06.747768","status":"completed"},"tags":[],"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# plt.imshow(\"/kaggle/working/runs/detect/exp/53f6b9d988c8195673ea55343c046187.png\")","metadata":{"papermill":{"duration":8.713755,"end_time":"2022-10-11T08:53:33.577779","exception":false,"start_time":"2022-10-11T08:53:24.864024","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-02-06T15:06:18.131204Z","iopub.execute_input":"2024-02-06T15:06:18.131619Z","iopub.status.idle":"2024-02-06T15:06:18.404279Z","shell.execute_reply.started":"2024-02-06T15:06:18.131587Z","shell.execute_reply":"2024-02-06T15:06:18.40269Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# !python yolov7/detect.py --weights yolov7/weights/best.pt --img-size 256 --conf 0.5 --source /kaggle/input/vinbigdata-512-image-dataset/vinbigdata/train/000434271f63a053c4128a0ba6352c7f.png","metadata":{"papermill":{"duration":9.267807,"end_time":"2022-10-11T08:53:51.734793","exception":false,"start_time":"2022-10-11T08:53:42.466986","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-02-07T05:20:34.631935Z","iopub.execute_input":"2024-02-07T05:20:34.632247Z","iopub.status.idle":"2024-02-07T05:20:42.342046Z","shell.execute_reply.started":"2024-02-07T05:20:34.632221Z","shell.execute_reply":"2024-02-07T05:20:42.341083Z"},"trusted":true},"execution_count":null,"outputs":[]}]}