{"cells":[{"metadata":{},"cell_type":"markdown","source":"This is a starter kernel based on @ultralytics demo with COCO\n\nJust a quick note. You will see a download with my gdrive. I have already made the labels outside of Kaggle. I wanted to match the ultralytics version here with real data. If you have questions / suggestions please comment. ","execution_count":null},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"!git clone https://github.com/ultralytics/yolov5  # clone repo\n!pip install -r yolov5/requirements.txt  # install dependencies\n%cd yolov5\n\nimport torch\nfrom IPython.display import Image, clear_output  # to display images\nfrom utils.google_utils import gdrive_download  # to download models/datasets\n\nclear_output()\nprint('Setup complete. Using torch %s %s' % (torch.__version__, torch.cuda.get_device_properties(0) if torch.cuda.is_available() else 'CPU'))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"%cd ..","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"# Download wheat and labels\ngdrive_download('1XqetalfvoOpgYK2YsyHmMu85qEHTgjGN','WheatYolo.zip')  # dataset","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"The yaml file below is my adjusted version yolo5x yaml file where you have to change the nc: 1  \nYou can upload the yaml file yourself just change the nc:\nhttps://github.com/ultralytics/yolov5/blob/master/models/yolov5x.yaml\n\nThat dataset should also be public. ","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"!mv ../input/wheatyaml/yolov5xnc1.yaml ./","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"%cd yolov5\n!ls","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"All training results are saved to runs/exp0 for the first experiment, then runs/exp1, runs/exp2 etc. for subsequent experiments.\n\nI just set basic img size, batch and epochs. These are for you to tweak. ","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"%%time\n!python train.py --img 416 --batch 16 --epochs 2 --data '../data.yaml' --cfg '../yolov5xnc1.yaml' --weights '' --name tutorial --nosave --cache","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# start tensorboard\n# launch after training \n# log saves in the folder \"runs\"\n#%load_ext tensorboard\n#%tensorboard --logdir runs\n#if Kaggle ever fixes issue with tensorboard uncomment the two lines above. ","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Visualize the training data\n\n> After training starts, view `train*.jpg` images to see training images, labels and augmentation effects.","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"Image(filename='runs/exp0_tutorial/train_batch1.jpg', width=900)  # view augmented training mosaics","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"Image(filename='runs/exp0_tutorial/test_batch0_gt.jpg', width=900)  # view test image labels","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"Image(filename='runs/exp0_tutorial/test_batch0_pred.jpg', width=900)  # view test image predictions","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Run Inference with Trained Weights\n\nRun inference with a pretrained checkpoint on contents of test/images folder","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"# trained weights are saved by default in our weights folder\n%ls","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"!python detect.py --source ../test/images --weights 'runs/exp0_tutorial/weights/last_tutorial.pt' --img 416 --conf 0.5","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"!ls","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"%cd inference/output/","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"!ls","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"Image(filename='2fd875eaa_jpg.rf.dd1d8cd790ac7bd4fa42b63bd6b6293b.jpg', width=900)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"Image(filename='348a992bb_jpg.rf.1d04a696a55ee0ae7737b687d63f7af6.jpg', width=900)","execution_count":null,"outputs":[]}],"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":4,"nbformat_minor":4}