{"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":"markdown","source":" ## This code is to download YOLO data from its offical data center \"Github\"\n YOLOv7 is one of the best methods available in the current emerging technologies for object detection and a more accurate one available. ","metadata":{}},{"cell_type":"code","source":"# Download YOLOv7 repository and install requirements\n!git clone https://github.com/WongKinYiu/yolov7\n%cd yolov7\n!pip install -r requirements.txt","metadata":{"id":"nD-uPyQ_2jiN","execution":{"iopub.status.busy":"2022-12-22T13:29:40.65708Z","iopub.execute_input":"2022-12-22T13:29:40.660355Z","iopub.status.idle":"2022-12-22T13:29:57.106262Z","shell.execute_reply.started":"2022-12-22T13:29:40.660302Z","shell.execute_reply":"2022-12-22T13:29:57.104962Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## This part of the code is attaching the API's\n### Add-ons -> secerts -> attach api's","metadata":{"execution":{"iopub.status.busy":"2022-12-21T17:05:41.365489Z","iopub.execute_input":"2022-12-21T17:05:41.366233Z","iopub.status.idle":"2022-12-21T17:05:41.391127Z","shell.execute_reply.started":"2022-12-21T17:05:41.366146Z","shell.execute_reply":"2022-12-21T17:05:41.390232Z"}}},{"cell_type":"code","source":"from kaggle_secrets import UserSecretsClient\nuser_secrets = UserSecretsClient()\nsecret_value_0 = user_secrets.get_secret(\"roboflow_api\")\nsecret_value_1 = user_secrets.get_secret(\"wand_api\")","metadata":{"execution":{"iopub.status.busy":"2022-12-22T13:30:15.967283Z","iopub.execute_input":"2022-12-22T13:30:15.968025Z","iopub.status.idle":"2022-12-22T13:30:16.298012Z","shell.execute_reply.started":"2022-12-22T13:30:15.967988Z","shell.execute_reply":"2022-12-22T13:30:16.296849Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## This code is for Importing the data for processing from Roboflow website","metadata":{}},{"cell_type":"code","source":"!pip install roboflow\n\nfrom roboflow import Roboflow\nrf = Roboflow(api_key=secret_value_0)\nproject = rf.workspace(\"rathinam-college-of-arts-and-science-l6xbt\").project(\"breasy_cancer\")\ndataset = project.version(1).download(\"yolov7\")","metadata":{"id":"ovKgrVN8ygdW","execution":{"iopub.status.busy":"2022-12-22T13:43:01.735424Z","iopub.execute_input":"2022-12-22T13:43:01.736636Z","iopub.status.idle":"2022-12-22T13:43:30.941534Z","shell.execute_reply.started":"2022-12-22T13:43:01.736575Z","shell.execute_reply":"2022-12-22T13:43:30.94026Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## This code is for downloading  the pre tarined weights for kick starting the YOLO","metadata":{}},{"cell_type":"code","source":"# download COCO starting checkpoint\n#%cd /kaggle/working/yolov7\n#!wget https://github.com/WongKinYiu/yolov7/releases/download/v0.1/yolov7_training.pt","metadata":{"id":"bUbmy674bhpD","execution":{"iopub.status.busy":"2022-12-22T14:20:54.647018Z","iopub.execute_input":"2022-12-22T14:20:54.647416Z","iopub.status.idle":"2022-12-22T14:21:08.172764Z","shell.execute_reply.started":"2022-12-22T14:20:54.647386Z","shell.execute_reply":"2022-12-22T14:21:08.171651Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## This part of the code is importing the wandb login for processing the YOLOv7 because the kaggle supports the wandb for processing the  YOLOv7.","metadata":{}},{"cell_type":"code","source":"!pip install wandb","metadata":{"execution":{"iopub.status.busy":"2022-12-22T13:38:32.507591Z","iopub.execute_input":"2022-12-22T13:38:32.508778Z","iopub.status.idle":"2022-12-22T13:38:43.444837Z","shell.execute_reply.started":"2022-12-22T13:38:32.508731Z","shell.execute_reply":"2022-12-22T13:38:43.443565Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import wandb\n\ntry:\n    user_secrets = UserSecretsClient()\n    wandb_api_key = user_secrets.get_secret(\"wand_api\")\n    wandb.login(key=wandb_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')\n  \n    \n","metadata":{"execution":{"iopub.status.busy":"2022-12-22T13:38:46.874584Z","iopub.execute_input":"2022-12-22T13:38:46.874977Z","iopub.status.idle":"2022-12-22T13:38:49.38767Z","shell.execute_reply.started":"2022-12-22T13:38:46.874939Z","shell.execute_reply":"2022-12-22T13:38:49.386453Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## This part of the coding is for running the **Epochs** for training","metadata":{"execution":{"iopub.status.busy":"2022-12-21T17:15:25.326515Z","iopub.execute_input":"2022-12-21T17:15:25.327815Z","iopub.status.idle":"2022-12-21T17:15:25.333592Z","shell.execute_reply.started":"2022-12-21T17:15:25.327771Z","shell.execute_reply":"2022-12-21T17:15:25.332459Z"}}},{"cell_type":"code","source":"# run this cell to begin training\n%cd /kaggle/working/yolov7\n!python train.py --batch 28 --epochs 55 --data /kaggle/working/yolov7/breasy_cancer-1/data.yaml --weights '/kaggle/input/yolov7-weight/yolov7.pt' --device 0,1 \n","metadata":{"id":"1iqOPKjr22mL","execution":{"iopub.status.busy":"2022-12-22T13:44:37.854291Z","iopub.execute_input":"2022-12-22T13:44:37.854718Z","iopub.status.idle":"2022-12-22T14:04:01.706799Z","shell.execute_reply.started":"2022-12-22T13:44:37.85467Z","shell.execute_reply":"2022-12-22T14:04:01.705643Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## This part of the coding is for **fussing** the trainded data in the test data.","metadata":{}},{"cell_type":"code","source":"# Run evaluation\n%cd /kaggle/working/yolov7\n!python detect.py --weights \"runs/train/exp/weights/best.pt\" --conf 0.1 --source  \"/kaggle/working/yolov7/breasy_cancer-1/test/images\"\n","metadata":{"id":"N4cfnLtTCIce","execution":{"iopub.status.busy":"2022-12-22T14:04:21.485795Z","iopub.execute_input":"2022-12-22T14:04:21.486176Z","iopub.status.idle":"2022-12-22T14:04:43.138713Z","shell.execute_reply.started":"2022-12-22T14:04:21.48614Z","shell.execute_reply":"2022-12-22T14:04:43.137554Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## This part of the code is visualizing the fussed data","metadata":{}},{"cell_type":"code","source":"#display inference on ALL test images\n\nimport glob\nfrom IPython.display import Image, display\n\ni = 0\nlimit = 10000 # max images to print\nfor imageName in glob.glob('/kaggle/working/yolov7/runs/detect/exp/*.jpg'): #assuming JPG\n    if i < limit:\n      display(Image(filename=imageName))\n      print(\"\\n\")\n    i = i + 1\n    ","metadata":{"id":"6AGhNOSSHY4_","outputId":"b0e7593f-5c5b-4807-82ab-57ffc65a8ca2","execution":{"iopub.status.busy":"2022-12-22T14:05:00.286576Z","iopub.execute_input":"2022-12-22T14:05:00.286978Z","iopub.status.idle":"2022-12-22T14:05:00.48576Z","shell.execute_reply.started":"2022-12-22T14:05:00.286941Z","shell.execute_reply":"2022-12-22T14:05:00.484879Z"},"trusted":true},"execution_count":null,"outputs":[]}]}