\n",
- "\n",
- "
\n",
- " \n",
- "\n",
- "\n",
- "
\n",
- "
\n",
- "
\n",
- "
\n",
- "
\n",
- "\n",
- "This
YOLOv5 🚀 notebook by
Ultralytics presents simple train, validate and predict examples to help start your AI adventure.
See
GitHub for community support or
contact us for professional support.\n",
- "\n",
- "
"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "id": "7mGmQbAO5pQb"
- },
- "source": [
- "# Setup\n",
- "\n",
- "Clone GitHub [repository](https://github.com/ultralytics/yolov5), install [dependencies](https://github.com/ultralytics/yolov5/blob/master/requirements.txt) and check PyTorch and GPU."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {
- "colab": {
- "base_uri": "https://localhost:8080/"
- },
- "id": "wbvMlHd_QwMG",
- "outputId": "0806e375-610d-4ec0-c867-763dbb518279"
- },
- "outputs": [
- {
- "output_type": "stream",
- "name": "stderr",
- "text": [
- "YOLOv5 🚀 v7.0-3-g61ebf5e Python-3.7.15 torch-1.12.1+cu113 CUDA:0 (Tesla T4, 15110MiB)\n"
- ]
- },
- {
- "output_type": "stream",
- "name": "stdout",
- "text": [
- "Setup complete ✅ (2 CPUs, 12.7 GB RAM, 22.6/78.2 GB disk)\n"
- ]
- }
- ],
- "source": [
- "!git clone https://github.com/ultralytics/yolov5 # clone\n",
- "%cd yolov5\n",
- "%pip install -qr requirements.txt # install\n",
- "\n",
- "import torch\n",
- "import utils\n",
- "display = utils.notebook_init() # checks"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "id": "4JnkELT0cIJg"
- },
- "source": [
- "# 1. Predict\n",
- "\n",
- "`classify/predict.py` runs YOLOv5 Classification inference on a variety of sources, downloading models automatically from the [latest YOLOv5 release](https://github.com/ultralytics/yolov5/releases), and saving results to `runs/predict-cls`. Example inference sources are:\n",
- "\n",
- "```shell\n",
- "python classify/predict.py --source 0 # webcam\n",
- " img.jpg # image \n",
- " vid.mp4 # video\n",
- " screen # screenshot\n",
- " path/ # directory\n",
- " 'path/*.jpg' # glob\n",
- " 'https://youtu.be/Zgi9g1ksQHc' # YouTube\n",
- " 'rtsp://example.com/media.mp4' # RTSP, RTMP, HTTP stream\n",
- "```"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {
- "colab": {
- "base_uri": "https://localhost:8080/"
- },
- "id": "zR9ZbuQCH7FX",
- "outputId": "50504ef7-aa3e-4281-a4e3-d0c7df3c0ffe"
- },
- "outputs": [
- {
- "output_type": "stream",
- "name": "stdout",
- "text": [
- "\u001b[34m\u001b[1mclassify/predict: \u001b[0mweights=['yolov5s-cls.pt'], source=data/images, data=data/coco128.yaml, imgsz=[224, 224], device=, view_img=False, save_txt=False, nosave=False, augment=False, visualize=False, update=False, project=runs/predict-cls, name=exp, exist_ok=False, half=False, dnn=False, vid_stride=1\n",
- "YOLOv5 🚀 v7.0-3-g61ebf5e Python-3.7.15 torch-1.12.1+cu113 CUDA:0 (Tesla T4, 15110MiB)\n",
- "\n",
- "Downloading https://github.com/ultralytics/yolov5/releases/download/v7.0/yolov5s-cls.pt to yolov5s-cls.pt...\n",
- "100% 10.5M/10.5M [00:00<00:00, 12.3MB/s]\n",
- "\n",
- "Fusing layers... \n",
- "Model summary: 117 layers, 5447688 parameters, 0 gradients, 11.4 GFLOPs\n",
- "image 1/2 /content/yolov5/data/images/bus.jpg: 224x224 minibus 0.39, police van 0.24, amphibious vehicle 0.05, recreational vehicle 0.04, trolleybus 0.03, 3.9ms\n",
- "image 2/2 /content/yolov5/data/images/zidane.jpg: 224x224 suit 0.38, bow tie 0.19, bridegroom 0.18, rugby ball 0.04, stage 0.02, 4.6ms\n",
- "Speed: 0.3ms pre-process, 4.3ms inference, 1.5ms NMS per image at shape (1, 3, 224, 224)\n",
- "Results saved to \u001b[1mruns/predict-cls/exp\u001b[0m\n"
- ]
- }
- ],
- "source": [
- "!python classify/predict.py --weights yolov5s-cls.pt --img 224 --source data/images\n",
- "# display.Image(filename='runs/predict-cls/exp/zidane.jpg', width=600)"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "id": "hkAzDWJ7cWTr"
- },
- "source": [
- " \n",
- "