2023-04-05 15:15:50 +00:00
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"# Visualise embeddings of the JDE model\n",
"\n",
"This notebook embeds images from the training data using the JDE model. It then collects all embeddings and projects them using different techniques (e.g. UMAP, PCA). These projections are plotted; try to hover the plot to see the source detection.\n",
"\n",
"In a second step these images are drawn onto a canvas using the projected points."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import glob\n",
"import pickle\n",
"from typing import TypedDict\n",
"from tqdm.auto import tqdm\n",
"\n",
"import os\n",
"import numpy as np\n",
"\n",
"import logging\n",
"import argparse\n",
"logger = logging.getLogger(__name__)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
2023-04-13 11:12:50 +00:00
"2023-04-06 16:09:23 [WARNING]: Matplotlib created a temporary config/cache directory at /tmp/matplotlib-i8r80tk_ because the default path (/.config/matplotlib) is not a writable directory; it is highly recommended to set the MPLCONFIGDIR environment variable to a writable directory, in particular to speed up the import of Matplotlib and to better support multiprocessing.\n",
"2023-04-06 16:09:23 [INFO]: generated new fontManager\n"
2023-04-05 15:15:50 +00:00
]
}
],
"source": [
"from track import eval_seq\n",
"\n",
"from utils.parse_config import parse_model_cfg\n",
"from utils.utils import mkdir_if_missing\n",
"import utils.datasets as datasets\n",
"from utils.log import logger as trmlog # we need to override this...\n",
"\n",
"\n",
"trmlog.setLevel(logging.INFO)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"import umap # should provide better results than t-SNE\n",
"\n"
]
},
{
"cell_type": "code",
2023-04-13 11:12:50 +00:00
"execution_count": 4,
2023-04-05 15:15:50 +00:00
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
2023-04-13 11:12:50 +00:00
"<style>\n",
" .bk-notebook-logo {\n",
" display: block;\n",
" width: 20px;\n",
" height: 20px;\n",
" background-image: url(data:image/png;base64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fv/GtwwhzhxGVAprjbg0gCAEeIgwCZyTV2Z1REEW8O4py0wsjeloKoMr6iCY6dP92H6Vw/oTyICIthibxjm/DfN9lVz8IqtqKYLUXfoKVMVQVVJOElGjrnnUt9T9wbgp8AyYKaGlqingHZU/uG2NTZSVqwHQTWkx9hxjkpWDaCg6Ckj5qebgBVbT3V3NNXMSiWSDdGV3hrtzla7J+duwPOToIg42ChPQOQjspnSlp1V+Gjdged7+8UN5CRAV7a5EdFNwCjEaBR27b3W890TE7g24NAP/mMDXRWrGoFPQI9ls/MWO2dWFAar/xcOIImbbpA3zgAAAABJRU5ErkJggg==);\n",
" }\n",
" </style>\n",
" <div>\n",
" <a href=\"https://bokeh.org\" target=\"_blank\" class=\"bk-notebook-logo\"></a>\n",
" <span id=\"p1001\">Loading BokehJS ...</span>\n",
2023-04-05 15:15:50 +00:00
" </div>\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
2023-04-13 11:12:50 +00:00
"application/javascript": "(function(root) {\n function now() {\n return new Date();\n }\n\n const force = true;\n\n if (typeof root._bokeh_onload_callbacks === \"undefined\" || force === true) {\n root._bokeh_onload_callbacks = [];\n root._bokeh_is_loading = undefined;\n }\n\nconst JS_MIME_TYPE = 'application/javascript';\n const HTML_MIME_TYPE = 'text/html';\n const EXEC_MIME_TYPE = 'application/vnd.bokehjs_exec.v0+json';\n const CLASS_NAME = 'output_bokeh rendered_html';\n\n /**\n * Render data to the DOM node\n */\n function render(props, node) {\n const script = document.createElement(\"script\");\n node.appendChild(script);\n }\n\n /**\n * Handle when an output is cleared or removed\n */\n function handleClearOutput(event, handle) {\n const cell = handle.cell;\n\n const id = cell.output_area._bokeh_element_id;\n const server_id = cell.output_area._bokeh_server_id;\n // Clean up Bokeh references\n if (id != null && id in Bokeh.index) {\n Bokeh.index[id].model.document.clear();\n delete Bokeh.index[id];\n }\n\n if (server_id !== undefined) {\n // Clean up Bokeh references\n const cmd_clean = \"from bokeh.io.state import curstate; print(curstate().uuid_to_server['\" + server_id + \"'].get_sessions()[0].document.roots[0]._id)\";\n cell.notebook.kernel.execute(cmd_clean, {\n iopub: {\n output: function(msg) {\n const id = msg.content.text.trim();\n if (id in Bokeh.index) {\n Bokeh.index[id].model.document.clear();\n delete Bokeh.index[id];\n }\n }\n }\n });\n // Destroy server and session\n const cmd_destroy = \"import bokeh.io.notebook as ion; ion.destroy_server('\" + server_id + \"')\";\n cell.notebook.kernel.execute(cmd_destroy);\n }\n }\n\n /**\n * Handle when a new output is added\n */\n function handleAddOutput(event, handle) {\n const output_area = handle.output_area;\n const output = handle.output;\n\n // limit handleAddOutput to display_data with EXEC_MIME_TYPE content only\n if ((output.output_type != \"display_data\") || (!Object.prototype.hasOwnProperty.call(output.data, EXEC_MIME_TYPE))) {\n return\n }\n\n const toinsert = output_area.element.find(\".\" + CLASS_NAME.split(' ')[0]);\n\n if (output.metadata[EXEC_MIME_TYPE][\"id\"] !== undefined) {\n toinsert[toinsert.length - 1].firstChild.textContent = output.data[JS_MIME_TYPE];\n // store reference to embed id on output_area\n output_area._bokeh_element_id = output.metadata[EXEC_MIME_TYPE][\"id\"];\n }\n if (output.metadata[EXEC_MIME_TYPE][\"server_id\"] !== undefined) {\n const bk_div = document.createElement(\"div\");\n bk_div.innerHTML = output.data[HTML_MIME_TYPE];\n const script_attrs = bk_div.children[0].attributes;\n for (let i = 0; i < script_attrs.length; i++) {\n toinsert[toinsert.length - 1].firstChild.setAttribute(script_attrs[i].name, script_attrs[i].value);\n toinsert[toinsert.length - 1].firstChild.textContent = bk_div.children[0].textContent\n }\n // store reference to server id on output_area\n output_area._bokeh_server_id = output.metadata[EXEC_MIME_TYPE][\"server_id\"];\n }\n }\n\n function register_renderer(events, OutputArea) {\n\n function append_mime(data, metadata, element) {\n // create a DOM node to render to\n const toinsert = this.create_output_subarea(\n metadata,\n CLASS_NAME,\n EXEC_MIME_TYPE\n );\n this.keyboard_manager.register_events(toinsert);\n // Render to node\n const props = {data: data, metadata: metadata[EXEC_MIME_TYPE]};\n render(props, toinsert[toinsert.length - 1]);\n element.append(toinsert);\n return toinsert\n }\n\n /* Handle when an output is cleared or removed */\n events.on('clear_output.CodeCell', handleClearOutput);\n events.on('delete.Cell', handleClearOutput);\n\n /* Handle when a new output is added */\n events.o
2023-04-05 15:15:50 +00:00
"application/vnd.bokehjs_load.v0+json": ""
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# import matplotlib.pyplot as plt\n",
"\n",
"from bokeh.io import curdoc, output_notebook\n",
"from bokeh.models import ColumnDataSource\n",
"from bokeh.layouts import column, row, gridplot\n",
"from bokeh.plotting import figure, show\n",
"from bokeh.models import (PanTool,\n",
" ResetTool,\n",
" HoverTool, WheelZoomTool, BoxZoomTool)\n",
"\n",
"# load bokeh\n",
"output_notebook()\n"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"# p1 = figure(plot_width=250, plot_height=250)\n",
"# r1 = p1.circle([1,2,3],[3,2,1], size=20)\n",
"\n",
"# t = show(p1, notebook_handle=True)"
]
},
{
"cell_type": "code",
2023-04-13 11:12:50 +00:00
"execution_count": 26,
2023-04-05 15:15:50 +00:00
"metadata": {},
"outputs": [],
"source": [
"img_seqs = [\n",
" \"MOT16/test/MOT16-01/\",\n",
" \"MOT16/test/MOT16-03/\",\n",
" \"MOT16/test/MOT16-06/\",\n",
" \"MOT16/test/MOT16-07/\",\n",
" \"MOT16/test/MOT16-08/\",\n",
" \"MOT16/test/MOT16-12/\",\n",
" \"MOT16/test/MOT16-14/\",\n",
2023-04-13 11:12:50 +00:00
" \"MOT16/train/MOT16-02/\",\n",
" \"MOT16/train/MOT16-04/\",\n",
" \"MOT16/train/MOT16-05/\",\n",
" \"MOT16/train/MOT16-09/\",\n",
" \"MOT16/train/MOT16-10/\",\n",
" \"MOT16/train/MOT16-11/\",\n",
" \"MOT16/train/MOT16-13/\",\n",
" \"CaltechPedestrians/data/images/\",\n",
" \"PRW/images/\",\n",
" \"CUHK-SYSU/images/\",\n",
" \"CityScapes/leftImg8bit/test/*\",\n",
" \"CityScapes/leftImg8bit/train/*\",\n",
" \"CityScapes/leftImg8bit/val/*\",\n",
2023-04-05 15:15:50 +00:00
"]"
]
},
{
"cell_type": "code",
2023-04-13 11:12:50 +00:00
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 12,
2023-04-05 15:15:50 +00:00
"metadata": {},
"outputs": [],
"source": [
"# Data types\n",
"\n",
"from dataclasses import dataclass\n",
"from pathlib import Path\n",
"\n",
"\n",
"Tlwh = list[float, float, float, float] #top left width height\n",
"Embedding = np.array\n",
"TrackerFrameEmbedding = list[Tlwh, Embedding]\n",
"\n",
"@dataclass\n",
"class FrameEmbedding():\n",
" pcl_filename: str\n",
" tlwh: Tlwh\n",
" embedding: Embedding\n",
" umap: Embedding = None\n",
" pca: Embedding = None\n",
" \n",
" @classmethod\n",
" def from_tracker_embedding(cls, pcl_filename: str | Path, tfe: TrackerFrameEmbedding):\n",
" return cls(pcl_filename=pcl_filename, tlwh=tfe[0], embedding=tfe[1])\n",
" \n",
" @property\n",
" def img_filename(self):\n",
" return self.pcl_filename[:-4] + '.jpg'\n",
" \n"
]
},
{
"cell_type": "code",
2023-04-13 11:12:50 +00:00
"execution_count": 13,
2023-04-05 15:15:50 +00:00
"metadata": {},
"outputs": [],
"source": [
"# load options; quick'n'dirty copy from track.py (as the Namespace object is used in the multitracker)\n",
"\n",
"parser = argparse.ArgumentParser(prog='visualise_embeddings.py')\n",
"parser.add_argument('--cfg', type=str, default='cfg/yolov3_1088x608.cfg', help='cfg file path')\n",
"parser.add_argument('--weights', type=str, default='jde.1088x608.uncertainty.pt', help='path to weights file')\n",
"parser.add_argument('--iou-thres', type=float, default=0.5, help='iou threshold required to qualify as detected')\n",
"parser.add_argument('--conf-thres', type=float, default=0.5, help='object confidence threshold')\n",
"parser.add_argument('--nms-thres', type=float, default=0.4, help='iou threshold for non-maximum suppression')\n",
"parser.add_argument('--min-box-area', type=float, default=200, help='filter out tiny boxes')\n",
"parser.add_argument('--track-buffer', type=int, default=30, help='tracking buffer')\n",
"parser.add_argument('--dataset-dir', type=str, default=\"/datasets\", help='Path to directory with datasets')\n",
"parser.add_argument('--experiment-name', type=str, default=\"embedding_test\", help=\"name to prefix output directory with\")\n",
"parser.add_argument('--output-dir', type=str, default=\"./OUT\", help=\"directory for results\")\n",
" \n",
"# we're running in notebook, so default to empty\n",
"opt = parser.parse_args([])\n",
"\n",
"logger.setLevel(logging.INFO)\n",
"result_path = os.path.join(opt.output_dir, opt.experiment_name)\n",
"mkdir_if_missing(result_path)\n",
"data_type = 'mot'\n",
"\n",
"# Read config\n",
"cfg_dict = parse_model_cfg(opt.cfg)\n",
"# set img_size in opt, so it is passed on to JDETracker\n",
"opt.img_size = [int(cfg_dict[0]['width']), int(cfg_dict[0]['height'])]\n"
]
},
{
"cell_type": "code",
2023-04-13 11:12:50 +00:00
"execution_count": 24,
2023-04-05 15:15:50 +00:00
"metadata": {},
"outputs": [],
"source": [
2023-04-13 11:12:50 +00:00
"from ipywidgets import __version__\n",
"assert __version__ == \"7.7.2\"\n",
2023-04-05 15:15:50 +00:00
"\n",
2023-04-13 11:12:50 +00:00
"# import time\n",
"# for i in tqdm(range(10)):\n",
"# time.sleep(1)"
2023-04-05 15:15:50 +00:00
]
},
{
"cell_type": "code",
2023-04-13 11:12:50 +00:00
"execution_count": 25,
2023-04-05 15:15:50 +00:00
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
2023-04-13 11:12:50 +00:00
"model_id": "fbe592aeef6b4187b74d98c022740535",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
" 0%| | 0/6 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"2023-04-07 05:16:49 [INFO]: start seq: /datasets/CaltechPedestrians/data/images/\n",
"2023-04-07 05:16:50 [WARNING]: No ini file for /datasets/CaltechPedestrians/data/images/. Note, these are only for MOT\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "2ad8b161df134bcdb43dece558128264",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
" 0%| | 0/258509 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"2023-04-07 05:40:47 [INFO]: start seq: /datasets/PRW/images/\n",
"2023-04-07 05:40:47 [WARNING]: No ini file for /datasets/PRW/images/. Note, these are only for MOT\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "daa9b25785fa4db08ff34b87bc0a76dc",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
" 0%| | 0/11816 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"2023-04-07 05:43:57 [INFO]: start seq: /datasets/CUHK-SYSU/images/\n",
"2023-04-07 05:43:57 [WARNING]: No ini file for /datasets/CUHK-SYSU/images/. Note, these are only for MOT\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "bdf681fe5f24436194064c107d752025",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
" 0%| | 0/18184 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"2023-04-07 05:45:52 [INFO]: start seq: /datasets/CityScapes/leftImg8bit/test/berlin\n",
"2023-04-07 05:45:52 [WARNING]: No ini file for /datasets/CityScapes/leftImg8bit/test/berlin. Note, these are only for MOT\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "1f0a89ce0c024e58b782ff8222751d89",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
" 0%| | 0/544 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"2023-04-07 05:46:19 [INFO]: start seq: /datasets/CityScapes/leftImg8bit/test/bonn\n",
"2023-04-07 05:46:19 [WARNING]: No ini file for /datasets/CityScapes/leftImg8bit/test/bonn. Note, these are only for MOT\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "7e3b736b25154557873321c6037fd42c",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
" 0%| | 0/46 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"2023-04-07 05:46:22 [INFO]: start seq: /datasets/CityScapes/leftImg8bit/test/bielefeld\n",
"2023-04-07 05:46:22 [WARNING]: No ini file for /datasets/CityScapes/leftImg8bit/test/bielefeld. Note, these are only for MOT\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "f1a6765e87c642aba8ad3422b71d2051",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
" 0%| | 0/181 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"2023-04-07 05:46:32 [INFO]: start seq: /datasets/CityScapes/leftImg8bit/test/munich\n",
"2023-04-07 05:46:32 [WARNING]: No ini file for /datasets/CityScapes/leftImg8bit/test/munich. Note, these are only for MOT\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "484b26c576ae45a684581647dc68b717",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
" 0%| | 0/398 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"2023-04-07 05:46:51 [INFO]: start seq: /datasets/CityScapes/leftImg8bit/test/leverkusen\n",
"2023-04-07 05:46:51 [WARNING]: No ini file for /datasets/CityScapes/leftImg8bit/test/leverkusen. Note, these are only for MOT\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "666255a38fd446b9b193eabab7777388",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
" 0%| | 0/58 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"2023-04-07 05:46:55 [INFO]: start seq: /datasets/CityScapes/leftImg8bit/test/mainz\n",
"2023-04-07 05:46:55 [WARNING]: No ini file for /datasets/CityScapes/leftImg8bit/test/mainz. Note, these are only for MOT\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "62407ccf716b4d36a4c845b9a107bf03",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
" 0%| | 0/298 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"2023-04-07 05:47:10 [INFO]: start seq: /datasets/CityScapes/leftImg8bit/train/strasbourg\n",
"2023-04-07 05:47:10 [WARNING]: No ini file for /datasets/CityScapes/leftImg8bit/train/strasbourg. Note, these are only for MOT\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "7fcda6850c6f42858e1d2b26b7ff772e",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
" 0%| | 0/365 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"2023-04-07 05:47:29 [INFO]: start seq: /datasets/CityScapes/leftImg8bit/train/weimar\n",
"2023-04-07 05:47:29 [WARNING]: No ini file for /datasets/CityScapes/leftImg8bit/train/weimar. Note, these are only for MOT\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "bad486408c104e7a86d6868cd6fbeb53",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
" 0%| | 0/142 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"2023-04-07 05:47:37 [INFO]: start seq: /datasets/CityScapes/leftImg8bit/train/ulm\n",
"2023-04-07 05:47:37 [WARNING]: No ini file for /datasets/CityScapes/leftImg8bit/train/ulm. Note, these are only for MOT\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "6f4c845acf2c41eca0f1e5918ae01457",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
" 0%| | 0/95 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"2023-04-07 05:47:42 [INFO]: start seq: /datasets/CityScapes/leftImg8bit/train/dusseldorf\n",
"2023-04-07 05:47:42 [WARNING]: No ini file for /datasets/CityScapes/leftImg8bit/train/dusseldorf. Note, these are only for MOT\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "fdac09a4f7304b1db167954c7e51f698",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
" 0%| | 0/221 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"2023-04-07 05:47:53 [INFO]: start seq: /datasets/CityScapes/leftImg8bit/train/aachen\n",
"2023-04-07 05:47:53 [WARNING]: No ini file for /datasets/CityScapes/leftImg8bit/train/aachen. Note, these are only for MOT\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "99b5a4a0f1e24e6e80f142443fcbd839",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
" 0%| | 0/174 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"2023-04-07 05:48:02 [INFO]: start seq: /datasets/CityScapes/leftImg8bit/train/tubingen\n",
"2023-04-07 05:48:02 [WARNING]: No ini file for /datasets/CityScapes/leftImg8bit/train/tubingen. Note, these are only for MOT\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "8aba1d10bf3a47618644919cbe029bec",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
" 0%| | 0/144 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"2023-04-07 05:48:09 [INFO]: start seq: /datasets/CityScapes/leftImg8bit/train/bochum\n",
"2023-04-07 05:48:09 [WARNING]: No ini file for /datasets/CityScapes/leftImg8bit/train/bochum. Note, these are only for MOT\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "b2bf5daf1b094d3b8d995a638645924f",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
" 0%| | 0/96 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"2023-04-07 05:48:15 [INFO]: start seq: /datasets/CityScapes/leftImg8bit/train/monchengladbach\n",
"2023-04-07 05:48:15 [WARNING]: No ini file for /datasets/CityScapes/leftImg8bit/train/monchengladbach. Note, these are only for MOT\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "bca3e39498ae4dc9bdff844a12f355ce",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
" 0%| | 0/94 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"2023-04-07 05:48:20 [INFO]: start seq: /datasets/CityScapes/leftImg8bit/train/hanover\n",
"2023-04-07 05:48:20 [WARNING]: No ini file for /datasets/CityScapes/leftImg8bit/train/hanover. Note, these are only for MOT\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "52f03f81edc2416d9cab65326cb1cebb",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
" 0%| | 0/196 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"2023-04-07 05:48:30 [INFO]: start seq: /datasets/CityScapes/leftImg8bit/train/stuttgart\n",
"2023-04-07 05:48:30 [WARNING]: No ini file for /datasets/CityScapes/leftImg8bit/train/stuttgart. Note, these are only for MOT\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "d72f4d8a85a54dfa9f9290a45e385190",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
" 0%| | 0/196 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"2023-04-07 05:48:41 [INFO]: start seq: /datasets/CityScapes/leftImg8bit/train/bremen\n",
"2023-04-07 05:48:41 [WARNING]: No ini file for /datasets/CityScapes/leftImg8bit/train/bremen. Note, these are only for MOT\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "c158a646fd434227afe6cc5af933fc1f",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
" 0%| | 0/316 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"2023-04-07 05:48:56 [INFO]: start seq: /datasets/CityScapes/leftImg8bit/train/jena\n",
"2023-04-07 05:48:56 [WARNING]: No ini file for /datasets/CityScapes/leftImg8bit/train/jena. Note, these are only for MOT\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "5ff2e1d7e60442fb9279e04468317f08",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
" 0%| | 0/119 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"2023-04-07 05:49:03 [INFO]: start seq: /datasets/CityScapes/leftImg8bit/train/hamburg\n",
"2023-04-07 05:49:03 [WARNING]: No ini file for /datasets/CityScapes/leftImg8bit/train/hamburg. Note, these are only for MOT\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "8e5c7738a9b2469ea205b1b6b416b24e",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
" 0%| | 0/248 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"2023-04-07 05:49:16 [INFO]: start seq: /datasets/CityScapes/leftImg8bit/train/darmstadt\n",
"2023-04-07 05:49:16 [WARNING]: No ini file for /datasets/CityScapes/leftImg8bit/train/darmstadt. Note, these are only for MOT\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "7fb9bb5ddede44b7bafb7929f2616956",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
" 0%| | 0/85 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"2023-04-07 05:49:21 [INFO]: start seq: /datasets/CityScapes/leftImg8bit/train/zurich\n",
"2023-04-07 05:49:21 [WARNING]: No ini file for /datasets/CityScapes/leftImg8bit/train/zurich. Note, these are only for MOT\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "8124ae02e5354d9187ddbd6a2c4b2ff4",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
" 0%| | 0/122 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"2023-04-07 05:49:27 [INFO]: start seq: /datasets/CityScapes/leftImg8bit/train/krefeld\n",
"2023-04-07 05:49:27 [WARNING]: No ini file for /datasets/CityScapes/leftImg8bit/train/krefeld. Note, these are only for MOT\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "8904845c79034924945aab1e1aa47ccf",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
" 0%| | 0/99 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"2023-04-07 05:49:33 [INFO]: start seq: /datasets/CityScapes/leftImg8bit/train/cologne\n",
"2023-04-07 05:49:33 [WARNING]: No ini file for /datasets/CityScapes/leftImg8bit/train/cologne. Note, these are only for MOT\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "20b4b8a31c9346849db48cea23ac5dbf",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
" 0%| | 0/154 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"2023-04-07 05:49:41 [INFO]: start seq: /datasets/CityScapes/leftImg8bit/train/erfurt\n",
"2023-04-07 05:49:41 [WARNING]: No ini file for /datasets/CityScapes/leftImg8bit/train/erfurt. Note, these are only for MOT\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "a99491fa239d460eadb8d6b6335d5044",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
" 0%| | 0/109 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"2023-04-07 05:49:47 [INFO]: start seq: /datasets/CityScapes/leftImg8bit/val/frankfurt\n",
"2023-04-07 05:49:47 [WARNING]: No ini file for /datasets/CityScapes/leftImg8bit/val/frankfurt. Note, these are only for MOT\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "6d285bf5027e40d6848f82ffab9e1a0d",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
" 0%| | 0/267 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"2023-04-07 05:50:00 [INFO]: start seq: /datasets/CityScapes/leftImg8bit/val/munster\n",
"2023-04-07 05:50:00 [WARNING]: No ini file for /datasets/CityScapes/leftImg8bit/val/munster. Note, these are only for MOT\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "9ba428c85a8f4f40ac6838d1e6698625",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
" 0%| | 0/174 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"2023-04-07 05:50:09 [INFO]: start seq: /datasets/CityScapes/leftImg8bit/val/lindau\n",
"2023-04-07 05:50:09 [WARNING]: No ini file for /datasets/CityScapes/leftImg8bit/val/lindau. Note, these are only for MOT\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "3c9dac13400840ee8cba32e9f2a7b326",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
" 0%| | 0/59 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
" # run tracking on all img_seqs\n",
"\n",
"for pattern in tqdm(img_seqs):\n",
" for seq in glob.glob(os.path.join(opt.dataset_dir, pattern)):\n",
" logger.info('start seq: {}'.format(seq))\n",
" if os.path.exists(os.path.join(seq, 'img1')):\n",
" seq_dir = os.path.join(seq, 'img1')\n",
" else:\n",
" seq_dir = seq\n",
" dataloader = datasets.LoadImages(seq_dir, opt.img_size)\n",
" # result_filename = os.path.join(result_path, '{}.txt'.format(seq))\n",
" try:\n",
" meta_info = open(os.path.join(seq, 'seqinfo.ini')).read() \n",
" frame_rate = int(meta_info[meta_info.find('frameRate')+10:meta_info.find('\\nseqLength')])\n",
" except FileNotFoundError as e:\n",
" logger.warning(f\"No ini file for {seq}. Note, these are only for MOT\")\n",
" frame_rate = 25\n",
" p = str(Path(seq).relative_to(opt.dataset_dir))\n",
" nf, ta, tc = eval_seq(opt, dataloader, data_type, None,\n",
" save_dir=os.path.join(result_path, p), save_figures=True, save_img=False, show_image=False, frame_rate=frame_rate)\n"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {},
"outputs": [],
"source": [
"result_path = os.path.join(opt.output_dir, opt.experiment_name)\n",
"transformed_embedding_pcl = os.path.join(result_path, 'transformed_embeddings.pcl')\n",
"orig_embedding_pcl = os.path.join(result_path, 'orig_embeddings.pcl')"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Load all pre-calculated embeddings from disk and project them. Save this collection of embeddings and their projections for easier working at a later stages."
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "bb5214947bff4a508dab53f59b3269e6",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
" 0%| | 0/20 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "9b811d86c5bd47d09c8246cc061bbb27",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"0it [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "14cb0741d2994b5ababb27d3425ac380",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"0it [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "e14e32488c3c4a1dbd145305527989bb",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"0it [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "7b052d84f1c4456b8c98821e5d781f15",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"0it [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "149203cb330d410db136976afc7db87d",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"0it [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "a095931ec0d24b18afc56b6890da3ccf",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"0it [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "f24d30a079f845ffa96414444f88479e",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"0it [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "402b6117fa0349199e790b5e65ce1af1",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"0it [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "2c543e3319a04234b00b1b0fe9476c62",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"0it [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "6bc2611061e1440cb925c80b7669b99e",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"0it [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "4d46e63c14244eb3b3ad53da008e963e",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"0it [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "e2e32c0911d847229fc16b343602aa51",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"0it [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "0adccb52bd5740ce8cc229704237aee7",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"0it [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "a7e2f4ee2b62423f842194cbf8648758",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"0it [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "29903e9a0b464cc2b3433ebc0ecebfdc",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"0it [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "3ca9208801e94db19c3f4de237bcdb53",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"0it [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "9e49b94b1a4d43d4a4a6e1ce85438218",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"0it [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "b56424e56f6d4056a23822530380be13",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"0it [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "65247fa441404c25a87bdcbae962c42e",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"0it [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "416b00ee819a4e8a895fbe44adb74698",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"0it [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "134df80696ce4da48ad573b6a997afe6",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"0it [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "366c5280c0a648d78078e5199a369456",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"0it [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "145e1cb273e645bc8b50ebc182e92406",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"0it [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "d38eb86b45ab42f38461ef986c9b77d7",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"0it [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "4f8d40650c0c48a8a29748f759d89f9c",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"0it [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "4e83bcfacd6b495ab74d9d6fe9e4caf1",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"0it [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "3713c29e36d749be8148e9797f5e1100",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"0it [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "0e5d545213774e3a8095c96ffb7e503c",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"0it [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "6f13d3016f904ab8a732a9f3ca3de89b",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"0it [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "1bfb0adf537546a6ab523d855520e476",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"0it [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "e064c93e40de48fb85e413c16f79165e",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"0it [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "e9a26107046e4ba7b7facd6e455e4397",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"0it [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "4990c6b5a14d4006b5f51c46ab8bcacb",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"0it [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "4d833f54ecde4792a443fb0b1b7fe3f8",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"0it [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "b2d9109c5987406fa9d2a4c58fae705f",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"0it [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "b5fa2e7c5cee4befb2466c472001576a",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"0it [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "f7447c0a0a0c448390f21c4b4c0c3b55",
2023-04-05 15:15:50 +00:00
"version_major": 2,
"version_minor": 0
},
"text/plain": [
2023-04-13 11:12:50 +00:00
"0it [00:00, ?it/s]"
2023-04-05 15:15:50 +00:00
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
2023-04-13 11:12:50 +00:00
"model_id": "85427dae328f4612af77a54828d31d73",
2023-04-05 15:15:50 +00:00
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"0it [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
2023-04-13 11:12:50 +00:00
"model_id": "6b9f043c1b0947569218000f0eb0a42e",
2023-04-05 15:15:50 +00:00
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"0it [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
2023-04-13 11:12:50 +00:00
"model_id": "81587afb2cbe42c591df0622b34cacfe",
2023-04-05 15:15:50 +00:00
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"0it [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
2023-04-13 11:12:50 +00:00
"model_id": "b74676e4f3e04ee4b92034d458f425b4",
2023-04-05 15:15:50 +00:00
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"0it [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
2023-04-13 11:12:50 +00:00
"model_id": "14faf83633e04fc9aba2f72edf4d8bed",
2023-04-05 15:15:50 +00:00
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"0it [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
2023-04-13 11:12:50 +00:00
"model_id": "1638f354911243fd9a798630b9844e07",
2023-04-05 15:15:50 +00:00
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"0it [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
2023-04-13 11:12:50 +00:00
"model_id": "f47e96fd925d4b51ad760e94266478e0",
2023-04-05 15:15:50 +00:00
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"0it [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
2023-04-13 11:12:50 +00:00
"2023-04-07 05:56:57 [INFO]: loaded 587540 embeddings\n",
"2023-04-07 05:56:57 [INFO]: saved all loaded embeddings embeddings\n",
"2023-04-07 05:57:06 [INFO]: transform using UMAP\n",
"OMP: Info #276: omp_set_nested routine deprecated, please use omp_set_max_active_levels instead.\n",
"2023-04-07 06:30:42 [INFO]: transform using PCA\n",
"2023-04-07 06:30:48 [INFO]: saved transformed embeddings\n"
2023-04-05 15:15:50 +00:00
]
}
],
"source": [
"from sklearn import decomposition\n",
"\n",
"frame_embeddings: list[FrameEmbedding] = []\n",
"\n",
2023-04-13 11:12:50 +00:00
"if os.path.exists(transformed_embedding_pcl):\n",
" with open(transformed_embedding_pcl, 'rb') as fp:\n",
2023-04-05 15:15:50 +00:00
" frame_embeddings = pickle.load(fp)\n",
" logger.info(f'loaded {len(frame_embeddings)} embeddings')\n",
"else:\n",
2023-04-13 11:12:50 +00:00
" if os.path.exists(orig_embedding_pcl):\n",
" with open(orig_embedding_pcl, 'rb') as fp:\n",
" frame_embeddings = pickle.load(fp)\n",
" logger.info(f'loaded {len(frame_embeddings)} embeddings')\n",
" else:\n",
" for pattern in tqdm(img_seqs):\n",
" for seq_path in glob.glob(os.path.join(result_path, pattern)):\n",
" for i, frame_path in tqdm(enumerate(glob.iglob(f\"{seq_path}/*-*.pcl\"))):\n",
" # if i%2 == 1:\n",
" # # TODO skip 50% for now\n",
" # continue\n",
" with open(frame_path, 'rb') as fp:\n",
" tracker_embedding = pickle.load(fp)\n",
" fe = FrameEmbedding.from_tracker_embedding(frame_path, tracker_embedding)\n",
" frame_embeddings.append(fe)\n",
"\n",
" logger.info(f'loaded {len(frame_embeddings)} embeddings')\n",
"\n",
" with open(orig_embedding_pcl, 'wb') as fp:\n",
" logger.info(f'saved all loaded embeddings embeddings')\n",
" pickle.dump(frame_embeddings, fp)\n",
2023-04-05 15:15:50 +00:00
"\n",
" \n",
" logger.info(f'transform using UMAP')\n",
" reducer = umap.UMAP(n_components=2)\n",
" umap_embeddings = reducer.fit_transform([e.embedding for e in frame_embeddings])\n",
" for i, e in enumerate(umap_embeddings):\n",
" frame_embeddings[i].umap = e\n",
" \n",
" logger.info(f'transform using PCA')\n",
" pca = decomposition.PCA(n_components=2)\n",
" pca_embeddings = pca.fit_transform([e.embedding for e in frame_embeddings])\n",
" for i, e in enumerate(pca_embeddings):\n",
" frame_embeddings[i].pca = e\n",
"\n",
2023-04-13 11:12:50 +00:00
" with open(transformed_embedding_pcl, 'wb') as fp:\n",
2023-04-05 15:15:50 +00:00
" logger.info(f'saved transformed embeddings')\n",
" pickle.dump(frame_embeddings, fp)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"\n"
]
},
{
"cell_type": "code",
2023-04-13 11:12:50 +00:00
"execution_count": 30,
2023-04-05 15:15:50 +00:00
"metadata": {},
"outputs": [],
"source": [
"\n",
"# print(embeddings)\n",
"umap_embeddings = np.array([e.umap for e in frame_embeddings])\n",
"pca_embeddings = np.array([e.pca for e in frame_embeddings])\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 64,
"metadata": {},
"outputs": [],
"source": [
"\n",
"import base64\n",
"import cv2\n",
"\n",
"\n",
"def b64_image_files(frame_embeddings: list[FrameEmbedding]):\n",
" urls = []\n",
" for i, fe in enumerate(frame_embeddings):\n",
" im = cv2.imread(fe.img_filename)\n",
" pic_width = int(im.shape[1] * .3)\n",
" pic_height = int(im.shape[0] * .3)\n",
" new_dimension = (pic_width, pic_height)\n",
" try:\n",
" im = cv2.resize(im, new_dimension)\n",
" _, byte_data = cv2.imencode('.png', im) \n",
" except Exception as e:\n",
" print(i, fe.img_filename, e)\n",
" \n",
" url = 'data:image/png;base64,' + base64.b64encode(byte_data).decode('utf-8')\n",
" urls.append(url)\n",
" return urls"
]
},
{
"cell_type": "code",
2023-04-13 11:12:50 +00:00
"execution_count": 31,
2023-04-05 15:15:50 +00:00
"metadata": {},
"outputs": [],
"source": [
" \n",
"# source = ColumnDataSource(data={'x': embeddings[:, 0], 'y': embeddings[:, 1], 'b64': b64_image_files(frame_embeddings), 'fn': [e.img_filename for e in frame_embeddings] })\n",
"source = ColumnDataSource(data={\n",
" 'x': umap_embeddings[:, 0], 'y': umap_embeddings[:, 1], \n",
" 'pca_x': pca_embeddings[:, 0], 'pca_y': pca_embeddings[:, 1],\n",
" 'fn': [e.img_filename for e in frame_embeddings]\n",
" })\n"
]
},
{
"cell_type": "code",
"execution_count": 85,
"metadata": {},
"outputs": [],
"source": [
"\n",
"\n",
"# thanks to https://github.com/jni/blob-explorer/blob/bd9fa676a2a23317e2ea84bdf48b19e71b9e75d4/picker.py#L24\n",
"# who uses base64 encoding, but in VScode we can just use the _path_ to the file\n",
"tooltip = \"\"\"\n",
" <img height=100 src='@fn'>\n",
" \"\"\"\n",
" \n",
"tools1 = [BoxZoomTool(), PanTool(), WheelZoomTool(), ResetTool(), HoverTool(tooltips=tooltip)]\n",
"tools2 = [BoxZoomTool(), PanTool(), WheelZoomTool(), ResetTool(), HoverTool(tooltips=tooltip)]\n"
]
},
{
"cell_type": "code",
"execution_count": 86,
"metadata": {},
"outputs": [],
"source": [
"\n",
"p_umap = figure(width=800, height=800, title='UMAP projection', \n",
" tools=tools1\n",
" )\n",
"r_umap = p_umap.circle(source=source, size=10, color=\"navy\", alpha=0.5)"
]
},
{
"cell_type": "code",
"execution_count": 87,
"metadata": {},
"outputs": [],
"source": [
"p_pca = figure(width=800, height=800, title='PCA projection', \n",
" tools=tools2\n",
" )\n",
"r_pca = p_pca.circle('pca_x', 'pca_y', source=source, size=10, color=\"red\", alpha=0.5)"
]
},
{
"cell_type": "code",
"execution_count": 83,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
" <div class=\"bk-root\" id=\"aadf5ca0-8b62-40e4-9063-92b32f7a3f1e\" data-root-id=\"3453\"></div>\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": "(function(root) {\n function embed_document(root) {\n const docs_json = {\"f0e85271-f463-45ad-a119-343d8d173388\":{\"defs\":[],\"roots\":{\"references\":[{\"attributes\":{\"children\":[{\"id\":\"3452\"},{\"id\":\"3450\"}]},\"id\":\"3453\",\"type\":\"Column\"},{\"attributes\":{\"below\":[{\"id\":\"3375\"}],\"center\":[{\"id\":\"3378\"},{\"id\":\"3382\"}],\"height\":800,\"left\":[{\"id\":\"3379\"}],\"renderers\":[{\"id\":\"3394\"}],\"title\":{\"id\":\"3365\"},\"toolbar\":{\"id\":\"3384\"},\"toolbar_location\":null,\"width\":800,\"x_range\":{\"id\":\"3367\"},\"x_scale\":{\"id\":\"3371\"},\"y_range\":{\"id\":\"3369\"},\"y_scale\":{\"id\":\"3373\"}},\"id\":\"3364\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"3408\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"3405\",\"type\":\"LinearScale\"},{\"attributes\":{\"toolbar\":{\"id\":\"3451\"},\"toolbar_location\":\"above\"},\"id\":\"3452\",\"type\":\"ToolbarBox\"},{\"attributes\":{},\"id\":\"3401\",\"type\":\"DataRange1d\"},{\"attributes\":{\"coordinates\":null,\"formatter\":{\"id\":\"3433\"},\"group\":null,\"major_label_policy\":{\"id\":\"3434\"},\"ticker\":{\"id\":\"3376\"}},\"id\":\"3375\",\"type\":\"LinearAxis\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.5},\"fill_color\":{\"value\":\"navy\"},\"hatch_alpha\":{\"value\":0.5},\"hatch_color\":{\"value\":\"navy\"},\"line_alpha\":{\"value\":0.5},\"line_color\":{\"value\":\"navy\"},\"size\":{\"value\":10}},\"id\":\"3391\",\"type\":\"Circle\"},{\"attributes\":{\"children\":[[{\"id\":\"3364\"},0,0],[{\"id\":\"3396\"},0,1]]},\"id\":\"3450\",\"type\":\"GridBox\"},{\"attributes\":{},\"id\":\"3376\",\"type\":\"BasicTicker\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.5},\"fill_color\":{\"value\":\"red\"},\"hatch_alpha\":{\"value\":0.5},\"hatch_color\":{\"value\":\"red\"},\"line_alpha\":{\"value\":0.5},\"line_color\":{\"value\":\"red\"},\"size\":{\"value\":10},\"x\":{\"field\":\"pca_x\"},\"y\":{\"field\":\"pca_y\"}},\"id\":\"3423\",\"type\":\"Circle\"},{\"attributes\":{\"coordinates\":null,\"data_source\":{\"id\":\"2363\"},\"glyph\":{\"id\":\"3391\"},\"group\":null,\"hover_glyph\":null,\"muted_glyph\":{\"id\":\"3393\"},\"nonselection_glyph\":{\"id\":\"3392\"},\"view\":{\"id\":\"3395\"}},\"id\":\"3394\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"3441\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"3369\",\"type\":\"DataRange1d\"},{\"attributes\":{\"source\":{\"id\":\"2363\"}},\"id\":\"3395\",\"type\":\"CDSView\"},{\"attributes\":{\"tools\":[{\"id\":\"3354\"},{\"id\":\"3355\"},{\"id\":\"3356\"},{\"id\":\"3357\"},{\"id\":\"3358\"}]},\"id\":\"3384\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"3442\",\"type\":\"AllLabels\"},{\"attributes\":{\"data\":{\"fn\":[\"./OUT/embedding_test/MOT16/test/MOT16-01/00340-5.jpg\",\"./OUT/embedding_test/MOT16/test/MOT16-01/00034-3.jpg\",\"./OUT/embedding_test/MOT16/test/MOT16-01/00170-1.jpg\",\"./OUT/embedding_test/MOT16/test/MOT16-01/00267-2.jpg\",\"./OUT/embedding_test/MOT16/test/MOT16-01/00267-4.jpg\",\"./OUT/embedding_test/MOT16/test/MOT16-01/00103-5.jpg\",\"./OUT/embedding_test/MOT16/test/MOT16-01/00368-4.jpg\",\"./OUT/embedding_test/MOT16/test/MOT16-01/00296-5.jpg\",\"./OUT/embedding_test/MOT16/test/MOT16-01/00335-7.jpg\",\"./OUT/embedding_test/MOT16/test/MOT16-01/00204-8.jpg\",\"./OUT/embedding_test/MOT16/test/MOT16-01/00229-10.jpg\",\"./OUT/embedding_test/MOT16/test/MOT16-01/00108-9.jpg\",\"./OUT/embedding_test/MOT16/test/MOT16-01/00331-10.jpg\",\"./OUT/embedding_test/MOT16/test/MOT16-01/00118-1.jpg\",\"./OUT/embedding_test/MOT16/test/MOT16-01/00268-2.jpg\",\"./OUT/embedding_test/MOT16/test/MOT16-01/00368-10.jpg\",\"./OUT/embedding_test/MOT16/test/MOT16-01/00109-8.jpg\",\"./OUT/embedding_test/MOT16/test/MOT16-01/00374-3.jpg\",\"./OUT/embedding_test/MOT16/test/MOT16-01/00236-1.jpg\",\"./OUT/embedding_test/MOT16/test/MOT16-01/00447-3.jpg\",\"./OUT/embedding_test/MOT16/test/MOT16-01/00169-9.jpg\",\"./OUT/embedding_test/MOT16/test/MOT16-01/00103-4.jpg\",\"./OUT/embedding_test/MOT16/test/MOT16-01/000
"application/vnd.bokehjs_exec.v0+json": ""
},
"metadata": {
"application/vnd.bokehjs_exec.v0+json": {
"id": "3453"
}
},
"output_type": "display_data"
}
],
"source": [
"handle = show(gridplot([[p_umap, p_pca]]), notebook_handle=True)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"# Stage 2 Generate a grid images out of the projections\n",
"\n",
"Now that there are individual points, we can perheaps better make sense of patterns if we see all points at once. As this is virtually impossible, we can try rendering a grid, with images on it. For each field on the grid, try to find the point closest to the center, and draw that image."
]
},
{
"cell_type": "code",
2023-04-13 11:12:50 +00:00
"execution_count": 32,
2023-04-05 15:15:50 +00:00
"metadata": {},
"outputs": [],
"source": [
"from scipy import spatial"
]
},
{
"cell_type": "code",
2023-04-13 11:12:50 +00:00
"execution_count": 48,
"metadata": {},
"outputs": [],
"source": [
"\n",
"class GridPosition(TypedDict):\n",
" pos: tuple[int,int]\n",
" distance: float\n",
" frame_embedding: FrameEmbedding"
]
},
{
"cell_type": "code",
"execution_count": 49,
"metadata": {},
"outputs": [],
"source": [
"import cv2\n",
2023-04-13 11:49:40 +00:00
"# resize and pad from https://stackoverflow.com/a/44724368 (alkasm)\n",
2023-04-13 11:12:50 +00:00
"def resizeAndPad(img, size, padColor=0):\n",
2023-04-13 11:49:40 +00:00
" \n",
2023-04-13 11:12:50 +00:00
" h, w = img.shape[:2]\n",
" sh, sw = size\n",
"\n",
" # interpolation method\n",
" if h > sh or w > sw: # shrinking image\n",
" interp = cv2.INTER_AREA\n",
" else: # stretching image\n",
" interp = cv2.INTER_CUBIC\n",
"\n",
" # aspect ratio of image\n",
" aspect = w/h # if on Python 2, you might need to cast as a float: float(w)/h\n",
"\n",
" # compute scaling and pad sizing\n",
" if aspect > 1: # horizontal image\n",
" new_w = sw\n",
" new_h = np.round(new_w/aspect).astype(int)\n",
" pad_vert = (sh-new_h)/2\n",
" pad_top, pad_bot = np.floor(pad_vert).astype(int), np.ceil(pad_vert).astype(int)\n",
" pad_left, pad_right = 0, 0\n",
" elif aspect < 1: # vertical image\n",
" new_h = sh\n",
" new_w = np.round(new_h*aspect).astype(int)\n",
" pad_horz = (sw-new_w)/2\n",
" pad_left, pad_right = np.floor(pad_horz).astype(int), np.ceil(pad_horz).astype(int)\n",
" pad_top, pad_bot = 0, 0\n",
" else: # square image\n",
" new_h, new_w = sh, sw\n",
" pad_left, pad_right, pad_top, pad_bot = 0, 0, 0, 0\n",
"\n",
" # set pad color\n",
" if len(img.shape) == 3 and not isinstance(padColor, (list, tuple, np.ndarray)): # color image but only one color provided\n",
" padColor = [padColor]*3\n",
"\n",
" # scale and pad\n",
" scaled_img = cv2.resize(img, (new_w, new_h), interpolation=interp)\n",
" scaled_img = cv2.copyMakeBorder(scaled_img, pad_top, pad_bot, pad_left, pad_right, borderType=cv2.BORDER_CONSTANT, value=padColor)\n",
"\n",
" return scaled_img"
]
},
{
"cell_type": "code",
2023-04-13 11:49:40 +00:00
"execution_count": 68,
2023-04-13 11:12:50 +00:00
"metadata": {},
"outputs": [],
"source": [
"def projection_to_grid(grid_items, points, frame_embeddings: list[FrameEmbedding]):\n",
" # create a KDTree for fast searching of nearest points\n",
" spatial_tree = spatial.KDTree(points)\n",
"\n",
" min_x = min(points[:,0])\n",
" max_x = max(points[:,0])\n",
" min_y = min(points[:,1])\n",
" max_y = max(points[:,1])\n",
"\n",
" #initialize empty\n",
" # grid = [None]*(grid_items * grid_items)\n",
" grid: list[GridPosition] = []\n",
"\n",
"\n",
" # find the points closest to the grid centroids\n",
" for ix in range(grid_items):\n",
" embedding_x = (ix+0.5) / grid_items * (max_x - min_x) + min_x\n",
"\n",
" for iy in range(grid_items):\n",
" embedding_y = (iy+0.5) / grid_items * (max_y - min_y) + min_y\n",
"\n",
" distance, index = spatial_tree.query([embedding_x, embedding_y])\n",
" # print(distance, frame_embeddings[index].img_filename)\n",
" grid_index = ix * grid_items + iy\n",
" gp = GridPosition(pos=(ix, iy), distance=distance, frame_embedding=frame_embeddings[index])\n",
" grid.append(gp)\n",
"\n",
"\n",
" print(f'{len(grid)} items. Sort')\n",
" grid.sort(key=lambda k: k['distance']) \n",
" \n",
" # remove duplicate closest points based on distance\n",
" drawn_embeddings = set()\n",
" items_to_draw: list[GridPosition] = []\n",
" for point in grid:\n",
" if point['frame_embedding'].img_filename not in drawn_embeddings:\n",
" drawn_embeddings.add(point['frame_embedding'].img_filename)\n",
" items_to_draw.append(point)\n",
"\n",
" return items_to_draw"
]
},
{
"cell_type": "code",
2023-04-13 11:49:40 +00:00
"execution_count": 87,
2023-04-13 11:12:50 +00:00
"metadata": {},
"outputs": [],
"source": [
2023-04-13 11:49:40 +00:00
"\n",
"bgcolors = [\n",
" ('MOT16', [255, 0, 0]),\n",
" ('CaltechPedestrians', [0, 255, 0]),\n",
" ('PRW', [0, 0, 255]),\n",
" ('CUHK-SYSU', [255, 255, 0]),\n",
" ('CityScapes', [0, 255, 255]),\n",
"]\n",
"\n",
"def draw_grid(grid_size, items_to_draw: list[GridPosition], colored=True):\n",
2023-04-13 11:12:50 +00:00
" grid_items = max([max(p['pos']) for p in items_to_draw])+1\n",
" canvas = np.zeros((grid_size * grid_items, grid_size*grid_items, 3), np.uint8)\n",
" for point in items_to_draw:\n",
2023-04-13 11:49:40 +00:00
" if colored:\n",
" try:\n",
" color_idx = [k[0] in point['frame_embedding'].img_filename for k in bgcolors].index(True)\n",
" color = bgcolors[color_idx][1]\n",
" except ValueError:\n",
" color = [0,0,0]\n",
" else:\n",
" color = [0,0,0]\n",
" \n",
2023-04-13 11:12:50 +00:00
" img = cv2.imread(point['frame_embedding'].img_filename)\n",
2023-04-13 11:49:40 +00:00
" img = resizeAndPad(img, (grid_size, grid_size), color)\n",
2023-04-13 11:12:50 +00:00
" iy = point['pos'][1]\n",
" ix = point['pos'][0]\n",
"\n",
" y = grid_size*iy\n",
" x = grid_size*ix\n",
" canvas[x:x+grid_size,y:y+grid_size] = img\n",
" return canvas"
]
},
{
"cell_type": "code",
2023-04-13 11:49:40 +00:00
"execution_count": 76,
2023-04-05 15:15:50 +00:00
"metadata": {},
"outputs": [],
"source": [
2023-04-13 11:12:50 +00:00
"from matplotlib import pyplot as plt\n",
"from PIL import Image\n",
"\n",
"def show_and_save(cv_img, fn):\n",
" # Convert for consumption by matplotlib or Pillow\n",
" image = cv2.cvtColor(cv_img, cv2.COLOR_BGR2RGB)\n",
"\n",
" # Converts from one colour space to the other. this is needed as RGB\n",
" # is not the default colour space for OpenCV\n",
" plt.imshow(image)\n",
" plt.show()\n",
" im = Image.fromarray(image)\n",
" # im = im.resize((1500,1500))\n",
" im.save(fn)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"PCA reduces dimensions in a linear fasion. Thus this should stay truer to the values as they are embedded."
2023-04-05 15:15:50 +00:00
]
},
{
"cell_type": "code",
2023-04-13 11:49:40 +00:00
"execution_count": 88,
2023-04-05 15:15:50 +00:00
"metadata": {},
"outputs": [
2023-04-13 11:12:50 +00:00
{
"name": "stdout",
"output_type": "stream",
"text": [
"22500 items. Sort\n"
]
},
2023-04-05 15:15:50 +00:00
{
"data": {
2023-04-13 11:12:50 +00:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAbIAAAGiCAYAAACCpUOHAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjcuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/b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cSZswCARsuFyQin1pDvXnzoO2g0BfhxaI+AIzTXg48XWFoS0MOW0cuN8fGzUwAA23awsi7R2VuuEUNmmSYs1ssWLgo7TdNxkS3IsfxRRNdcfQ10XbarVkR5V3IrsHieubXsZcctF+SzRFLqYpqmYW7xAgBg37YrM4eYloVoQoxmKC5Go9FoIJcTw1jIiUGr15sqIvMlYoXhNCXa2XXkcqDK9slxAEA0GoFh6NA0DZmMoCbTNNS242Dl4uIVzy+Tlu0rtToajUtbG3pHBpF+DamxOvLmk44h68grSvy7pITq9RayxUs9aK3ZRKkiXv3pXlG4iVhURUTPnpwFABTKedhM1QUJQMiX20rsidMSJfSmRBm6ros8DU8ycbmHnqJBdQHUHNmuJyDn7uoe/GxcMEJgQ0JXCbr3fuw22T4VhsYU5PNMAcZ60ipy7GYqMhpoG2CTgI6ZU8/Lfg0dwaAco787ddl5JmlQkskkTIJXknGJakuNCjyCHXrTCR6zjV6sNWVdsyVZN8/z4BGEOdQna6LrOixC+OMxWf9IJAidadugvSHnaRkwrEvTl4ZlIkhGEZ/mLWG1EOA1Gi+TKh505QTK5QZcx4Wu67AZwVXcK6eKNV2DSZDLRl32EbZ0hCxZ21hM0JXpaATGd9mPL1bA6ky6+BGVjiHryCvK2ya
2023-04-05 15:15:50 +00:00
"text/plain": [
2023-04-13 11:12:50 +00:00
"<Figure size 640x480 with 1 Axes>"
2023-04-05 15:15:50 +00:00
]
},
"metadata": {},
2023-04-13 11:12:50 +00:00
"output_type": "display_data"
2023-04-13 11:49:40 +00:00
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAbIAAAGiCAYAAACCpUOHAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjcuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/bCgiHAAAACXBIWXMAAA9hAAAPYQGoP6dpAAEAAElEQVR4nOydeZwUxfn/390998zOzN73ssvNwrLcN4JIPFbB+0IiqNF4IBFNYvxGTKLma6IJ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p3WsSYycPF+PF/Pl9Ozq9EQe7XBJj/tjJUhNlsEtg/7T6fOf7ZR0Yj+yNcgVxdKQT6gAn8pZWVDP4xRNLWt5Mv6esf0a4jEXRdh0SEpDDgT1AahAMcBcV//cqu04mnqAgcTuJhHTWuAYLGgw2gKIydMI7c8o9pZKpKn1DlBl2Hg7IyN1g+NsOPRDBSOiSTtPf0gBAYNisN+3aDw8GRhAmcTohEIJ4AbPQrLQEcCJsNzW2DCNTvazrxER0OXB4Pwu7All9KWLHhEBHQTNiJffyBaOyOYDZbiClKeh+xk8OBGJJ1JBGNCpLJ1Ams9mhUEI8nIRIlmUpBJIyqaJgdOTidsOdgMw6HQp9ukDKbIRIhlUqixKLoWhK7TfyVjX5yuBwKziwbf8HTEGbNjtn0d2yQNiCZTP2prpbBfzj+qwTZr4C3kMTEIPAonDBMZPC3w5W1FK/3OiR7BkBjzJjbcLm+DStWMLq0AB588GNXrGDwwDI4cCfFQQvKVaGPnTuV6mHDgSdgxQrGnTYVZsw4dtZ0k4FRH5FM0z8Dt2MpVf3uAjTeeWc9mKD/Eg3t9iAsXIgvGIRbbsEYMpCAzQYrVjB
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
2023-04-05 15:15:50 +00:00
}
],
"source": [
"\n",
2023-04-13 11:12:50 +00:00
"grid_points = projection_to_grid(150, pca_embeddings, frame_embeddings)\n",
2023-04-13 11:49:40 +00:00
"# print(['CUHK-SYSU' in p['frame_embedding'].img_filename for p in grid_points])\n",
"canvas = draw_grid(60, grid_points, False)\n",
"show_and_save(canvas, os.path.join(result_path, 'pca_plain.png'))\n",
"\n",
"canvas = draw_grid(60, grid_points, True)\n",
"for i, k in enumerate(bgcolors):\n",
" dataset, color = k\n",
" cv2.putText(canvas, dataset, (100, 100*i+100), cv2.FONT_HERSHEY_DUPLEX, 2, color, 2)\n",
"show_and_save(canvas, os.path.join(result_path, 'pca_color.png'))"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Large versions are saved [without colors](OUT/embedding_test/pca_plain.png) and [with colors](OUT/embedding_test/pca_color.png). [Note, these are _big_ image files]"
2023-04-05 15:15:50 +00:00
]
},
{
2023-04-13 11:12:50 +00:00
"attachments": {},
"cell_type": "markdown",
2023-04-05 15:15:50 +00:00
"metadata": {},
"source": [
2023-04-13 11:12:50 +00:00
"UMAP is a clustering algorithm ,which tries to confirm to local and global structures. Being similar to T-SNE it is a visualisation/exploratory method, and thus it shoul not be interpreted too strict."
2023-04-05 15:15:50 +00:00
]
},
{
"cell_type": "code",
2023-04-13 11:49:40 +00:00
"execution_count": 89,
2023-04-05 15:15:50 +00:00
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
2023-04-13 11:12:50 +00:00
"22500 items. Sort\n"
2023-04-05 15:15:50 +00:00
]
2023-04-13 11:12:50 +00:00
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAbIAAAGiCAYAAACCpUOHAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjcuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/bCgiHAAAACXBIWXMAAA9hAAAPYQGoP6dpAAEAAElEQVR4nOy9dbgl53Em/nb36cN4mXlm7jCjmNmSLKPMbMewjr3JxpvEIf/Wu3HsgO2sE5PMlkmymDUajYY0zHcuMx/m0/D7o6q/c++cGUtOvLLGOfU8euaqu0/31193V31V9dZbkmmaJspSlrKUpSxluURF/n0PoCxlKUtZylKW/4yUDVlZylKWspTlkpayIStLWcpSlrJc0lI2ZGUpS1nKUpZLWsqGrCxlKUtZynJJS9mQlaUsZSlLWS5pKRuyspSlLGUpyyUtZUNWlrKUpSxluaSlbMjKUpaylKUsl7SUDVlZylKWspTlkpbXtSH7+te/jra2NjidTmzduhUHDhz4fQ+pLGUpS1nK8jqT160hu//++/GZz3wGf/VXf4XDhw9j7dq1uOmmmzAzM/P7HlpZylKWspTldSTS65U0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5jskodbDBgVy3gyeK8JACMz1NZg67pwnNLpem3BS3zmtHRjY3NoJC9eB60LK+tlA1ZWS5p2bP/EF7cR/ybZ3qJvmxmdg4HDh5ddJwiS7AAfz72ppwuJyxUuZ/DYyvXNMHhILBDJUO+w5FJcZ4rtxNQY1kFeSsSgA0r2gAAU/OlhcOPPUxAEKOQg5Yjo2Jxgra1tZVA7e98y91Y0t0Nm82GG26
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
2023-04-13 11:49:40 +00:00
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAbIAAAGiCAYAAACCpUOHAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjcuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/bCgiHAAAACXBIWXMAAA9hAAAPYQGoP6dpAAEAAElEQVR4nOydd5wV1fn/3zN3bi/be6ezsCwdaWJHjYC9YAE1GgsaUVOMNaYYNRpjS/JNooZgjUYRFRsoSO/swtLZBba3u/fu7u13zu+PM7uwiFF/yfcbTe7n9bqvuztzZubMzLnnOU/7PIoQQpBAAgkkkEAC31Ko/+4OJJBAAgkkkMA/g4QgSyCBBBJI4FuNhCBLIIEEEkjgW42EIEsggQQSSOBbjYQgSyCBBBJI4FuNhCBLIIEEEkjgW42EIEsggQQSSOBbjYQgSyCBBBJI4FuNhCBLIIEEEkjgW42EIEsggQQSSOBbjW+0IHvmmWcoLi7GZrMxYcIE1q9f/+/uUgIJJJBAAt8wfGMF2auvvsrtt9/O/fffz+bNmykvL2f69Ok0Nzf/u7uWQAIJJJDANwjKN5U0eMKECYwbN46nn34aAF3XKSgo4JZbbuHHP/7xv7l3CSSQQAIJfFOg/bs7cDxEIhE2bdrEXXfd1btNVVVOO+001qxZc9xjwuEw4XC4939d12lvbyctLQ1FUf7X+5xAAgkkkMC/DkIIOjs7yc3NRVX/sfHwGynIWltbicfjZGVl9dmelZXFrl27jnvMQ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wYrV5XywLBcYzXML/gpMIClpMU7nOgBGDpC+mKguEEI6Nsc
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
2023-04-05 15:15:50 +00:00
}
],
"source": [
2023-04-13 11:12:50 +00:00
"grid_points = projection_to_grid(150, umap_embeddings, frame_embeddings)\n",
2023-04-13 11:49:40 +00:00
"canvas = draw_grid(60, grid_points, False)\n",
"show_and_save(canvas, os.path.join(result_path, 'umap_plain.png'))\n",
"\n",
"canvas = draw_grid(60, grid_points, True)\n",
"for i, k in enumerate(bgcolors):\n",
" dataset, color = k\n",
" cv2.putText(canvas, dataset, (100, 100*i+100), cv2.FONT_HERSHEY_DUPLEX, 2, color, 2)\n",
"show_and_save(canvas, os.path.join(result_path, 'umap_color.png'))"
2023-04-05 15:15:50 +00:00
]
},
2023-04-13 11:12:50 +00:00
{
2023-04-13 11:49:40 +00:00
"attachments": {},
"cell_type": "markdown",
2023-04-13 11:12:50 +00:00
"metadata": {},
2023-04-13 11:49:40 +00:00
"source": [
"Large versions are saved [without colors](OUT/embedding_test/umap_plain.png) and [with colors](OUT/embedding_test/umap_color.png). [Note, these are _big_ image files]"
]
2023-04-13 11:12:50 +00:00
},
2023-04-05 15:15:50 +00:00
{
2023-04-13 11:49:40 +00:00
"cell_type": "markdown",
2023-04-05 15:15:50 +00:00
"metadata": {},
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "trm",
"language": "python",
"name": "trm"
},
"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.10.8"
},
"orig_nbformat": 4,
"vscode": {
"interpreter": {
"hash": "dc02836f3be4f05ab358b62045dee0ee510294e31b25a582b38257a3269c0c99"
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}