{"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":"!pip install -qU wandb\n!pip install -qU bbox-utility","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\nfrom tqdm.notebook import tqdm\ntqdm.pandas()\nimport pandas as pd\nimport os\nimport cv2\nimport matplotlib.pyplot as plt\nimport glob\n\nimport shutil\nimport sys\nsys.path.append('/kaggle/input/tensorflow-great-barrier-reef')\n\nfrom joblib import Parallel, delayed\n\nfrom IPython.display import display","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import wandb\n\ntry:\n    from kaggle_secrets import UserSecretsClient\n    user_secrets = UserSecretsClient()\n    api_key = user_secrets.get_secret(\"wandb_api\")\n    wandb.login(key=api_key)\n    anonymous = None\nexcept:\n    wandb.login(anonymous='must')\n    print('To use your W&B account,\\nGo to Add-ons -> Secrets and provide your W&B access token. Use the Label name as WANDB. \\nGet your W&B access token from here: https://wandb.ai/authorize')","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"FOLD      = 1 # which fold to train\nDIM       = 1280 \nMODEL     = 'yolov7-e6e'\nBATCH     = 3\nEPOCHS    = 7\nPROJECT   = 'great-barrier-reef-yolov7' # w&b in yolov7\nNAME      = f'{MODEL}-dim{DIM}-fold{FOLD}' # w&b for yolov7\n\nREMOVE_NOBBOX = True # remove images with no bbox\nROOT_DIR  = '/kaggle/input/tensorflow-great-barrier-reef/'\nIMAGE_DIR = '/kaggle/images' # directory to save images\nLABEL_DIR = '/kaggle/labels' # directory to save labels","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!mkdir -p {IMAGE_DIR}\n!mkdir -p {LABEL_DIR}","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Train Data\ndf = pd.read_csv(f'{ROOT_DIR}/train.csv')\ndf['old_image_path'] = f'{ROOT_DIR}/train_images/video_'+df.video_id.astype(str)+'/'+df.video_frame.astype(str)+'.jpg'\ndf['image_path']  = f'{IMAGE_DIR}/'+df.image_id+'.jpg'\ndf['label_path']  = f'{LABEL_DIR}/'+df.image_id+'.txt'\ndf['annotations'] = df['annotations'].progress_apply(eval)\ndisplay(df.head(2))","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['num_bbox'] = df['annotations'].progress_apply(lambda x: len(x))\ndata = (df.num_bbox>0).value_counts(normalize=True)*100\nprint(f\"No BBox: {data[0]:0.2f}% | With BBox: {data[1]:0.2f}%\")","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"if REMOVE_NOBBOX:\n    df = df.query(\"num_bbox>0\")","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def make_copy(row):\n    shutil.copyfile(row.old_image_path, row.image_path)\n    return","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"image_paths = df.old_image_path.tolist()\n_ = Parallel(n_jobs=-1, backend='threading')(delayed(make_copy)(row) for _, row in tqdm(df.iterrows(), total=len(df)))","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from bbox.utils import coco2yolo, coco2voc, voc2yolo\nfrom bbox.utils import draw_bboxes, load_image\nfrom bbox.utils import clip_bbox, str2annot, annot2str\n\ndef get_bbox(annots):\n    bboxes = [list(annot.values()) for annot in annots]\n    return bboxes\n\ndef get_imgsize(row):\n    row['width'], row['height'] = imagesize.get(row['image_path'])\n    return row\n\nnp.random.seed(42)\ncolors = [(np.random.randint(255), np.random.randint(255), np.random.randint(255))\\\n          for idx in range(1)]","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['bboxes'] = df.annotations.progress_apply(get_bbox)\ndf.head(2)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['width']  = 1280\ndf['height'] = 720\ndisplay(df.head(2))","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cnt = 0\nall_bboxes = []\nbboxes_info = []\nfor row_idx in tqdm(range(df.shape[0])):\n    row = df.iloc[row_idx]\n    image_height = row.height\n    image_width  = row.width\n    bboxes_coco  = np.array(row.bboxes).astype(np.float32).copy()\n    num_bbox     = len(bboxes_coco)\n    names        = ['cots']*num_bbox\n    labels       = np.array([0]*num_bbox)[..., None].astype(str)\n    ## Create Annotation(YOLO)\n    with open(row.label_path, 'w') as f:\n        if num_bbox<1:\n            annot = ''\n            f.write(annot)\n            cnt+=1\n            continue\n        bboxes_voc  = coco2voc(bboxes_coco, image_height, image_width)\n        bboxes_voc  = clip_bbox(bboxes_voc, image_height, image_width)\n        bboxes_yolo = voc2yolo(bboxes_voc, image_height, image_width).astype(str)\n        all_bboxes.extend(bboxes_yolo.astype(float))\n        bboxes_info.extend([[row.image_id, row.video_id, row.sequence]]*len(bboxes_yolo))\n        annots = np.concatenate([labels, bboxes_yolo], axis=1)\n        string = annot2str(annots)\n        f.write(string)\nprint('Missing:',cnt)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import GroupKFold\nkf = GroupKFold(n_splits = 3)\ndf = df.reset_index(drop=True)\ndf['fold'] = -1\nfor fold, (train_idx, val_idx) in enumerate(kf.split(df, groups=df.video_id.tolist())):\n    df.loc[val_idx, 'fold'] = fold\ndisplay(df.fold.value_counts())","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bbox_df = pd.DataFrame(np.concatenate([bboxes_info, all_bboxes], axis=1),\n             columns=['image_id','video_id','sequence',\n                     'xmid','ymid','w','h'])\nbbox_df[['xmid','ymid','w','h']] = bbox_df[['xmid','ymid','w','h']].astype(float)\nbbox_df['area'] = bbox_df.w * bbox_df.h * 1280 * 720\nbbox_df = bbox_df.merge(df[['image_id','fold']], on='image_id', how='left')\nbbox_df.head(2)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df2 = df[(df.num_bbox>0)].sample(100) # takes samples with bbox\ny = 3; x = 2\nplt.figure(figsize=(12.8*x, 7.2*y))\nfor idx in range(x*y):\n    row = df2.iloc[idx]\n    img           = load_image(row.image_path)\n    image_height  = row.height\n    image_width   = row.width\n    with open(row.label_path) as f:\n        annot = str2annot(f.read())\n    bboxes_yolo = annot[...,1:]\n    labels      = annot[..., 0].astype(int).tolist()\n    names         = ['cots']*len(bboxes_yolo)\n    plt.subplot(y, x, idx+1)\n    plt.imshow(draw_bboxes(img = img,\n                           bboxes = bboxes_yolo, \n                           classes = names,\n                           class_ids = labels,\n                           class_name = True, \n                           colors = colors, \n                           bbox_format = 'yolo',\n                           line_thickness = 2))\n    plt.axis('OFF')\nplt.tight_layout()\nplt.show()","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_files = []\nval_files   = []\ntrain_df = df.query(\"fold!=@FOLD\")\nvalid_df = df.query(\"fold==@FOLD\")\ntrain_files += list(train_df.image_path.unique())\nval_files += list(valid_df.image_path.unique())\nlen(train_files), len(val_files)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import yaml\n\ncwd = '/kaggle/working/'\n\nwith open(os.path.join( cwd , 'train.txt'), 'w') as f:\n    for path in train_df.image_path.tolist():\n        f.write(path+'\\n')\n            \nwith open(os.path.join(cwd , 'val.txt'), 'w') as f:\n    for path in valid_df.image_path.tolist():\n        f.write(path+'\\n')\n\ndata = dict(\n    path  = '/kaggle/working',\n    train =  os.path.join( cwd , 'train.txt') ,\n    val   =  os.path.join( cwd , 'val.txt' ),\n    nc    = 1,\n    names = ['cots'],\n    )\n\nwith open(os.path.join( cwd , 'gbr.yaml'), 'w') as outfile:\n    yaml.dump(data, outfile, default_flow_style=False)\n\nf = open(os.path.join( cwd , 'gbr.yaml'), 'r')\nprint('\\nyaml:')\nprint(f.read())","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%writefile /kaggle/working/hyp.yaml\nlr0: 0.01  # initial learning rate (SGD=1E-2, Adam=1E-3)\nlrf: 0.2  # final OneCycleLR learning rate (lr0 * lrf)\nmomentum: 0.937  # SGD momentum/Adam beta1\nweight_decay: 0.0005  # optimizer weight decay 5e-4\nwarmup_epochs: 3.0  # warmup epochs (fractions ok)\nwarmup_momentum: 0.8  # warmup initial momentum\nwarmup_bias_lr: 0.1  # warmup initial bias lr\nbox: 0.05  # box loss gain\ncls: 0.3  # cls loss gain\ncls_pw: 1.0  # cls BCELoss positive_weight\nobj: 0.7  # obj loss gain (scale with pixels)\nobj_pw: 1.0  # obj BCELoss positive_weight\niou_t: 0.20  # IoU training threshold\nanchor_t: 4.0  # anchor-multiple threshold\n# anchors: 3  # anchors per output layer (0 to ignore)\nfl_gamma: 0.0  # focal loss gamma (efficientDet default gamma=1.5)\nhsv_h: 0.015  # image HSV-Hue augmentation (fraction)\nhsv_s: 0.7  # image HSV-Saturation augmentation (fraction)\nhsv_v: 0.4  # image HSV-Value augmentation (fraction)\ndegrees: 0.0  # image rotation (+/- deg)\ntranslate: 0.2  # image translation (+/- fraction)\nscale: 0.9  # image scale (+/- gain)\nshear: 0.0  # image shear (+/- deg)\nperspective: 0.0  # image perspective (+/- fraction), range 0-0.001\nflipud: 0.0  # image flip up-down (probability)\nfliplr: 0.5  # image flip left-right (probability)\nmosaic: 1.0  # image mosaic (probability)\nmixup: 0.15  # image mixup (probability)\ncopy_paste: 0.0  # image copy paste (probability)\npaste_in: 0.15  # image copy paste (probability)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%cd /kaggle/working\n!rm -r /kaggle/working/yolov7\n!git clone https://github.com/WongKinYiu/yolov7.git # clone\n#!cp -r /kaggle/input/yolov5-lib-ds /kaggle/working/yolov5\n%cd yolov7\n%pip install -qr requirements.txt  # install","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%writefile /kaggle/working/yolov7-e6e.yaml\n# parameters\nnc: 1  # number of classes\ndepth_multiple: 1.0  # model depth multiple\nwidth_multiple: 1.0  # layer channel multiple\n\n# anchors\nanchors:\n  - [ 19,27,  44,40,  38,94 ]  # P3/8\n  - [ 96,68,  86,152,  180,137 ]  # P4/16\n  - [ 140,301,  303,264,  238,542 ]  # P5/32\n  - [ 436,615,  739,380,  925,792 ]  # P6/64\n\n# yolov7 backbone\nbackbone:\n  # [from, number, module, args],\n  [[-1, 1, ReOrg, []],  # 0\n   [-1, 1, Conv, [80, 3, 1]],  # 1-P1/2\n   \n   [-1, 1, DownC, [160]],  # 2-P2/4  \n   [-1, 1, Conv, [64, 1, 1]],\n   [-2, 1, Conv, [64, 1, 1]],\n   [-1, 1, Conv, [64, 3, 1]],\n   [-1, 1, Conv, [64, 3, 1]],\n   [-1, 1, Conv, [64, 3, 1]],\n   [-1, 1, Conv, [64, 3, 1]],\n   [-1, 1, Conv, [64, 3, 1]],\n   [-1, 1, Conv, [64, 3, 1]],\n   [[-1, -3, -5, -7, -8], 1, Concat, [1]],\n   [-1, 1, Conv, [160, 1, 1]],  # 12\n   [-11, 1, Conv, [64, 1, 1]],\n   [-12, 1, Conv, [64, 1, 1]],\n   [-1, 1, Conv, [64, 3, 1]],\n   [-1, 1, Conv, [64, 3, 1]],\n   [-1, 1, Conv, [64, 3, 1]],\n   [-1, 1, Conv, [64, 3, 1]],\n   [-1, 1, Conv, [64, 3, 1]],\n   [-1, 1, Conv, [64, 3, 1]],\n   [[-1, -3, -5, -7, -8], 1, Concat, [1]],\n   [-1, 1, Conv, [160, 1, 1]],  # 22\n   [[-1, -11], 1, Shortcut, [1]],  # 23\n         \n   [-1, 1, DownC, [320]],  # 24-P3/8  \n   [-1, 1, Conv, [128, 1, 1]],\n   [-2, 1, Conv, [128, 1, 1]],\n   [-1, 1, Conv, [128, 3, 1]],\n   [-1, 1, Conv, [128, 3, 1]],\n   [-1, 1, Conv, [128, 3, 1]],\n   [-1, 1, Conv, [128, 3, 1]],\n   [-1, 1, Conv, [128, 3, 1]],\n   [-1, 1, Conv, [128, 3, 1]],\n   [[-1, -3, -5, -7, -8], 1, Concat, [1]],\n   [-1, 1, Conv, [320, 1, 1]],  # 34\n   [-11, 1, Conv, [128, 1, 1]],\n   [-12, 1, Conv, [128, 1, 1]],\n   [-1, 1, Conv, [128, 3, 1]],\n   [-1, 1, Conv, [128, 3, 1]],\n   [-1, 1, Conv, [128, 3, 1]],\n   [-1, 1, Conv, [128, 3, 1]],\n   [-1, 1, Conv, [128, 3, 1]],\n   [-1, 1, Conv, [128, 3, 1]],\n   [[-1, -3, -5, -7, -8], 1, Concat, [1]],\n   [-1, 1, Conv, [320, 1, 1]],  # 44\n   [[-1, -11], 1, Shortcut, [1]],  # 45\n         \n   [-1, 1, DownC, [640]],  # 46-P4/16  \n   [-1, 1, Conv, [256, 1, 1]],\n   [-2, 1, Conv, [256, 1, 1]],\n   [-1, 1, Conv, [256, 3, 1]],\n   [-1, 1, Conv, [256, 3, 1]],\n   [-1, 1, Conv, [256, 3, 1]],\n   [-1, 1, Conv, [256, 3, 1]],\n   [-1, 1, Conv, [256, 3, 1]],\n   [-1, 1, Conv, [256, 3, 1]],\n   [[-1, -3, -5, -7, -8], 1, Concat, [1]],\n   [-1, 1, Conv, [640, 1, 1]],  # 56\n   [-11, 1, Conv, [256, 1, 1]],\n   [-12, 1, Conv, [256, 1, 1]],\n   [-1, 1, Conv, [256, 3, 1]],\n   [-1, 1, Conv, [256, 3, 1]],\n   [-1, 1, Conv, [256, 3, 1]],\n   [-1, 1, Conv, [256, 3, 1]],\n   [-1, 1, Conv, [256, 3, 1]],\n   [-1, 1, Conv, [256, 3, 1]],\n   [[-1, -3, -5, -7, -8], 1, Concat, [1]],\n   [-1, 1, Conv, [640, 1, 1]],  # 66\n   [[-1, -11], 1, Shortcut, [1]],  # 67\n         \n   [-1, 1, DownC, [960]],  # 68-P5/32  \n   [-1, 1, Conv, [384, 1, 1]],\n   [-2, 1, Conv, [384, 1, 1]],\n   [-1, 1, Conv, [384, 3, 1]],\n   [-1, 1, Conv, [384, 3, 1]],\n   [-1, 1, Conv, [384, 3, 1]],\n   [-1, 1, Conv, [384, 3, 1]],\n   [-1, 1, Conv, [384, 3, 1]],\n   [-1, 1, Conv, [384, 3, 1]],\n   [[-1, -3, -5, -7, -8], 1, Concat, [1]],\n   [-1, 1, Conv, [960, 1, 1]],  # 78\n   [-11, 1, Conv, [384, 1, 1]],\n   [-12, 1, Conv, [384, 1, 1]],\n   [-1, 1, Conv, [384, 3, 1]],\n   [-1, 1, Conv, [384, 3, 1]],\n   [-1, 1, Conv, [384, 3, 1]],\n   [-1, 1, Conv, [384, 3, 1]],\n   [-1, 1, Conv, [384, 3, 1]],\n   [-1, 1, Conv, [384, 3, 1]],\n   [[-1, -3, -5, -7, -8], 1, Concat, [1]],\n   [-1, 1, Conv, [960, 1, 1]],  # 88\n   [[-1, -11], 1, Shortcut, [1]],  # 89\n         \n   [-1, 1, DownC, [1280]],  # 90-P6/64  \n   [-1, 1, Conv, [512, 1, 1]],\n   [-2, 1, Conv, [512, 1, 1]],\n   [-1, 1, Conv, [512, 3, 1]],\n   [-1, 1, Conv, [512, 3, 1]],\n   [-1, 1, Conv, [512, 3, 1]],\n   [-1, 1, Conv, [512, 3, 1]],\n   [-1, 1, Conv, [512, 3, 1]],\n   [-1, 1, Conv, [512, 3, 1]],\n   [[-1, -3, -5, -7, -8], 1, Concat, [1]],\n   [-1, 1, Conv, [1280, 1, 1]],  # 100 \n   [-11, 1, Conv, [512, 1, 1]],\n   [-12, 1, Conv, [512, 1, 1]],\n   [-1, 1, Conv, [512, 3, 1]],\n   [-1, 1, Conv, [512, 3, 1]],\n   [-1, 1, Conv, [512, 3, 1]],\n   [-1, 1, Conv, [512, 3, 1]],\n   [-1, 1, Conv, [512, 3, 1]],\n   [-1, 1, Conv, [512, 3, 1]],\n   [[-1, -3, -5, -7, -8], 1, Concat, [1]],\n   [-1, 1, Conv, [1280, 1, 1]],  # 110\n   [[-1, -11], 1, Shortcut, [1]],  # 111 \n  ]\n\n# yolov7 head\nhead:\n  [[-1, 1, SPPCSPC, [640]], # 112\n  \n   [-1, 1, Conv, [480, 1, 1]],\n   [-1, 1, nn.Upsample, [None, 2, 'nearest']],\n   [89, 1, Conv, [480, 1, 1]], # route backbone P5\n   [[-1, -2], 1, Concat, [1]],\n   \n   [-1, 1, Conv, [384, 1, 1]],\n   [-2, 1, Conv, [384, 1, 1]],\n   [-1, 1, Conv, [192, 3, 1]],\n   [-1, 1, Conv, [192, 3, 1]],\n   [-1, 1, Conv, [192, 3, 1]],\n   [-1, 1, Conv, [192, 3, 1]],\n   [-1, 1, Conv, [192, 3, 1]],\n   [-1, 1, Conv, [192, 3, 1]],\n   [[-1, -2, -3, -4, -5, -6, -7, -8], 1, Concat, [1]],\n   [-1, 1, Conv, [480, 1, 1]], # 126\n   [-11, 1, Conv, [384, 1, 1]],\n   [-12, 1, Conv, [384, 1, 1]],\n   [-1, 1, Conv, [192, 3, 1]],\n   [-1, 1, Conv, [192, 3, 1]],\n   [-1, 1, Conv, [192, 3, 1]],\n   [-1, 1, Conv, [192, 3, 1]],\n   [-1, 1, Conv, [192, 3, 1]],\n   [-1, 1, Conv, [192, 3, 1]],\n   [[-1, -2, -3, -4, -5, -6, -7, -8], 1, Concat, [1]],\n   [-1, 1, Conv, [480, 1, 1]], # 136\n   [[-1, -11], 1, Shortcut, [1]],  # 137\n  \n   [-1, 1, Conv, [320, 1, 1]],\n   [-1, 1, nn.Upsample, [None, 2, 'nearest']],\n   [67, 1, Conv, [320, 1, 1]], # route backbone P4\n   [[-1, -2], 1, Concat, [1]],\n   \n   [-1, 1, Conv, [256, 1, 1]],\n   [-2, 1, Conv, [256, 1, 1]],\n   [-1, 1, Conv, [128, 3, 1]],\n   [-1, 1, Conv, [128, 3, 1]],\n   [-1, 1, Conv, [128, 3, 1]],\n   [-1, 1, Conv, [128, 3, 1]],\n   [-1, 1, Conv, [128, 3, 1]],\n   [-1, 1, Conv, [128, 3, 1]],\n   [[-1, -2, -3, -4, -5, -6, -7, -8], 1, Concat, [1]],\n   [-1, 1, Conv, [320, 1, 1]], # 151\n   [-11, 1, Conv, [256, 1, 1]],\n   [-12, 1, Conv, [256, 1, 1]],\n   [-1, 1, Conv, [128, 3, 1]],\n   [-1, 1, Conv, [128, 3, 1]],\n   [-1, 1, Conv, [128, 3, 1]],\n   [-1, 1, Conv, [128, 3, 1]],\n   [-1, 1, Conv, [128, 3, 1]],\n   [-1, 1, Conv, [128, 3, 1]],\n   [[-1, -2, -3, -4, -5, -6, -7, -8], 1, Concat, [1]],\n   [-1, 1, Conv, [320, 1, 1]], # 161\n   [[-1, -11], 1, Shortcut, [1]],  # 162\n   \n   [-1, 1, Conv, [160, 1, 1]],\n   [-1, 1, nn.Upsample, [None, 2, 'nearest']],\n   [45, 1, Conv, [160, 1, 1]], # route backbone P3\n   [[-1, -2], 1, Concat, [1]],\n   \n   [-1, 1, Conv, [128, 1, 1]],\n   [-2, 1, Conv, [128, 1, 1]],\n   [-1, 1, Conv, [64, 3, 1]],\n   [-1, 1, Conv, [64, 3, 1]],\n   [-1, 1, Conv, [64, 3, 1]],\n   [-1, 1, Conv, [64, 3, 1]],\n   [-1, 1, Conv, [64, 3, 1]],\n   [-1, 1, Conv, [64, 3, 1]],\n   [[-1, -2, -3, -4, -5, -6, -7, -8], 1, Concat, [1]],\n   [-1, 1, Conv, [160, 1, 1]], # 176\n   [-11, 1, Conv, [128, 1, 1]],\n   [-12, 1, Conv, [128, 1, 1]],\n   [-1, 1, Conv, [64, 3, 1]],\n   [-1, 1, Conv, [64, 3, 1]],\n   [-1, 1, Conv, [64, 3, 1]],\n   [-1, 1, Conv, [64, 3, 1]],\n   [-1, 1, Conv, [64, 3, 1]],\n   [-1, 1, Conv, [64, 3, 1]],\n   [[-1, -2, -3, -4, -5, -6, -7, -8], 1, Concat, [1]],\n   [-1, 1, Conv, [160, 1, 1]], # 186\n   [[-1, -11], 1, Shortcut, [1]],  # 187\n      \n   [-1, 1, DownC, [320]],\n   [[-1, 162], 1, Concat, [1]],\n   \n   [-1, 1, Conv, [256, 1, 1]],\n   [-2, 1, Conv, [256, 1, 1]],\n   [-1, 1, Conv, [128, 3, 1]],\n   [-1, 1, Conv, [128, 3, 1]],\n   [-1, 1, Conv, [128, 3, 1]],\n   [-1, 1, Conv, [128, 3, 1]],\n   [-1, 1, Conv, [128, 3, 1]],\n   [-1, 1, Conv, [128, 3, 1]],\n   [[-1, -2, -3, -4, -5, -6, -7, -8], 1, Concat, [1]],\n   [-1, 1, Conv, [320, 1, 1]], # 199\n   [-11, 1, Conv, [256, 1, 1]],\n   [-12, 1, Conv, [256, 1, 1]],\n   [-1, 1, Conv, [128, 3, 1]],\n   [-1, 1, Conv, [128, 3, 1]],\n   [-1, 1, Conv, [128, 3, 1]],\n   [-1, 1, Conv, [128, 3, 1]],\n   [-1, 1, Conv, [128, 3, 1]],\n   [-1, 1, Conv, [128, 3, 1]],\n   [[-1, -2, -3, -4, -5, -6, -7, -8], 1, Concat, [1]],\n   [-1, 1, Conv, [320, 1, 1]], # 209\n   [[-1, -11], 1, Shortcut, [1]],  # 210\n      \n   [-1, 1, DownC, [480]],\n   [[-1, 137], 1, Concat, [1]],\n   \n   [-1, 1, Conv, [384, 1, 1]],\n   [-2, 1, Conv, [384, 1, 1]],\n   [-1, 1, Conv, [192, 3, 1]],\n   [-1, 1, Conv, [192, 3, 1]],\n   [-1, 1, Conv, [192, 3, 1]],\n   [-1, 1, Conv, [192, 3, 1]],\n   [-1, 1, Conv, [192, 3, 1]],\n   [-1, 1, Conv, [192, 3, 1]],\n   [[-1, -2, -3, -4, -5, -6, -7, -8], 1, Concat, [1]],\n   [-1, 1, Conv, [480, 1, 1]], # 222\n   [-11, 1, Conv, [384, 1, 1]],\n   [-12, 1, Conv, [384, 1, 1]],\n   [-1, 1, Conv, [192, 3, 1]],\n   [-1, 1, Conv, [192, 3, 1]],\n   [-1, 1, Conv, [192, 3, 1]],\n   [-1, 1, Conv, [192, 3, 1]],\n   [-1, 1, Conv, [192, 3, 1]],\n   [-1, 1, Conv, [192, 3, 1]],\n   [[-1, -2, -3, -4, -5, -6, -7, -8], 1, Concat, [1]],\n   [-1, 1, Conv, [480, 1, 1]], # 232\n   [[-1, -11], 1, Shortcut, [1]],  # 233\n      \n   [-1, 1, DownC, [640]],\n   [[-1, 112], 1, Concat, [1]],\n   \n   [-1, 1, Conv, [512, 1, 1]],\n   [-2, 1, Conv, [512, 1, 1]],\n   [-1, 1, Conv, [256, 3, 1]],\n   [-1, 1, Conv, [256, 3, 1]],\n   [-1, 1, Conv, [256, 3, 1]],\n   [-1, 1, Conv, [256, 3, 1]],\n   [-1, 1, Conv, [256, 3, 1]],\n   [-1, 1, Conv, [256, 3, 1]],\n   [[-1, -2, -3, -4, -5, -6, -7, -8], 1, Concat, [1]],\n   [-1, 1, Conv, [640, 1, 1]], # 245\n   [-11, 1, Conv, [512, 1, 1]],\n   [-12, 1, Conv, [512, 1, 1]],\n   [-1, 1, Conv, [256, 3, 1]],\n   [-1, 1, Conv, [256, 3, 1]],\n   [-1, 1, Conv, [256, 3, 1]],\n   [-1, 1, Conv, [256, 3, 1]],\n   [-1, 1, Conv, [256, 3, 1]],\n   [-1, 1, Conv, [256, 3, 1]],\n   [[-1, -2, -3, -4, -5, -6, -7, -8], 1, Concat, [1]],\n   [-1, 1, Conv, [640, 1, 1]], # 255\n   [[-1, -11], 1, Shortcut, [1]],  # 256\n   \n   [187, 1, Conv, [320, 3, 1]],\n   [210, 1, Conv, [640, 3, 1]],\n   [233, 1, Conv, [960, 3, 1]],\n   [256, 1, Conv, [1280, 3, 1]],\n   \n   [186, 1, Conv, [320, 3, 1]],\n   [161, 1, Conv, [640, 3, 1]],\n   [136, 1, Conv, [960, 3, 1]],\n   [112, 1, Conv, [1280, 3, 1]],\n\n   [[257,258,259,260,261,262,263,264], 1, IAuxDetect, [nc, anchors]],   # Detect(P3, P4, P5, P6)\n  ]","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!wget https://github.com/WongKinYiu/yolov7/releases/download/v0.1/yolov7-e6e_training.pt","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!python train_aux.py --workers 8 --device 0 --epochs {EPOCHS} --batch-size {BATCH} --data /kaggle/working/gbr.yaml --img 1280 1280 --cfg /kaggle/working/yolov7-e6e.yaml --weights yolov7-e6e_training.pt --name {NAME} --hyp /kaggle/working/hyp.yaml","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}