{"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":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport torch\nfrom tqdm import tqdm\nimport sys\n\nsys.path.append('../input/tensorflow-great-barrier-reef')","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!mkdir -p /root/.config/Ultralytics\n!cp /kaggle/input/yolov5-font/Arial.ttf /root/.config/Ultralytics/","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import greatbarrierreef\nenv = greatbarrierreef.make_env()# initialize the environment\niter_test = env.iter_test()      # an iterator which loops over the test set and sample submission","metadata":{"execution":{"iopub.status.busy":"2022-01-12T06:17:41.194729Z","iopub.execute_input":"2022-01-12T06:17:41.195011Z","iopub.status.idle":"2022-01-12T06:17:41.220687Z","shell.execute_reply.started":"2022-01-12T06:17:41.194973Z","shell.execute_reply":"2022-01-12T06:17:41.21992Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = torch.hub.load('../input/yolov5-lib-ds', \n                       'custom', \n                       path='../input/yolov5-high-resolution-training/yolov5/runs/train/l6_3600_uflip_vm5_f1/weights/best.pt',\n                       source='local',\n                       force_reload=True)  # local repo\nmodel.conf = 0.01","metadata":{"execution":{"iopub.status.busy":"2022-01-12T06:18:34.92187Z","iopub.execute_input":"2022-01-12T06:18:34.92215Z","iopub.status.idle":"2022-01-12T06:18:41.246215Z","shell.execute_reply.started":"2022-01-12T06:18:34.922121Z","shell.execute_reply":"2022-01-12T06:18:41.245413Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for idx, (img, pred_df) in enumerate(tqdm(iter_test)):\n    anno = ''\n    r = model(img, size=3600, augment=True)\n    if r.pandas().xyxy[0].shape[0] == 0:\n        anno = ''\n    else:\n        for idx, row in r.pandas().xyxy[0].iterrows():\n            if row.confidence > 0.15:\n                anno += '{} {} {} {} {} '.format(row.confidence, int(row.xmin), int(row.ymin), int(row.xmax-row.xmin), int(row.ymax-row.ymin))\n#                 pred.append([row.confidence, row.xmin, row.ymin, row.xmax-row.xmin, row.ymax-row.ymin])\n    pred_df['annotations'] = anno.strip(' ')\n    env.predict(pred_df)","metadata":{"execution":{"iopub.status.busy":"2022-01-12T06:18:41.248178Z","iopub.execute_input":"2022-01-12T06:18:41.249643Z","iopub.status.idle":"2022-01-12T06:18:46.826251Z","shell.execute_reply.started":"2022-01-12T06:18:41.249595Z","shell.execute_reply":"2022-01-12T06:18:46.825522Z"},"trusted":true},"execution_count":null,"outputs":[]}]}