docs(notebooks): 📝 json and csv sink cookbooks are added

Signed-off-by: Onuralp SEZER <thunderbirdtr@gmail.com>
This commit is contained in:
Onuralp SEZER 2024-03-05 05:23:15 +03:00
parent e86fc592c7
commit d309d74f37
No known key found for this signature in database
GPG Key ID: CF0835DFDF14CA38
3 changed files with 1417 additions and 0 deletions

View File

@ -0,0 +1,706 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "RFjrV07Spmm2"
},
"source": [
"# Serialise Detections to a CSV File\n",
"\n",
"---\n",
"\n",
"[![Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/roboflow/supervision/blob/develop/docs/notebooks/detections-to-jsonsink.ipynb)\n",
"\n",
"This cookbook introduce [sv.CSVSink](https://supervision.roboflow.com/develop/detection/tools/save_detections/#supervision.detection.tools.csv_sink.CSVSink) tool designed to write captured object detection data to file from video streams/file"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "aFQHoaDLp8R3"
},
"source": [
"Click the `Open in Colab` button to run the cookbook on Google Colab."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "hzMGlRKlel4p"
},
"outputs": [],
"source": [
"!pip install -q inference requests tqdm supervision==0.19.0rc5"
]
},
{
"cell_type": "code",
"execution_count": 39,
"metadata": {
"id": "6vRfXc_Je5Ee"
},
"outputs": [],
"source": [
"import supervision as sv\n",
"from supervision.assets import download_assets, VideoAssets\n",
"from inference import InferencePipeline\n",
"from inference.core.interfaces.camera.entities import VideoFrame\n",
"import numpy as np\n",
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "urRjZjh2f30v"
},
"outputs": [],
"source": [
"SOURCE_VIDEO_PATH = download_assets(VideoAssets.PEOPLE_WALKING)\n",
"CONFIDENCE_THRESHOLD = 0.3\n",
"IOU_THRESHOLD = 0.7"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "2YyE30JOS4Sf"
},
"source": [
"## Initialize ByteTrack"
]
},
{
"cell_type": "code",
"execution_count": 41,
"metadata": {
"id": "Jpw_TzAsm2oL"
},
"outputs": [],
"source": [
"byte_track = sv.ByteTrack()"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "IjYwj2vbTLBd"
},
"source": [
"## Initialize CSVSink and open sink"
]
},
{
"cell_type": "code",
"execution_count": 42,
"metadata": {
"id": "-yvv6N1uTKSl"
},
"outputs": [],
"source": [
"csv_sink = sv.CSVSink('detections.csv')\n",
"csv_sink.open()"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "d7IAyIYzmv_v"
},
"source": [
"## Process video to class to track detections and save detections to CSV file"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "-YvmJW5yud1G"
},
"source": [
"All the operations we plan to perform for each frame of our video - detection, tracking, annotation, and write to csv - are encapsulated in a function named `callback`."
]
},
{
"cell_type": "code",
"execution_count": 43,
"metadata": {
"id": "eRQiVkblapCk"
},
"outputs": [],
"source": [
"def callback(predictions: dict, frame: VideoFrame) -> np.ndarray:\n",
" detections = sv.Detections.from_inference(predictions)\n",
" detections = byte_track.update_with_detections(detections)\n",
" csv_sink.append(detections, custom_data={'frame_number': frame.frame_id})\n",
" print(f\"Processed Frame ID: {frame.frame_id}\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "3GRH_QdHgGiC"
},
"outputs": [],
"source": [
"#Aliases:\u00a0https://inference.roboflow.com/reference_pages/model_aliases/\n",
"\n",
"REGISTERED_ALIASES = {\n",
" \"yolov8n-640\": \"coco/3\",\n",
" \"yolov8n-1280\": \"coco/9\",\n",
" \"yolov8m-640\": \"coco/8\",\n",
" \"yolov8x-1280\": \"coco/10\",\n",
"}\n",
"\n",
"def resolve_roboflow_model_alias(model_id: str) -> str:\n",
" return REGISTERED_ALIASES.get(model_id, model_id)\n",
"\n",
"alias = \"yolov8n-640\"\n",
"model_name = resolve_roboflow_model_alias(alias)\n",
"\n",
"pipeline = InferencePipeline.init(\n",
" model_id=model_name,\n",
" video_reference=SOURCE_VIDEO_PATH,\n",
" on_prediction=callback,\n",
" iou_threshold=IOU_THRESHOLD,\n",
" confidence_threshold=CONFIDENCE_THRESHOLD,\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "bYpA9VxBsOvS"
},
"outputs": [],
"source": [
"pipeline.start()\n",
"pipeline.join()"
]
},
{
"cell_type": "code",
"execution_count": 46,
"metadata": {
"id": "RrewOF02AYta"
},
"outputs": [],
"source": [
"# Close CSVSink\n",
"csv_sink.close()"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "u7Akx7aUsh75"
},
"source": [
"## Visualizate results of detections CSV data with Pandas\n",
"\n",
"Let's take a look at our resulting data with by using Pandas.\n",
"\n",
"It will also be created in your current directory with the name detections.csv as well."
]
},
{
"cell_type": "code",
"execution_count": 47,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 424
},
"id": "Bu7AZ3QHiAqb",
"outputId": "22678389-7be4-4d5e-beb5-2543bdde0b52"
},
"outputs": [
{
"data": {
"application/vnd.google.colaboratory.intrinsic+json": {
"summary": "{\n \"name\": \"df\",\n \"rows\": 7922,\n \"fields\": [\n {\n \"column\": \"x_min\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 526.8407670284447,\n \"min\": -12.644972,\n \"max\": 1898.8293,\n \"num_unique_values\": 7920,\n \"samples\": [\n 1172.3636,\n 737.3481,\n 1380.5814\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"y_min\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 284.9445302145063,\n \"min\": -0.33771914,\n \"max\": 1028.6375,\n \"num_unique_values\": 7911,\n \"samples\": [\n 30.866436,\n 162.8454,\n 103.83498\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"x_max\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 527.2472667729564,\n \"min\": 23.571644,\n \"max\": 1933.4734,\n \"num_unique_values\": 7916,\n \"samples\": [\n 265.69644,\n 212.48213,\n 1423.4131\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"y_max\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 302.5701148946947,\n \"min\": 79.2273,\n \"max\": 1083.3434,\n \"num_unique_values\": 7879,\n \"samples\": [\n 1060.831,\n 390.86444,\n 805.1297\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"class_id\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 2,\n \"min\": 0,\n \"max\": 28,\n \"num_unique_values\": 4,\n \"samples\": [\n 14,\n 26,\n 0\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"confidence\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 0.12142000720578869,\n \"min\": 0.40000778,\n \"max\": 0.9084047,\n \"num_unique_values\": 7912,\n \"samples\": [\n 0.65444267,\n 0.65596485,\n 0.6623484\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"tracker_id\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 33,\n \"min\": 180,\n \"max\": 323,\n \"num_unique_values\": 86,\n \"samples\": [\n 309,\n 180,\n 300\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"frame_number\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 96,\n \"min\": 1,\n \"max\": 341,\n \"num_unique_values\": 341,\n \"samples\": [\n 323,\n 117,\n 114\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}",
"type": "dataframe",
"variable_name": "df"
},
"text/html": [
"\n",
" <div id=\"df-99d055bc-2dba-48a7-b8d3-8dcc44874fd1\" class=\"colab-df-container\">\n",
" <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>frame_number</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1460.000000</td>\n",
" <td>469.000000</td>\n",
" <td>1544.00000</td>\n",
" <td>641.00000</td>\n",
" <td>0</td>\n",
" <td>0.820143</td>\n",
" <td>180</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>1447.000000</td>\n",
" <td>320.000000</td>\n",
" <td>1516.00000</td>\n",
" <td>480.00000</td>\n",
" <td>0</td>\n",
" <td>0.791599</td>\n",
" <td>181</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>259.000000</td>\n",
" <td>435.000000</td>\n",
" <td>326.00000</td>\n",
" <td>610.00000</td>\n",
" <td>0</td>\n",
" <td>0.775027</td>\n",
" <td>182</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>1142.000000</td>\n",
" <td>950.000000</td>\n",
" <td>1245.00000</td>\n",
" <td>1080.00000</td>\n",
" <td>0</td>\n",
" <td>0.768063</td>\n",
" <td>183</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>665.000000</td>\n",
" <td>649.000000</td>\n",
" <td>744.00000</td>\n",
" <td>851.00000</td>\n",
" <td>0</td>\n",
" <td>0.762994</td>\n",
" <td>184</td>\n",
" <td>1</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",
" </tr>\n",
" <tr>\n",
" <th>7917</th>\n",
" <td>1854.766600</td>\n",
" <td>259.925570</td>\n",
" <td>1914.51900</td>\n",
" <td>442.58704</td>\n",
" <td>0</td>\n",
" <td>0.715024</td>\n",
" <td>322</td>\n",
" <td>341</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7918</th>\n",
" <td>391.996430</td>\n",
" <td>470.574280</td>\n",
" <td>460.88147</td>\n",
" <td>632.92770</td>\n",
" <td>0</td>\n",
" <td>0.506561</td>\n",
" <td>318</td>\n",
" <td>341</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7919</th>\n",
" <td>74.250565</td>\n",
" <td>700.197940</td>\n",
" <td>173.04185</td>\n",
" <td>893.15936</td>\n",
" <td>0</td>\n",
" <td>0.477815</td>\n",
" <td>306</td>\n",
" <td>341</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7920</th>\n",
" <td>1012.475770</td>\n",
" <td>170.831770</td>\n",
" <td>1058.31270</td>\n",
" <td>297.39798</td>\n",
" <td>0</td>\n",
" <td>0.565866</td>\n",
" <td>283</td>\n",
" <td>341</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7921</th>\n",
" <td>1012.560800</td>\n",
" <td>60.415718</td>\n",
" <td>1052.00890</td>\n",
" <td>175.33592</td>\n",
" <td>0</td>\n",
" <td>0.406130</td>\n",
" <td>320</td>\n",
" <td>341</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>7922 rows \u00d7 8 columns</p>\n",
"</div>\n",
" <div class=\"colab-df-buttons\">\n",
"\n",
" <div class=\"colab-df-container\">\n",
" <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-99d055bc-2dba-48a7-b8d3-8dcc44874fd1')\"\n",
" title=\"Convert this dataframe to an interactive table.\"\n",
" style=\"display:none;\">\n",
"\n",
" <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\n",
" <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n",
" </svg>\n",
" </button>\n",
"\n",
" <style>\n",
" .colab-df-container {\n",
" display:flex;\n",
" gap: 12px;\n",
" }\n",
"\n",
" .colab-df-convert {\n",
" background-color: #E8F0FE;\n",
" border: none;\n",
" border-radius: 50%;\n",
" cursor: pointer;\n",
" display: none;\n",
" fill: #1967D2;\n",
" height: 32px;\n",
" padding: 0 0 0 0;\n",
" width: 32px;\n",
" }\n",
"\n",
" .colab-df-convert:hover {\n",
" background-color: #E2EBFA;\n",
" box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
" fill: #174EA6;\n",
" }\n",
"\n",
" .colab-df-buttons div {\n",
" margin-bottom: 4px;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert {\n",
" background-color: #3B4455;\n",
" fill: #D2E3FC;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert:hover {\n",
" background-color: #434B5C;\n",
" box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
" filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
" fill: #FFFFFF;\n",
" }\n",
" </style>\n",
"\n",
" <script>\n",
" const buttonEl =\n",
" document.querySelector('#df-99d055bc-2dba-48a7-b8d3-8dcc44874fd1 button.colab-df-convert');\n",
" buttonEl.style.display =\n",
" google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
"\n",
" async function convertToInteractive(key) {\n",
" const element = document.querySelector('#df-99d055bc-2dba-48a7-b8d3-8dcc44874fd1');\n",
" const dataTable =\n",
" await google.colab.kernel.invokeFunction('convertToInteractive',\n",
" [key], {});\n",
" if (!dataTable) return;\n",
"\n",
" const docLinkHtml = 'Like what you see? Visit the ' +\n",
" '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
" + ' to learn more about interactive tables.';\n",
" element.innerHTML = '';\n",
" dataTable['output_type'] = 'display_data';\n",
" await google.colab.output.renderOutput(dataTable, element);\n",
" const docLink = document.createElement('div');\n",
" docLink.innerHTML = docLinkHtml;\n",
" element.appendChild(docLink);\n",
" }\n",
" </script>\n",
" </div>\n",
"\n",
"\n",
"<div id=\"df-7b9a62a0-d6a9-45ac-8c4f-0045260ee899\">\n",
" <button class=\"colab-df-quickchart\" onclick=\"quickchart('df-7b9a62a0-d6a9-45ac-8c4f-0045260ee899')\"\n",
" title=\"Suggest charts\"\n",
" style=\"display:none;\">\n",
"\n",
"<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
" width=\"24px\">\n",
" <g>\n",
" <path d=\"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z\"/>\n",
" </g>\n",
"</svg>\n",
" </button>\n",
"\n",
"<style>\n",
" .colab-df-quickchart {\n",
" --bg-color: #E8F0FE;\n",
" --fill-color: #1967D2;\n",
" --hover-bg-color: #E2EBFA;\n",
" --hover-fill-color: #174EA6;\n",
" --disabled-fill-color: #AAA;\n",
" --disabled-bg-color: #DDD;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-quickchart {\n",
" --bg-color: #3B4455;\n",
" --fill-color: #D2E3FC;\n",
" --hover-bg-color: #434B5C;\n",
" --hover-fill-color: #FFFFFF;\n",
" --disabled-bg-color: #3B4455;\n",
" --disabled-fill-color: #666;\n",
" }\n",
"\n",
" .colab-df-quickchart {\n",
" background-color: var(--bg-color);\n",
" border: none;\n",
" border-radius: 50%;\n",
" cursor: pointer;\n",
" display: none;\n",
" fill: var(--fill-color);\n",
" height: 32px;\n",
" padding: 0;\n",
" width: 32px;\n",
" }\n",
"\n",
" .colab-df-quickchart:hover {\n",
" background-color: var(--hover-bg-color);\n",
" box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
" fill: var(--button-hover-fill-color);\n",
" }\n",
"\n",
" .colab-df-quickchart-complete:disabled,\n",
" .colab-df-quickchart-complete:disabled:hover {\n",
" background-color: var(--disabled-bg-color);\n",
" fill: var(--disabled-fill-color);\n",
" box-shadow: none;\n",
" }\n",
"\n",
" .colab-df-spinner {\n",
" border: 2px solid var(--fill-color);\n",
" border-color: transparent;\n",
" border-bottom-color: var(--fill-color);\n",
" animation:\n",
" spin 1s steps(1) infinite;\n",
" }\n",
"\n",
" @keyframes spin {\n",
" 0% {\n",
" border-color: transparent;\n",
" border-bottom-color: var(--fill-color);\n",
" border-left-color: var(--fill-color);\n",
" }\n",
" 20% {\n",
" border-color: transparent;\n",
" border-left-color: var(--fill-color);\n",
" border-top-color: var(--fill-color);\n",
" }\n",
" 30% {\n",
" border-color: transparent;\n",
" border-left-color: var(--fill-color);\n",
" border-top-color: var(--fill-color);\n",
" border-right-color: var(--fill-color);\n",
" }\n",
" 40% {\n",
" border-color: transparent;\n",
" border-right-color: var(--fill-color);\n",
" border-top-color: var(--fill-color);\n",
" }\n",
" 60% {\n",
" border-color: transparent;\n",
" border-right-color: var(--fill-color);\n",
" }\n",
" 80% {\n",
" border-color: transparent;\n",
" border-right-color: var(--fill-color);\n",
" border-bottom-color: var(--fill-color);\n",
" }\n",
" 90% {\n",
" border-color: transparent;\n",
" border-bottom-color: var(--fill-color);\n",
" }\n",
" }\n",
"</style>\n",
"\n",
" <script>\n",
" async function quickchart(key) {\n",
" const quickchartButtonEl =\n",
" document.querySelector('#' + key + ' button');\n",
" quickchartButtonEl.disabled = true; // To prevent multiple clicks.\n",
" quickchartButtonEl.classList.add('colab-df-spinner');\n",
" try {\n",
" const charts = await google.colab.kernel.invokeFunction(\n",
" 'suggestCharts', [key], {});\n",
" } catch (error) {\n",
" console.error('Error during call to suggestCharts:', error);\n",
" }\n",
" quickchartButtonEl.classList.remove('colab-df-spinner');\n",
" quickchartButtonEl.classList.add('colab-df-quickchart-complete');\n",
" }\n",
" (() => {\n",
" let quickchartButtonEl =\n",
" document.querySelector('#df-7b9a62a0-d6a9-45ac-8c4f-0045260ee899 button');\n",
" quickchartButtonEl.style.display =\n",
" google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
" })();\n",
" </script>\n",
"</div>\n",
"\n",
" <div id=\"id_c686c1cf-a259-4607-96eb-65ba62bdeb6e\">\n",
" <style>\n",
" .colab-df-generate {\n",
" background-color: #E8F0FE;\n",
" border: none;\n",
" border-radius: 50%;\n",
" cursor: pointer;\n",
" display: none;\n",
" fill: #1967D2;\n",
" height: 32px;\n",
" padding: 0 0 0 0;\n",
" width: 32px;\n",
" }\n",
"\n",
" .colab-df-generate:hover {\n",
" background-color: #E2EBFA;\n",
" box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
" fill: #174EA6;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-generate {\n",
" background-color: #3B4455;\n",
" fill: #D2E3FC;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-generate:hover {\n",
" background-color: #434B5C;\n",
" box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
" filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
" fill: #FFFFFF;\n",
" }\n",
" </style>\n",
" <button class=\"colab-df-generate\" onclick=\"generateWithVariable('df')\"\n",
" title=\"Generate code using this dataframe.\"\n",
" style=\"display:none;\">\n",
"\n",
" <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
" width=\"24px\">\n",
" <path d=\"M7,19H8.4L18.45,9,17,7.55,7,17.6ZM5,21V16.75L18.45,3.32a2,2,0,0,1,2.83,0l1.4,1.43a1.91,1.91,0,0,1,.58,1.4,1.91,1.91,0,0,1-.58,1.4L9.25,21ZM18.45,9,17,7.55Zm-12,3A5.31,5.31,0,0,0,4.9,8.1,5.31,5.31,0,0,0,1,6.5,5.31,5.31,0,0,0,4.9,4.9,5.31,5.31,0,0,0,6.5,1,5.31,5.31,0,0,0,8.1,4.9,5.31,5.31,0,0,0,12,6.5,5.46,5.46,0,0,0,6.5,12Z\"/>\n",
" </svg>\n",
" </button>\n",
" <script>\n",
" (() => {\n",
" const buttonEl =\n",
" document.querySelector('#id_c686c1cf-a259-4607-96eb-65ba62bdeb6e button.colab-df-generate');\n",
" buttonEl.style.display =\n",
" google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
"\n",
" buttonEl.onclick = () => {\n",
" google.colab.notebook.generateWithVariable('df');\n",
" }\n",
" })();\n",
" </script>\n",
" </div>\n",
"\n",
" </div>\n",
" </div>\n"
],
"text/plain": [
" x_min y_min x_max y_max class_id confidence \\\n",
"0 1460.000000 469.000000 1544.00000 641.00000 0 0.820143 \n",
"1 1447.000000 320.000000 1516.00000 480.00000 0 0.791599 \n",
"2 259.000000 435.000000 326.00000 610.00000 0 0.775027 \n",
"3 1142.000000 950.000000 1245.00000 1080.00000 0 0.768063 \n",
"4 665.000000 649.000000 744.00000 851.00000 0 0.762994 \n",
"... ... ... ... ... ... ... \n",
"7917 1854.766600 259.925570 1914.51900 442.58704 0 0.715024 \n",
"7918 391.996430 470.574280 460.88147 632.92770 0 0.506561 \n",
"7919 74.250565 700.197940 173.04185 893.15936 0 0.477815 \n",
"7920 1012.475770 170.831770 1058.31270 297.39798 0 0.565866 \n",
"7921 1012.560800 60.415718 1052.00890 175.33592 0 0.406130 \n",
"\n",
" tracker_id frame_number \n",
"0 180 1 \n",
"1 181 1 \n",
"2 182 1 \n",
"3 183 1 \n",
"4 184 1 \n",
"... ... ... \n",
"7917 322 341 \n",
"7918 318 341 \n",
"7919 306 341 \n",
"7920 283 341 \n",
"7921 320 341 \n",
"\n",
"[7922 rows x 8 columns]"
]
},
"execution_count": 47,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df = pd.read_csv('detections.csv')\n",
"df"
]
}
],
"metadata": {
"colab": {
"provenance": []
},
"kernelspec": {
"display_name": "Python 3",
"name": "python3"
},
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

View File

@ -0,0 +1,708 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "RFjrV07Spmm2"
},
"source": [
"# Serialise Detections to a JSON File\n",
"\n",
"---\n",
"\n",
"[![Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/roboflow/supervision/blob/develop/docs/notebooks/detections-to-jsonsink.ipynb)\n",
"\n",
"This cookbook introduce [sv.JSONSink](https://supervision.roboflow.com/develop/detection/tools/save_detections/#supervision.detection.tools.json_sink.JSONSink) tool designed to write captured object detection data to file from video streams/file"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "aFQHoaDLp8R3"
},
"source": [
"Click the `Open in Colab` button to run the cookbook on Google Colab."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "hzMGlRKlel4p"
},
"outputs": [],
"source": [
"!pip install -q inference requests tqdm supervision==0.19.0rc6"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "6vRfXc_Je5Ee"
},
"outputs": [],
"source": [
"import supervision as sv\n",
"from supervision.assets import download_assets, VideoAssets\n",
"from inference import InferencePipeline\n",
"from inference.core.interfaces.camera.entities import VideoFrame\n",
"import numpy as np\n",
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "urRjZjh2f30v"
},
"outputs": [],
"source": [
"SOURCE_VIDEO_PATH = download_assets(VideoAssets.PEOPLE_WALKING)\n",
"CONFIDENCE_THRESHOLD = 0.3\n",
"IOU_THRESHOLD = 0.7"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "2YyE30JOS4Sf"
},
"source": [
"## Initialize ByteTrack"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {
"id": "Jpw_TzAsm2oL"
},
"outputs": [],
"source": [
"byte_track = sv.ByteTrack()"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "IjYwj2vbTLBd"
},
"source": [
"## Initialize JsonSink"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {
"id": "-yvv6N1uTKSl"
},
"outputs": [],
"source": [
"json_sink = sv.JSONSink('detections.json')\n",
"json_sink.open()"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "d7IAyIYzmv_v"
},
"source": [
"## Process video to class to track detections and save detections to json file"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "-YvmJW5yud1G"
},
"source": [
"All the operations we plan to perform for each frame of our video - detection, tracking, annotation, and write to json - are encapsulated in a function named `callback`."
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {
"id": "eRQiVkblapCk"
},
"outputs": [],
"source": [
"def callback(predictions: dict, frame: VideoFrame) -> np.ndarray:\n",
" detections = sv.Detections.from_inference(predictions)\n",
" detections = byte_track.update_with_detections(detections)\n",
" json_sink.append(detections, custom_data={'frame_number': frame.frame_id})\n",
" print(f\"Processed Frame ID: {frame.frame_id}\")"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {
"id": "3GRH_QdHgGiC"
},
"outputs": [],
"source": [
"#Aliases:\u00a0https://inference.roboflow.com/reference_pages/model_aliases/\n",
"\n",
"REGISTERED_ALIASES = {\n",
" \"yolov8n-640\": \"coco/3\",\n",
" \"yolov8n-1280\": \"coco/9\",\n",
" \"yolov8m-640\": \"coco/8\",\n",
" \"yolov8x-1280\": \"coco/10\",\n",
"}\n",
"\n",
"def resolve_roboflow_model_alias(model_id: str) -> str:\n",
" return REGISTERED_ALIASES.get(model_id, model_id)\n",
"\n",
"alias = \"yolov8n-640\"\n",
"model_name = resolve_roboflow_model_alias(alias)\n",
"\n",
"pipeline = InferencePipeline.init(\n",
" model_id=model_name,\n",
" video_reference=SOURCE_VIDEO_PATH,\n",
" on_prediction=callback,\n",
" iou_threshold=IOU_THRESHOLD,\n",
" confidence_threshold=CONFIDENCE_THRESHOLD,\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "bYpA9VxBsOvS"
},
"outputs": [],
"source": [
"pipeline.start()\n",
"pipeline.join()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "KXbZt-FNVnrS"
},
"outputs": [],
"source": [
"# Close JSONSink\n",
"json_sink.write_and_close()"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "u7Akx7aUsh75"
},
"source": [
"## Visualizate results of detections json data with Pandas\n",
"\n",
"Let's take a look at our resulting data with by using Pandas.\n",
"\n",
"It will also be created in your current directory with the name detections.json as well."
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 424
},
"id": "Bu7AZ3QHiAqb",
"outputId": "f6dab963-6ac2-4055-b79b-893c100301e7"
},
"outputs": [
{
"data": {
"application/vnd.google.colaboratory.intrinsic+json": {
"summary": "{\n \"name\": \"df\",\n \"rows\": 15829,\n \"fields\": [\n {\n \"column\": \"x_min\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 526.8739960472874,\n \"min\": -12.64497184753418,\n \"max\": 1898.829345703125,\n \"num_unique_values\": 11137,\n \"samples\": [\n 1591.7908935546875,\n 1337.453125,\n 701.3184814453125\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"y_min\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 284.9995089434701,\n \"min\": -0.33771914243698103,\n \"max\": 1028.637451171875,\n \"num_unique_values\": 9618,\n \"samples\": [\n 47.191009521484375,\n 23.033039093017578,\n 44.03553009033203\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"x_max\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 527.3199046060209,\n \"min\": 23.571643829345703,\n \"max\": 1933.473388671875,\n \"num_unique_values\": 11122,\n \"samples\": [\n 746.7100219726562,\n 1432.0216064453125,\n 1901.59716796875\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"y_max\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 302.62132272340716,\n \"min\": 79.22730255126953,\n \"max\": 1083.3433837890625,\n \"num_unique_values\": 9538,\n \"samples\": [\n 301.63653564453125,\n 1079.0537109375,\n 152.47158813476562\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"class_id\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 2,\n \"min\": 0,\n \"max\": 28,\n \"num_unique_values\": 4,\n \"samples\": [\n 14,\n 26,\n 0\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"confidence\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 0.1214256650003242,\n \"min\": 0.40000790357589705,\n \"max\": 0.90840470790863,\n \"num_unique_values\": 7916,\n \"samples\": [\n 0.59814703464508,\n 0.737265467643737,\n 0.576151430606842\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"tracker_id\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 75,\n \"min\": 1,\n \"max\": 279,\n \"num_unique_values\": 164,\n \"samples\": [\n 226,\n 185,\n 211\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"frame_number\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 96,\n \"min\": 1,\n \"max\": 341,\n \"num_unique_values\": 341,\n \"samples\": [\n 323,\n 117,\n 114\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}",
"type": "dataframe",
"variable_name": "df"
},
"text/html": [
"\n",
" <div id=\"df-5ea81b5e-9bc4-4c00-9694-67672a5d5bdb\" class=\"colab-df-container\">\n",
" <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>frame_number</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1460.000000</td>\n",
" <td>469.000000</td>\n",
" <td>1544.000000</td>\n",
" <td>641.000000</td>\n",
" <td>0</td>\n",
" <td>0.820143</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>1447.000000</td>\n",
" <td>320.000000</td>\n",
" <td>1516.000000</td>\n",
" <td>480.000000</td>\n",
" <td>0</td>\n",
" <td>0.791599</td>\n",
" <td>2</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>259.000000</td>\n",
" <td>435.000000</td>\n",
" <td>326.000000</td>\n",
" <td>610.000000</td>\n",
" <td>0</td>\n",
" <td>0.775027</td>\n",
" <td>3</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>1142.000000</td>\n",
" <td>950.000000</td>\n",
" <td>1245.000000</td>\n",
" <td>1080.000000</td>\n",
" <td>0</td>\n",
" <td>0.768064</td>\n",
" <td>4</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>665.000000</td>\n",
" <td>649.000000</td>\n",
" <td>744.000000</td>\n",
" <td>851.000000</td>\n",
" <td>0</td>\n",
" <td>0.762994</td>\n",
" <td>5</td>\n",
" <td>1</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",
" </tr>\n",
" <tr>\n",
" <th>15824</th>\n",
" <td>1854.766602</td>\n",
" <td>259.925568</td>\n",
" <td>1914.519043</td>\n",
" <td>442.587036</td>\n",
" <td>0</td>\n",
" <td>0.715025</td>\n",
" <td>278</td>\n",
" <td>341</td>\n",
" </tr>\n",
" <tr>\n",
" <th>15825</th>\n",
" <td>391.996429</td>\n",
" <td>470.574280</td>\n",
" <td>460.881470</td>\n",
" <td>632.927673</td>\n",
" <td>0</td>\n",
" <td>0.506562</td>\n",
" <td>274</td>\n",
" <td>341</td>\n",
" </tr>\n",
" <tr>\n",
" <th>15826</th>\n",
" <td>74.250565</td>\n",
" <td>700.197937</td>\n",
" <td>173.041855</td>\n",
" <td>893.159363</td>\n",
" <td>0</td>\n",
" <td>0.477815</td>\n",
" <td>262</td>\n",
" <td>341</td>\n",
" </tr>\n",
" <tr>\n",
" <th>15827</th>\n",
" <td>1012.475769</td>\n",
" <td>170.831772</td>\n",
" <td>1058.312744</td>\n",
" <td>297.397980</td>\n",
" <td>0</td>\n",
" <td>0.565866</td>\n",
" <td>239</td>\n",
" <td>341</td>\n",
" </tr>\n",
" <tr>\n",
" <th>15828</th>\n",
" <td>1012.560791</td>\n",
" <td>60.415718</td>\n",
" <td>1052.008911</td>\n",
" <td>175.335922</td>\n",
" <td>0</td>\n",
" <td>0.406129</td>\n",
" <td>276</td>\n",
" <td>341</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>15829 rows \u00d7 8 columns</p>\n",
"</div>\n",
" <div class=\"colab-df-buttons\">\n",
"\n",
" <div class=\"colab-df-container\">\n",
" <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-5ea81b5e-9bc4-4c00-9694-67672a5d5bdb')\"\n",
" title=\"Convert this dataframe to an interactive table.\"\n",
" style=\"display:none;\">\n",
"\n",
" <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\n",
" <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n",
" </svg>\n",
" </button>\n",
"\n",
" <style>\n",
" .colab-df-container {\n",
" display:flex;\n",
" gap: 12px;\n",
" }\n",
"\n",
" .colab-df-convert {\n",
" background-color: #E8F0FE;\n",
" border: none;\n",
" border-radius: 50%;\n",
" cursor: pointer;\n",
" display: none;\n",
" fill: #1967D2;\n",
" height: 32px;\n",
" padding: 0 0 0 0;\n",
" width: 32px;\n",
" }\n",
"\n",
" .colab-df-convert:hover {\n",
" background-color: #E2EBFA;\n",
" box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
" fill: #174EA6;\n",
" }\n",
"\n",
" .colab-df-buttons div {\n",
" margin-bottom: 4px;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert {\n",
" background-color: #3B4455;\n",
" fill: #D2E3FC;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert:hover {\n",
" background-color: #434B5C;\n",
" box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
" filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
" fill: #FFFFFF;\n",
" }\n",
" </style>\n",
"\n",
" <script>\n",
" const buttonEl =\n",
" document.querySelector('#df-5ea81b5e-9bc4-4c00-9694-67672a5d5bdb button.colab-df-convert');\n",
" buttonEl.style.display =\n",
" google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
"\n",
" async function convertToInteractive(key) {\n",
" const element = document.querySelector('#df-5ea81b5e-9bc4-4c00-9694-67672a5d5bdb');\n",
" const dataTable =\n",
" await google.colab.kernel.invokeFunction('convertToInteractive',\n",
" [key], {});\n",
" if (!dataTable) return;\n",
"\n",
" const docLinkHtml = 'Like what you see? Visit the ' +\n",
" '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
" + ' to learn more about interactive tables.';\n",
" element.innerHTML = '';\n",
" dataTable['output_type'] = 'display_data';\n",
" await google.colab.output.renderOutput(dataTable, element);\n",
" const docLink = document.createElement('div');\n",
" docLink.innerHTML = docLinkHtml;\n",
" element.appendChild(docLink);\n",
" }\n",
" </script>\n",
" </div>\n",
"\n",
"\n",
"<div id=\"df-78d2c252-82f9-4a1a-8fb9-de6d207bdec2\">\n",
" <button class=\"colab-df-quickchart\" onclick=\"quickchart('df-78d2c252-82f9-4a1a-8fb9-de6d207bdec2')\"\n",
" title=\"Suggest charts\"\n",
" style=\"display:none;\">\n",
"\n",
"<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
" width=\"24px\">\n",
" <g>\n",
" <path d=\"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z\"/>\n",
" </g>\n",
"</svg>\n",
" </button>\n",
"\n",
"<style>\n",
" .colab-df-quickchart {\n",
" --bg-color: #E8F0FE;\n",
" --fill-color: #1967D2;\n",
" --hover-bg-color: #E2EBFA;\n",
" --hover-fill-color: #174EA6;\n",
" --disabled-fill-color: #AAA;\n",
" --disabled-bg-color: #DDD;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-quickchart {\n",
" --bg-color: #3B4455;\n",
" --fill-color: #D2E3FC;\n",
" --hover-bg-color: #434B5C;\n",
" --hover-fill-color: #FFFFFF;\n",
" --disabled-bg-color: #3B4455;\n",
" --disabled-fill-color: #666;\n",
" }\n",
"\n",
" .colab-df-quickchart {\n",
" background-color: var(--bg-color);\n",
" border: none;\n",
" border-radius: 50%;\n",
" cursor: pointer;\n",
" display: none;\n",
" fill: var(--fill-color);\n",
" height: 32px;\n",
" padding: 0;\n",
" width: 32px;\n",
" }\n",
"\n",
" .colab-df-quickchart:hover {\n",
" background-color: var(--hover-bg-color);\n",
" box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
" fill: var(--button-hover-fill-color);\n",
" }\n",
"\n",
" .colab-df-quickchart-complete:disabled,\n",
" .colab-df-quickchart-complete:disabled:hover {\n",
" background-color: var(--disabled-bg-color);\n",
" fill: var(--disabled-fill-color);\n",
" box-shadow: none;\n",
" }\n",
"\n",
" .colab-df-spinner {\n",
" border: 2px solid var(--fill-color);\n",
" border-color: transparent;\n",
" border-bottom-color: var(--fill-color);\n",
" animation:\n",
" spin 1s steps(1) infinite;\n",
" }\n",
"\n",
" @keyframes spin {\n",
" 0% {\n",
" border-color: transparent;\n",
" border-bottom-color: var(--fill-color);\n",
" border-left-color: var(--fill-color);\n",
" }\n",
" 20% {\n",
" border-color: transparent;\n",
" border-left-color: var(--fill-color);\n",
" border-top-color: var(--fill-color);\n",
" }\n",
" 30% {\n",
" border-color: transparent;\n",
" border-left-color: var(--fill-color);\n",
" border-top-color: var(--fill-color);\n",
" border-right-color: var(--fill-color);\n",
" }\n",
" 40% {\n",
" border-color: transparent;\n",
" border-right-color: var(--fill-color);\n",
" border-top-color: var(--fill-color);\n",
" }\n",
" 60% {\n",
" border-color: transparent;\n",
" border-right-color: var(--fill-color);\n",
" }\n",
" 80% {\n",
" border-color: transparent;\n",
" border-right-color: var(--fill-color);\n",
" border-bottom-color: var(--fill-color);\n",
" }\n",
" 90% {\n",
" border-color: transparent;\n",
" border-bottom-color: var(--fill-color);\n",
" }\n",
" }\n",
"</style>\n",
"\n",
" <script>\n",
" async function quickchart(key) {\n",
" const quickchartButtonEl =\n",
" document.querySelector('#' + key + ' button');\n",
" quickchartButtonEl.disabled = true; // To prevent multiple clicks.\n",
" quickchartButtonEl.classList.add('colab-df-spinner');\n",
" try {\n",
" const charts = await google.colab.kernel.invokeFunction(\n",
" 'suggestCharts', [key], {});\n",
" } catch (error) {\n",
" console.error('Error during call to suggestCharts:', error);\n",
" }\n",
" quickchartButtonEl.classList.remove('colab-df-spinner');\n",
" quickchartButtonEl.classList.add('colab-df-quickchart-complete');\n",
" }\n",
" (() => {\n",
" let quickchartButtonEl =\n",
" document.querySelector('#df-78d2c252-82f9-4a1a-8fb9-de6d207bdec2 button');\n",
" quickchartButtonEl.style.display =\n",
" google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
" })();\n",
" </script>\n",
"</div>\n",
"\n",
" <div id=\"id_2459ce93-06af-4ff7-93a6-0af6715837a2\">\n",
" <style>\n",
" .colab-df-generate {\n",
" background-color: #E8F0FE;\n",
" border: none;\n",
" border-radius: 50%;\n",
" cursor: pointer;\n",
" display: none;\n",
" fill: #1967D2;\n",
" height: 32px;\n",
" padding: 0 0 0 0;\n",
" width: 32px;\n",
" }\n",
"\n",
" .colab-df-generate:hover {\n",
" background-color: #E2EBFA;\n",
" box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
" fill: #174EA6;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-generate {\n",
" background-color: #3B4455;\n",
" fill: #D2E3FC;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-generate:hover {\n",
" background-color: #434B5C;\n",
" box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
" filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
" fill: #FFFFFF;\n",
" }\n",
" </style>\n",
" <button class=\"colab-df-generate\" onclick=\"generateWithVariable('df')\"\n",
" title=\"Generate code using this dataframe.\"\n",
" style=\"display:none;\">\n",
"\n",
" <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
" width=\"24px\">\n",
" <path d=\"M7,19H8.4L18.45,9,17,7.55,7,17.6ZM5,21V16.75L18.45,3.32a2,2,0,0,1,2.83,0l1.4,1.43a1.91,1.91,0,0,1,.58,1.4,1.91,1.91,0,0,1-.58,1.4L9.25,21ZM18.45,9,17,7.55Zm-12,3A5.31,5.31,0,0,0,4.9,8.1,5.31,5.31,0,0,0,1,6.5,5.31,5.31,0,0,0,4.9,4.9,5.31,5.31,0,0,0,6.5,1,5.31,5.31,0,0,0,8.1,4.9,5.31,5.31,0,0,0,12,6.5,5.46,5.46,0,0,0,6.5,12Z\"/>\n",
" </svg>\n",
" </button>\n",
" <script>\n",
" (() => {\n",
" const buttonEl =\n",
" document.querySelector('#id_2459ce93-06af-4ff7-93a6-0af6715837a2 button.colab-df-generate');\n",
" buttonEl.style.display =\n",
" google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
"\n",
" buttonEl.onclick = () => {\n",
" google.colab.notebook.generateWithVariable('df');\n",
" }\n",
" })();\n",
" </script>\n",
" </div>\n",
"\n",
" </div>\n",
" </div>\n"
],
"text/plain": [
" x_min y_min x_max y_max class_id \\\n",
"0 1460.000000 469.000000 1544.000000 641.000000 0 \n",
"1 1447.000000 320.000000 1516.000000 480.000000 0 \n",
"2 259.000000 435.000000 326.000000 610.000000 0 \n",
"3 1142.000000 950.000000 1245.000000 1080.000000 0 \n",
"4 665.000000 649.000000 744.000000 851.000000 0 \n",
"... ... ... ... ... ... \n",
"15824 1854.766602 259.925568 1914.519043 442.587036 0 \n",
"15825 391.996429 470.574280 460.881470 632.927673 0 \n",
"15826 74.250565 700.197937 173.041855 893.159363 0 \n",
"15827 1012.475769 170.831772 1058.312744 297.397980 0 \n",
"15828 1012.560791 60.415718 1052.008911 175.335922 0 \n",
"\n",
" confidence tracker_id frame_number \n",
"0 0.820143 1 1 \n",
"1 0.791599 2 1 \n",
"2 0.775027 3 1 \n",
"3 0.768064 4 1 \n",
"4 0.762994 5 1 \n",
"... ... ... ... \n",
"15824 0.715025 278 341 \n",
"15825 0.506562 274 341 \n",
"15826 0.477815 262 341 \n",
"15827 0.565866 239 341 \n",
"15828 0.406129 276 341 \n",
"\n",
"[15829 rows x 8 columns]"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df = pd.read_json('detections.json')\n",
"df"
]
}
],
"metadata": {
"accelerator": "GPU",
"colab": {
"gpuType": "T4",
"provenance": []
},
"kernelspec": {
"display_name": "Python 3",
"name": "python3"
},
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

View File

@ -18,6 +18,9 @@
<p class="card repo-card" data-url="/develop/notebooks/annotate-video-with-detections" data-name="Annotate Video with Detections" data-labels="INFERENCE,YOLOV8" data-version="v0.18.0" data-author="nickherrig"></p>
<p class="card repo-card" data-url="/develop/notebooks/object-tracking" data-name="Object Tracking" data-labels="TRACKING, ANNOTATOR" data-version="v0.18.0" data-author="nickherrig"></p>
<p class="card repo-card" data-url="/develop/notebooks/evaluating-alignment-of-text-to-image-diffusion-models" data-name="Evaluating Alignment of Text-to-image Diffusion Models" data-labels="ANNOTATORS,YOLO WORLD" data-version="v0.19.0rc5" data-author="iamhatesz"></p>
<p class="card repo-card" data-url="/develop/notebooks/serialise-detections-to-csv" data-name="Serialise Detections to a CSV File" data-labels="DETECTIONS,CSV SINK,INFERENCE" data-version="v0.19.0rc5" data-author="onuralpszr"></p>
<p class="card repo-card" data-url="/develop/notebooks/serialise-detections-to-json" data-name="Serialise Detections to a JSON File" data-labels="DETECTIONS,JSON SINK,INFERENCE" data-version="v0.19.0rc6" data-author="onuralpszr"></p>
</div>
</div>
</section>