Human behavior with YOLO-World Cookbook (#915)

* Real application underestand visitors with yolo-world
* Improvements in the examples
* Small improvements in typing
* improve path video results
* fix(pre_commit): 🎨 auto format pre-commit hooks

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: jirka <6035284+Borda@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2026-02-03 14:59:08 +01:00
1 parent 6af1ab31f4
commit 2ca9bee083
2 files changed
+851

No files matched your search

@@ -0,0 +1,847 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "kR-PyK7YXPVZ"
},
"source": [
"# Underestand Visitors with YOLO-World\n",
"---\n",
"[![Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/roboflow/supervision/blob/develop/docs/notebooks/zero-shot-object-detection-with-yolo-world.ipynb)\n",
"[![Roboflow](https://raw.githubusercontent.com/roboflow-ai/notebooks/main/assets/badges/roboflow-blogpost.svg)](https://blog.roboflow.com/what-is-yolo-world/)\n",
"[![GitHub](https://badges.aleen42.com/src/github.svg)](https://github.com/AILab-CVC/YOLO-World)\n",
"[![arXiv](https://img.shields.io/badge/arXiv-2401.17270-b31b1b.svg)](https://arxiv.org/abs/2401.17270)\n",
"\n",
"Click the `Open in Colab` button to run the cookbook on Google Colab.\n",
"\n",
"<br>\n",
"\n",
"Understanding visitor behavior in malls, stores, and events is key to improving services and customer experience. With YOLO-World, we can now instantly identify specific visitor traits, like clothing colors or behaviors, without needing pre-trained data. This flexibility allows for tailored insights, enhancing how we manage and engage with visitors in any physical space.\n",
"\n",
"![visualization results of referring object detection](https://storage.googleapis.com/adonaivera_certified/test.jpeg)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "T-lkdAZUY73s"
},
"source": [
"## Before you start\n",
"\n",
"Let's make sure that we have access to GPU. We can use `nvidia-smi` command to do that. In case of any problems navigate to `Edit` -> `Notebook settings` -> `Hardware accelerator`, set it to `GPU`, and then click `Save`."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "mP1Bv5jBXNbw",
"outputId": "43cc5b50-9958-447d-f597-9ee510e52792"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Fri Feb 16 22:18:58 2024 \n",
"+---------------------------------------------------------------------------------------+\n",
"| NVIDIA-SMI 535.154.05 Driver Version: 535.154.05 CUDA Version: 12.2 |\n",
"|-----------------------------------------+----------------------+----------------------+\n",
"| GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC |\n",
"| Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. |\n",
"| | | MIG M. |\n",
"|=========================================+======================+======================|\n",
"| 0 NVIDIA GeForce RTX 4070 Ti Off | 00000000:01:00.0 On | N/A |\n",
"| 0% 35C P8 10W / 285W | 789MiB / 12282MiB | 37% Default |\n",
"| | | N/A |\n",
"+-----------------------------------------+----------------------+----------------------+\n",
" \n",
"+---------------------------------------------------------------------------------------+\n",
"| Processes: |\n",
"| GPU GI CI PID Type Process name GPU Memory |\n",
"| ID ID Usage |\n",
"|=======================================================================================|\n",
"| 0 N/A N/A 1385 G /usr/lib/xorg/Xorg 235MiB |\n",
"| 0 N/A N/A 1665 G /usr/bin/gnome-shell 127MiB |\n",
"| 0 N/A N/A 3005 G ...seed-version=20240209-130055.018000 56MiB |\n",
"| 0 N/A N/A 5673 G ...yOnDemand --variations-seed-version 55MiB |\n",
"| 0 N/A N/A 92076 G ...sion,SpareRendererForSitePerProcess 188MiB |\n",
"| 0 N/A N/A 92574 G ...erProcess --variations-seed-version 108MiB |\n",
"+---------------------------------------------------------------------------------------+\n"
]
}
],
"source": [
"!nvidia-smi"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "nySApmvdZDEd"
},
"source": [
"**NOTE:** To make it easier for us to manage datasets, images and models we create a `HOME` constant."
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "JGXqXrQfY2yo",
"outputId": "161ad18e-a296-4f27-b9c4-2c1fb68a2fc3"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"/home/adonai/Documents/supervision/docs/notebooks\n"
]
}
],
"source": [
"import os\n",
"HOME = os.getcwd()\n",
"print(HOME)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "h1jNp-i3ZL0D"
},
"source": [
"## Install required packages\n",
"\n",
"In this guide, we utilize two Python packages: `inference`, for executing zero-shot object detection using YOLO-World, and `supervision`, for post-processing and visualizing the detected objects."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"id": "zfc06V9QZFup"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m23.3.2\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.0\u001b[0m\n",
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n"
]
}
],
"source": [
"!pip install -q inference-gpu[yolo-world]==0.9.12rc1"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"id": "44LZf5qb3bet"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m23.3.2\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.0\u001b[0m\n",
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n"
]
}
],
"source": [
"!pip install -q supervision==0.19.0rc3"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dnEI8EOpalbe"
},
"source": [
"## Imports"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"id": "UIcZyEhuacFT"
},
"outputs": [
{
"data": {
"text/html": [
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">[02/16/24 22:24:10] </span><span style=\"color: #800000; text-decoration-color: #800000\">WARNING </span> Your inference package version <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0.9</span>.12rc1 is out of date! Please upgrade <a href=\"file:///home/adonai/Documents/supervision/env/lib/python3.9/site-packages/inference/core/__init__.py\" target=\"_blank\"><span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">__init__.py</span></a><span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">:</span><a href=\"file:///home/adonai/Documents/supervision/env/lib/python3.9/site-packages/inference/core/__init__.py#35\" target=\"_blank\"><span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">35</span></a>\n",
"<span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\"> </span> to version <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0.9</span>.<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">13</span> of inference for the latest features and bug fixes by <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\"> </span>\n",
"<span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\"> </span> running `pip install --upgrade inference`. <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\"> </span>\n",
"</pre>\n"
],
"text/plain": [
"\u001b[2;36m[02/16/24 22:24:10]\u001b[0m\u001b[2;36m \u001b[0m\u001b[31mWARNING \u001b[0m Your inference package version \u001b[1;36m0.9\u001b[0m.12rc1 is out of date! Please upgrade \u001b]8;id=987691;file:///home/adonai/Documents/supervision/env/lib/python3.9/site-packages/inference/core/__init__.py\u001b\\\u001b[2m__init__.py\u001b[0m\u001b]8;;\u001b\\\u001b[2m:\u001b[0m\u001b]8;id=799287;file:///home/adonai/Documents/supervision/env/lib/python3.9/site-packages/inference/core/__init__.py#35\u001b\\\u001b[2m35\u001b[0m\u001b]8;;\u001b\\\n",
"\u001b[2;36m \u001b[0m to version \u001b[1;36m0.9\u001b[0m.\u001b[1;36m13\u001b[0m of inference for the latest features and bug fixes by \u001b[2m \u001b[0m\n",
"\u001b[2;36m \u001b[0m running `pip install --upgrade inference`. \u001b[2m \u001b[0m\n"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import cv2\n",
"import supervision as sv\n",
"\n",
"from tqdm import tqdm\n",
"from inference.models.yolo_world.yolo_world import YOLOWorld"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "ULzC4SZdbO-L"
},
"source": [
"## Download example data"
]
},
{
"cell_type": "code",
"execution_count": 77,
"metadata": {
"id": "29c6jMS1a7NS"
},
"outputs": [],
"source": [
"!wget -P {HOME} -q https://storage.googleapis.com/adonaivera_certified/test.jpeg\n",
"!wget -P {HOME} -q https://storage.googleapis.com/adonaivera_certified/test_demo1.mp4"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"id": "Kvq4jtTjg31-"
},
"outputs": [],
"source": [
"SOURCE_IMAGE_PATH = f\"{HOME}/test.jpeg\"\n",
"SOURCE_VIDEO_PATH = f\"{HOME}/test_demo1.mp4\""
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "M0_JmZ08gyYg"
},
"source": [
"**NOTE:** If you want to run the cookbook using your own file as input, simply upload video to Google Colab and replace `SOURCE_IMAGE_PATH` and `SOURCE_VIDEO_PATH` with the path to your file."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "NLP6DK4YbVpm"
},
"source": [
"## Run Object Detection\n",
"\n",
"The Inference package provides the YOLO-World model in three versions: `S`, `M`, and `L`. You can load them by defining model_id as `yolo_world/s`, `yolo_world/m`, and `yolo_world/l`, respectively. The `ROBOFLOW_API_KEY` is not required to utilize this model.\n",
"\n",
"\n",
"\n",
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"id": "osrplWqebju0"
},
"outputs": [],
"source": [
"model = YOLOWorld(model_id=\"yolo_world/l\")"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "vzZgYhZodzgS"
},
"source": [
"YOLO-World is a zero-shot model, enabling object detection without any training. You only need to define a prompt as a list of classes (things) you are searching for."
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "UZTYuZlAdYhC",
"outputId": "89dba6b8-5f80-4802-fe85-27b4b5c66bb3"
},
"outputs": [],
"source": [
"classes = [\"person\"]\n",
"model.set_classes(classes)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "fXLWvBQNgoV_"
},
"source": [
"We perform detection on our sample image. Then, we convert the result into a [`sv.Detections`](https://supervision.roboflow.com/latest/detection/core/) object, which will be useful in the later parts of the cookbook."
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"id": "ZinEbFJsdp9m"
},
"outputs": [],
"source": [
"image = cv2.imread(SOURCE_IMAGE_PATH)\n",
"results = model.infer(image, confidence=0.003)\n",
"detections = sv.Detections.from_inference(results).with_nms(threshold=0.1)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "jiYw1EXzhpbu"
},
"source": [
"The results we've obtained can be easily visualized with [`sv.BoundingBoxAnnotator`](https://supervision.roboflow.com/latest/annotators/#supervision.annotators.core.BoundingBoxAnnotator) and [`sv.LabelAnnotator`](https://supervision.roboflow.com/latest/annotators/#supervision.annotators.core.LabelAnnotator). We can adjust parameters such as line thickness, text scale, line and text color allowing for a highly tailored visualization experience."
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"id": "37CMTxw0jSyH"
},
"outputs": [],
"source": [
"BOUNDING_BOX_ANNOTATOR = sv.BoundingBoxAnnotator(thickness=2)\n",
"LABEL_ANNOTATOR = sv.LabelAnnotator(text_thickness=2, text_scale=1, text_color=sv.Color.BLACK)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"By default, `sv.LabelAnnotator` displays only the names of objects. To also view the confidence levels associated with each detection, we must define custom `labels` and pass them to `sv.LabelAnnotator`."
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 807
},
"id": "YkVoWxchher5",
"outputId": "ff1dce17-5584-496a-9113-e4d5123489b4"
},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAxoAAAHHCAYAAAA4fy6KAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/H5lhTAAAACXBIWXMAAA9hAAAPYQGoP6dpAAEAAElEQVR4nOz9eZRl15XeB/7OcIc3xxwZkXMmMhOJkQAJggQIkgDHmlxVqkmWqrvlklpLbS1r6JaHbruXV7dl2eqWbcmWLZXKdlsqDa7BKhVZVSoOAGcSAAGQABJAJpBzZmTMEW++4zmn/zj3vQRYZYnyqrVaq1fsxWQmIl7Ee+++c8/Z+9vf923hnHMcxEEcxEEcxEEcxEEcxEEcxEH8EYb8//ULOIiDOIiDOIiDOIiDOIiDOIj//4uDQuMgDuIgDuIgDuIgDuIgDuIg/sjjoNA4iIM4iIM4iIM4iIM4iIM4iD/yOCg0DuIgDuIgDuIgDuIgDuIgDuKPPA4KjYM4iIM4iIM4iIM4iIM4iIP4I4+DQuMgDuIgDuIgDuIgDuIgDuIg/sjjoNA4iIM4iIM4iIM4iIM4iIM4iD/yOCg0DuIgDuIgDuIgDuIgDuIgDuKPPPQP+8Cj9xxBSolzYK2lKAqMMVhraTQaBEGAMQ4dCISSJElOGCowGUo4Wjrj6SfO0Go7bt26SmA0IQn3PnCWb14c8ub1IVY0sKXFWMPM7CxKQ3d/i7nZNq16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/H1cba7w8IwwClJNtZShgGNNsNFpeWGI/H1OuNqgCGINA440izhDzPsM4xGAy5c+cODz3wANZYtFYgNNY5GmFEFNYAR1FYrHFEQZM0STl8ZJXV1VVOnjgNTiIlDEb79Hq7SNnmn/zjf8Ta2hpaa3Z2dijLkk6nQzJO/IarFXlaIKlTrzc4evQIP/uzf4xnn/19Ll66QL1WZ8Osc/78g2RZzq1bdwiDgEazweLiMuPxmEajxeHDR3jm6U/w6qvfJUmGdDptOm3JaDSmKDKazQbj8Zjr166zsnKE9TtbbKxv8+EPP8GpU0f4ynNfYDDsI6UiiloYY6g3GsS1mL29IUpr1u6sURQpaTomrkVsbq3R6+8wtxBy9eodvvvK99nd3eXB978PpODI8iGEFLSbbZTW3Lx5EwRYVyJVhDUGqeDDH/4gs3Nt9vd3q8NyyNLSwvSQi6INdnd30YFmfqHF3Hyd8XhElhXU6zVarRZaa7rdiHEyptmeZW52ljCKyEarjEZD1tbu0G63OXv2HEmSEDc6ZIXm/gcf4sqVt3n2S19mbq5DUaS+cM8ywqBGo9ngyNGjZFnK5uY29XqNQ4cO+WJdabr7fe6sbSCEJIpv0Wq1aDabHD92gkBH5FlJWZRIKTl37l7eeustnLNo7e81cIzHCc5CkqYgnAeNnKXf73Px4kWOHz/OYNhjNO5z9MhxHnroPKdPn8DhuHHjJq989xV+4Wd/DqU0rUaDI0eO8M7Fdzh371nCUGNsTpoOWV09BAjSPGV3b4PP/tgn+MqXvsr21g5SyWkiONPpkOUZW9v+fXU6ba5fv0pZljz50Q+wtbnFm2++SRyHJOOEXm+fokxR2vLmm2/y+oU3KPKS0SgDNO/7wAdYXl4miiK+973vkSQpKEmW5ZRFiRAarTRSCISrgCDnMMbS6w64dPEyYRhy/Ng9DIdjhBgThgFhGODwycPc3Bw3bLine truncated
"text/plain": [
"<Figure size 1000x1000 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"labels = [\n",
" f\"{classes[class_id]} {confidence:0.3f}\"\n",
" for class_id, confidence\n",
" in zip(detections.class_id, detections.confidence)\n",
"]\n",
"\n",
"annotated_image = image.copy()\n",
"annotated_image = BOUNDING_BOX_ANNOTATOR.annotate(annotated_image, detections)\n",
"annotated_image = LABEL_ANNOTATOR.annotate(annotated_image, detections, labels=labels)\n",
"sv.plot_image(annotated_image, (10, 10))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Make Special Search\n",
"Imagine you're the marketing director of a leading retail chain, tasked with decoding the behavior of your visitors. Picture one of your flagship stores in the mall, renowned for its exquisite collection of hats and backpacks. You're curious about the number of event attendees sporting hats and backpacks. Enter YOLO-World, a tool that simplifies this task, requiring no prior training. With YOLO-World, you can effortlessly gauge customer preferences and trends, enabling you to tailor your marketing strategies and inventory to better meet your customers' needs."
]
},
{
"cell_type": "code",
"execution_count": 63,
"metadata": {},
"outputs": [],
"source": [
"\n",
"classes = [\"person\", \"backpack\", \"persons with backpack\", \"persons with hats\", \"hats\"]\n",
"model.set_classes(classes)"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAxoAAAHHCAYAAAA4fy6KAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/H5lhTAAAACXBIWXMAAA9hAAAPYQGoP6dpAAEAAElEQVR4nOz995NkV5bfCX6ueMK1e8iMSJ0JIIFCFVBaoVACpZrdzW0u2WzuznLWbJdjY9z/ZcWIteHscmYFh0MOh1w2W7DZpVBaowR0Akikzgwd4fqpK/aH+9wTNTbGLpq12ZqtxTELQyDSw8P9+X33nvM93+/3CO+95zRO4zRO4zRO4zRO4zRO4zRO468x5P+vX8BpnMZpnMZpnMZpnMZpnMZp/P9fnBYap3Eap3Eap3Eap3Eap3Eap/HXHqeFxmmcxmmcxmmcxmmcxmmcxmn8tcdpoXEap3Eap3Eap3Eap3Eap3Eaf+1xWm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wY9+lM3NTZIk4Ve/+hVZloOSFEWJqQxCaLTSSCEQvgaCvMdax2g44a3rN4jjmIsXHmM6nSPEnDiOiOMIT0geVlZWuHPnDh4HBtqtFtZ7puMZtjBUlaGZRAhC8iilpLine truncated
"text/plain": [
"<Figure size 1000x1000 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"image = cv2.imread(SOURCE_IMAGE_PATH)\n",
"results = model.infer(image, confidence=0.003)\n",
"detections = sv.Detections.from_inference(results).with_nms(threshold=0.1)\n",
"\n",
"BOUNDING_BOX_ANNOTATOR = sv.BoundingBoxAnnotator(thickness=2)\n",
"LABEL_ANNOTATOR = sv.LabelAnnotator(text_thickness=2, text_scale=1, text_color=sv.Color.BLACK)\n",
"\n",
"labels = [\n",
" f\"{classes[class_id]} {confidence:0.3f}\"\n",
" for class_id, confidence\n",
" in zip(detections.class_id, detections.confidence)\n",
"]\n",
"\n",
"annotated_image = image.copy()\n",
"annotated_image = BOUNDING_BOX_ANNOTATOR.annotate(annotated_image, detections)\n",
"annotated_image = LABEL_ANNOTATOR.annotate(annotated_image, detections)\n",
"sv.plot_image(annotated_image, (10, 10))\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "CwI09wuYCztj"
},
"source": [
"## Saving Detections "
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "TVAulRgE-idz"
},
"source": [
"Now, at the end of the day would you like to see the final results and show to your supervisor all the metrics, but for that you need to save each of the prediction and after that you can create reports with the data."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "OX4l0ofl_Pe4"
},
"source": [
"We can use [`sv.CSVSink`](https://supervision.roboflow.com/develop/detection/tools/save_detections/) to save predictions. CSVSink allow to pass custom data alongside the detection fields, providing flexibility for logging various types of information.\n"
]
},
{
"cell_type": "code",
"execution_count": 69,
"metadata": {},
"outputs": [],
"source": [
"csv_sink = sv.CSVSink('detections.csv')\n",
"csv_sink.open()\n",
"\n",
"image = cv2.imread(SOURCE_IMAGE_PATH)\n",
"results = model.infer(image, confidence=0.003)\n",
"detections = sv.Detections.from_inference(results).with_nms(threshold=0.1)\n",
"\n",
"BOUNDING_BOX_ANNOTATOR = sv.BoundingBoxAnnotator(thickness=2)\n",
"LABEL_ANNOTATOR = sv.LabelAnnotator(text_thickness=2, text_scale=1, text_color=sv.Color.BLACK)\n",
"\n",
"labels = [\n",
" f\"{classes[class_id]} {confidence:0.3f}\"\n",
" for class_id, confidence\n",
" in zip(detections.class_id, detections.confidence)\n",
"]\n"
]
},
{
"cell_type": "code",
"execution_count": 70,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 472
},
"id": "XzE7wjwE_bOR",
"outputId": "5df62911-a001-46a4-a16c-8cdab7608e2e"
},
"outputs": [],
"source": [
"annotated_image = image.copy()\n",
"annotated_image = BOUNDING_BOX_ANNOTATOR.annotate(annotated_image, detections)\n",
"annotated_image = LABEL_ANNOTATOR.annotate(annotated_image, detections)\n",
"csv_sink.append(detections, custom_data={'name_campaign': \"hat and backpack\"})\n",
"\n",
"csv_sink.close()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Display the results"
]
},
{
"cell_type": "code",
"execution_count": 71,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>x_min</th>\n",
" <th>y_min</th>\n",
" <th>x_max</th>\n",
" <th>y_max</th>\n",
" <th>class_id</th>\n",
" <th>confidence</th>\n",
" <th>tracker_id</th>\n",
" <th>class_name</th>\n",
" <th>name_campaign</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1259.824402</td>\n",
" <td>556.843323</td>\n",
" <td>1397.988586</td>\n",
" <td>880.115173</td>\n",
" <td>0</td>\n",
" <td>0.922177</td>\n",
" <td>NaN</td>\n",
" <td>person</td>\n",
" <td>hat and backpack</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>1907.605164</td>\n",
" <td>1374.541077</td>\n",
" <td>2123.481262</td>\n",
" <td>1511.999939</td>\n",
" <td>0</td>\n",
" <td>0.920088</td>\n",
" <td>NaN</td>\n",
" <td>person</td>\n",
" <td>hat and backpack</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>185.341125</td>\n",
" <td>1263.053284</td>\n",
" <td>414.481201</td>\n",
" <td>1511.509705</td>\n",
" <td>0</td>\n",
" <td>0.917237</td>\n",
" <td>NaN</td>\n",
" <td>person</td>\n",
" <td>hat and backpack</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>1758.057983</td>\n",
" <td>890.935486</td>\n",
" <td>1977.167114</td>\n",
" <td>1305.461975</td>\n",
" <td>0</td>\n",
" <td>0.914720</td>\n",
" <td>NaN</td>\n",
" <td>person</td>\n",
" <td>hat and backpack</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>2120.903442</td>\n",
" <td>775.296661</td>\n",
" <td>2363.229370</td>\n",
" <td>1198.338348</td>\n",
" <td>0</td>\n",
" <td>0.913808</td>\n",
" <td>NaN</td>\n",
" <td>person</td>\n",
" <td>hat and backpack</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>145</th>\n",
" <td>415.074677</td>\n",
" <td>164.863037</td>\n",
" <td>436.987091</td>\n",
" <td>237.999908</td>\n",
" <td>0</td>\n",
" <td>0.011514</td>\n",
" <td>NaN</td>\n",
" <td>person</td>\n",
" <td>hat and backpack</td>\n",
" </tr>\n",
" <tr>\n",
" <th>146</th>\n",
" <td>543.731293</td>\n",
" <td>764.712311</td>\n",
" <td>611.070221</td>\n",
" <td>820.007904</td>\n",
" <td>4</td>\n",
" <td>0.010440</td>\n",
" <td>NaN</td>\n",
" <td>hats</td>\n",
" <td>hat and backpack</td>\n",
" </tr>\n",
" <tr>\n",
" <th>147</th>\n",
" <td>945.790405</td>\n",
" <td>124.706638</td>\n",
" <td>977.625732</td>\n",
" <td>162.100552</td>\n",
" <td>3</td>\n",
" <td>0.010306</td>\n",
" <td>NaN</td>\n",
" <td>persons with hats</td>\n",
" <td>hat and backpack</td>\n",
" </tr>\n",
" <tr>\n",
" <th>148</th>\n",
" <td>1532.029236</td>\n",
" <td>999.259613</td>\n",
" <td>1661.712952</td>\n",
" <td>1252.837067</td>\n",
" <td>2</td>\n",
" <td>0.010227</td>\n",
" <td>NaN</td>\n",
" <td>persons with backpack</td>\n",
" <td>hat and backpack</td>\n",
" </tr>\n",
" <tr>\n",
" <th>149</th>\n",
" <td>859.790588</td>\n",
" <td>245.192230</td>\n",
" <td>890.864807</td>\n",
" <td>295.042755</td>\n",
" <td>0</td>\n",
" <td>0.010188</td>\n",
" <td>NaN</td>\n",
" <td>person</td>\n",
" <td>hat and backpack</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>150 rows \u00d7 9 columns</p>\n",
"</div>"
],
"text/plain": [
" x_min y_min x_max y_max class_id confidence \\\n",
"0 1259.824402 556.843323 1397.988586 880.115173 0 0.922177 \n",
"1 1907.605164 1374.541077 2123.481262 1511.999939 0 0.920088 \n",
"2 185.341125 1263.053284 414.481201 1511.509705 0 0.917237 \n",
"3 1758.057983 890.935486 1977.167114 1305.461975 0 0.914720 \n",
"4 2120.903442 775.296661 2363.229370 1198.338348 0 0.913808 \n",
".. ... ... ... ... ... ... \n",
"145 415.074677 164.863037 436.987091 237.999908 0 0.011514 \n",
"146 543.731293 764.712311 611.070221 820.007904 4 0.010440 \n",
"147 945.790405 124.706638 977.625732 162.100552 3 0.010306 \n",
"148 1532.029236 999.259613 1661.712952 1252.837067 2 0.010227 \n",
"149 859.790588 245.192230 890.864807 295.042755 0 0.010188 \n",
"\n",
" tracker_id class_name name_campaign \n",
"0 NaN person hat and backpack \n",
"1 NaN person hat and backpack \n",
"2 NaN person hat and backpack \n",
"3 NaN person hat and backpack \n",
"4 NaN person hat and backpack \n",
".. ... ... ... \n",
"145 NaN person hat and backpack \n",
"146 NaN hats hat and backpack \n",
"147 NaN persons with hats hat and backpack \n",
"148 NaN persons with backpack hat and backpack \n",
"149 NaN person hat and backpack \n",
"\n",
"[150 rows x 9 columns]"
]
},
"execution_count": 71,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import pandas as pd\n",
"df = pd.read_csv('detections.csv')\n",
"df"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "7SjPoFnLC9aI"
},
"source": [
"## Final Result\n",
"Imagine taking it a step further as the marketing director of a premier retail conglomerate, aiming to expand your insights across the entire mall. You're not just analyzing static images anymore; you're delving into the dynamic world of video analysis. With YOLO-World, you can now process continuous video streams, capturing the ebb and flow of visitor behaviors and preferences in real-time. This leap from image to video processing opens up a new dimension of understanding, allowing you to observe trends, track movements, and gather nuanced insights into how visitors interact with different spaces within the mall. This powerful capability empowers you to refine the shopping experience, optimize store layouts, and develop targeted marketing campaigns that resonate with your audience on a whole new level."
]
},
{
"cell_type": "code",
"execution_count": 78,
"metadata": {
"id": "p0aooVpaCSH3"
},
"outputs": [],
"source": [
"TARGET_VIDEO_PATH = f\"{HOME}/test_demo_result.mp4\""
]
},
{
"cell_type": "code",
"execution_count": 79,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "A8TzekpEwtTO",
"outputId": "cf71b8e7-00af-4b7b-c912-9157ced6b6c4"
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
" 87%|\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u258b | 173/199 [00:16<00:02, 10.77it/s]\n"
]
}
],
"source": [
"frame_generator = sv.get_video_frames_generator(SOURCE_VIDEO_PATH)\n",
"video_info = sv.VideoInfo.from_video_path(SOURCE_VIDEO_PATH)\n",
"csv_sink = sv.CSVSink('detections.csv')\n",
"\n",
"\n",
"with sv.VideoSink(target_path=TARGET_VIDEO_PATH, video_info=video_info) as sink, csv_sink:\n",
" for frame in tqdm(frame_generator, total=video_info.total_frames):\n",
" results = model.infer(frame, confidence=0.002)\n",
" detections = sv.Detections.from_inference(results).with_nms(threshold=0.1)\n",
"\n",
" annotated_frame = frame.copy()\n",
" annotated_frame = BOUNDING_BOX_ANNOTATOR.annotate(annotated_frame, detections)\n",
" annotated_frame = LABEL_ANNOTATOR.annotate(annotated_frame, detections)\n",
" sink.write_frame(annotated_frame)\n",
" csv_sink.append(detections, custom_data={'name_campaign': \"hat and backpack\"})"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "vMp9mSj1DGJ9"
},
"source": [
" Keep in mind that the video preview below works only in the web version of the cookbooks and not in Google Colab.\n",
"\n",
"<video controls>\n",
" <source\n",
" src=\"https://storage.googleapis.com/tecla/results_yolo_world.mp4\"\n",
" type=\"video/mp4\"\n",
" >\n",
"</video>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": []
}
],
"metadata": {
"accelerator": "GPU",
"colab": {
"gpuType": "T4",
"provenance": []
},
"kernelspec": {
"display_name": "Python 3",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.10"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
+4
View File
@@ -54,6 +54,10 @@
<p class="card repo-card" data-name="Small Object Detection with SAHI"
data-labels="DETECTIONS,SAHI,SMALL,OBJECT,INFERENCE" data-version="v0.26.0" data-author="ediardo"></p>
</a>
<a href="/develop/notebooks/underestand-visitors-with-yolo-world">
<p class="card repo-card" data-name="Underestand visitors with YOLO-World"
data-labels="ANNOTATORS,DETECTION,INFERENCE" data-version="v0.19.0" data-author="AdonaiVera"></p>
</a>
</div>
</div>
</section>