280 lines
1.9 MiB
Text
280 lines
1.9 MiB
Text
|
{
|
||
|
"cells": [
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"# Visualise tracking data\n",
|
||
|
"\n",
|
||
|
"This notebook is an adapted version of `process.py` as it is included in the Trajectron++ package. It can be used to \n",
|
||
|
"\n",
|
||
|
"* Visualise the recorded trajectories, which are normally parsed to a Trajectron++ Node"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 64,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"import sys\n",
|
||
|
"import os\n",
|
||
|
"import numpy as np\n",
|
||
|
"import pandas as pd\n",
|
||
|
"import dill\n",
|
||
|
"import tqdm\n",
|
||
|
"import matplotlib.pyplot as plt\n",
|
||
|
"\n",
|
||
|
"#sys.path.append(\"../../\")\n",
|
||
|
"from trajectron.environment import Environment, Scene, Node\n",
|
||
|
"from trajectron.environment import derivative_of\n"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 65,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"\n",
|
||
|
"desired_max_time = 100\n",
|
||
|
"pred_indices = [2, 3]\n",
|
||
|
"state_dim = 6\n",
|
||
|
"frame_diff = 10\n",
|
||
|
"desired_frame_diff = 1\n",
|
||
|
"dt = 0.1\n",
|
||
|
"\n",
|
||
|
"standardization = {\n",
|
||
|
" 'PEDESTRIAN': {\n",
|
||
|
" 'position': {\n",
|
||
|
" 'x': {'mean': 0, 'std': 1},\n",
|
||
|
" 'y': {'mean': 0, 'std': 1}\n",
|
||
|
" },\n",
|
||
|
" 'velocity': {\n",
|
||
|
" 'x': {'mean': 0, 'std': 2},\n",
|
||
|
" 'y': {'mean': 0, 'std': 2}\n",
|
||
|
" },\n",
|
||
|
" 'acceleration': {\n",
|
||
|
" 'x': {'mean': 0, 'std': 1},\n",
|
||
|
" 'y': {'mean': 0, 'std': 1}\n",
|
||
|
" }\n",
|
||
|
" }\n",
|
||
|
"}\n",
|
||
|
"\n",
|
||
|
"data_columns = pd.MultiIndex.from_product([['position', 'velocity', 'acceleration'], ['x', 'y']])\n",
|
||
|
"\n",
|
||
|
"\n",
|
||
|
"# desired_source = 'EXPERIMENTS/raw/hof-meter-maskrcnn2'\n",
|
||
|
"# desired_source = 'EXPERIMENTS/20240424-hof-meter-maskrcnn2'\n",
|
||
|
"# desired_source = 'EXPERIMENTS/20240426-hof-yolo'\n",
|
||
|
"desired_source = 'EXPERIMENTS/raw/hof2'\n"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 66,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"# run some tests\n",
|
||
|
"\n",
|
||
|
"if not os.path.exists(desired_source):\n",
|
||
|
" raise FileNotFoundError(f\"Path does not exist {desired_source=}\")"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 67,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"from matplotlib.axes import Axes\n",
|
||
|
"from trap.frame_emitter import DetectionState\n",
|
||
|
"\n",
|
||
|
"def parse_txt(data_path, dt, axes: Axes, axes2: Axes) -> dict[str, pd.DataFrame]:\n",
|
||
|
" skipped_for_error = 0\n",
|
||
|
" created = 0\n",
|
||
|
"\n",
|
||
|
" data = pd.read_csv(data_path, sep='\\t', index_col=False, header=None)\n",
|
||
|
" data.columns = ['frame_id', 'track_id', 'l','t', 'w','h', 'pos_x', 'pos_y', 'state']\n",
|
||
|
" # data['frame_id'] = pd.to_numeric(data['frame_id'], downcast='integer')\n",
|
||
|
" data['track_id'] = pd.to_numeric(data['track_id'], downcast='integer')\n",
|
||
|
"\n",
|
||
|
" data['frame_id'] = data['frame_id'] // 10\n",
|
||
|
" data['frame_id'] -= data['frame_id'].min()\n",
|
||
|
"\n",
|
||
|
" data['node_type'] = 'PEDESTRIAN'\n",
|
||
|
" data['node_id'] = data['track_id'].astype(str)\n",
|
||
|
" data['state'] = data['state'].apply(lambda x: (eval(x) if type(x) is str else DetectionState(x)).value)\n",
|
||
|
" data.sort_values('frame_id', inplace=True)\n",
|
||
|
"\n",
|
||
|
" # Mean Position\n",
|
||
|
"\n",
|
||
|
" print(\"Means: x:\", data['pos_x'].mean(), \"y:\", data['pos_y'].mean())\n",
|
||
|
" data['pos_x'] = data['pos_x'] - data['pos_x'].mean()\n",
|
||
|
" data['pos_y'] = data['pos_y'] - data['pos_y'].mean()\n",
|
||
|
"\n",
|
||
|
" max_timesteps = data['frame_id'].max()\n",
|
||
|
"\n",
|
||
|
" nodes = {}\n",
|
||
|
"\n",
|
||
|
" # only keep tentative and confirmed detections\n",
|
||
|
" # print(data)\n",
|
||
|
" data = data.loc[data['state'] != DetectionState.Lost.value]\n",
|
||
|
"\n",
|
||
|
" print(data[['track_id', 'node_id', 'state']])\n",
|
||
|
"\n",
|
||
|
" for node_id in tqdm.tqdm(pd.unique(data['node_id'])):\n",
|
||
|
" node_df = data[data['node_id'] == node_id]\n",
|
||
|
" if not np.all(np.diff(node_df['frame_id']) == 1):\n",
|
||
|
" # print(f\"Interval in {node_id} not always 1\")\n",
|
||
|
" # print(node_df['frame_id'])\n",
|
||
|
" # print(np.diff(node_df['frame_id']) != 1)\n",
|
||
|
" # mask=np.append(False, np.diff(node_df['frame_id']) != 1)\n",
|
||
|
" # print(node_df[mask]['frame_id'])\n",
|
||
|
" skipped_for_error += 1\n",
|
||
|
" continue\n",
|
||
|
"\n",
|
||
|
"\n",
|
||
|
" node_values = node_df[['pos_x', 'pos_y']].values\n",
|
||
|
"\n",
|
||
|
" if node_values.shape[0] <= 10:\n",
|
||
|
" continue\n",
|
||
|
"\n",
|
||
|
" new_first_idx = node_df['frame_id'].iloc[0]\n",
|
||
|
"\n",
|
||
|
" x = node_values[:, 0]\n",
|
||
|
" y = -node_values[:, 1]\n",
|
||
|
" vx = derivative_of(x, dt)\n",
|
||
|
" vy = derivative_of(y, dt)\n",
|
||
|
" ax = derivative_of(vx, dt)\n",
|
||
|
" ay = derivative_of(vy, dt)\n",
|
||
|
"\n",
|
||
|
" \n",
|
||
|
" axes.plot(x, y, alpha=.3)\n",
|
||
|
" axes.scatter(x, y, marker='x', alpha=.3)\n",
|
||
|
"\n",
|
||
|
" nv = node_df[['l','t', 'w', 'h']].values\n",
|
||
|
" x = nv[:, 0] + .5*nv[:, 2]\n",
|
||
|
" y = nv[:, 1] + nv[:, 3]\n",
|
||
|
" axes2.plot(x, y, alpha=.3)\n",
|
||
|
" axes2.scatter(x, y, marker='x', alpha=.3)\n",
|
||
|
"\n",
|
||
|
" nodes[node_id] = [x,y]\n",
|
||
|
" # data_dict = {'node_id': node_id, ('position', 'x'): x,\n",
|
||
|
" # ('position', 'y'): y,\n",
|
||
|
" # ('velocity', 'x'): vx,\n",
|
||
|
" # ('velocity', 'y'): vy,\n",
|
||
|
" # ('acceleration', 'x'): ax,\n",
|
||
|
" # ('acceleration', 'y'): ay}\n",
|
||
|
" \n",
|
||
|
" # node_data = pd.DataFrame(data_dict, columns=data_columns)\n",
|
||
|
" # nodes[node_id] = node_data\n",
|
||
|
" return nodes"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 68,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stdout",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"Means: x: 1281.0115073996574 y: 801.2940430516817\n",
|
||
|
" track_id node_id state\n",
|
||
|
"63577 1300 1300 2\n",
|
||
|
"87646 1853 1853 2\n",
|
||
|
"87645 1852 1852 2\n",
|
||
|
"87644 1851 1851 2\n",
|
||
|
"129133 2360 2360 2\n",
|
||
|
"... ... ... ...\n",
|
||
|
"38247 742 742 2\n",
|
||
|
"38248 742 742 2\n",
|
||
|
"38249 742 742 2\n",
|
||
|
"38250 742 742 2\n",
|
||
|
"38251 742 742 2\n",
|
||
|
"\n",
|
||
|
"[157580 rows x 3 columns]\n"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"name": "stderr",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"100%|██████████| 1719/1719 [00:12<00:00, 138.23it/s]\n"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"178"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 68,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
},
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA/QAAAT7CAYAAAAw1Ps5AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/NK7nSAAAACXBIWXMAAA9hAAAPYQGoP6dpAAEAAElEQVR4nOz9eZBlyV3f/b8z86x3q1v70tv07PsujUaSWSSBJGRsHitsKx7ZgQ0/5MAIG2zAKAIpglVGgTEhwMgQBMiBHLYxxpZlkCwkQIBGs/Zotp7pmel9qb3qrmfNzN8fNVMwSH6sZbpbNfN9Rdyo6rPcm+dU9In6VGZ+U3nvPUIIIYQQQgghhNhT9OVugBBCCCGEEEIIIb56EuiFEEIIIYQQQog9SAK9EEIIIYQQQgixB0mgF0IIIYQQQggh9iAJ9EIIIYQQQgghxB4kgV4IIYQQQgghhNiDJNALIYQQQgghhBB7UHC5GyD2Ducc58+fp91uo5S63M0RQgghhBBCfAPw3jMYDFhaWkJr6TO+lCTQi6/Y+fPnOXDgwOVuhhBCCCGEEOIb0JkzZ9i/f//lbsarigR68RVrt9vAzn/UTqdzmVsjhBBCCCGE+EbQ7/c5cODAbl4Ql44EevEVe3GYfafTkUAvhBBCCCGEeAmZlnvpyQQHIYQQQgghhBBiD5JAL4QQQ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N4PY7eDav6G33ePyhR8iqilRr7p5okpiX/urnncNWFfUL4b0qC+Avw3xdFtiqkkr5QgjxDUoCvRBCCCHEHuOrivz
|
||
|
"text/plain": [
|
||
|
"<Figure size 2000x1600 with 2 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"fig = plt.figure(figsize=(20,16))\n",
|
||
|
"ax1, ax2 = fig.subplots(2)\n",
|
||
|
"\n",
|
||
|
"import cv2\n",
|
||
|
"# ax = fig1.gca()\n",
|
||
|
"# ax2 = fig2.gca()\n",
|
||
|
"im = cv2.imread(\"../DATASETS/hof2/output.png\")\n",
|
||
|
"ax2.imshow(im)\n",
|
||
|
"ax1.set_aspect(1)\n",
|
||
|
"ax2.set_aspect(1)\n",
|
||
|
"nodes = []\n",
|
||
|
"for data_class in ['train', 'val', 'test']:\n",
|
||
|
" target_dir = os.path.join(desired_source, data_class)\n",
|
||
|
" for subdir, dirs, files in os.walk(target_dir):\n",
|
||
|
" for file in files:\n",
|
||
|
" if file.endswith('.txt'):\n",
|
||
|
" input_data_dict = dict()\n",
|
||
|
" full_data_path = os.path.join(subdir, file)\n",
|
||
|
" nodes.extend(parse_txt(full_data_path, dt, ax1, ax2))\n",
|
||
|
" break\n",
|
||
|
" break\n",
|
||
|
" break\n",
|
||
|
"fig.show()\n",
|
||
|
"len(nodes)"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"metadata": {
|
||
|
"kernelspec": {
|
||
|
"display_name": ".venv",
|
||
|
"language": "python",
|
||
|
"name": "python3"
|
||
|
},
|
||
|
"language_info": {
|
||
|
"codemirror_mode": {
|
||
|
"name": "ipython",
|
||
|
"version": 3
|
||
|
},
|
||
|
"file_extension": ".py",
|
||
|
"mimetype": "text/x-python",
|
||
|
"name": "python",
|
||
|
"nbconvert_exporter": "python",
|
||
|
"pygments_lexer": "ipython3",
|
||
|
"version": "3.10.4"
|
||
|
}
|
||
|
},
|
||
|
"nbformat": 4,
|
||
|
"nbformat_minor": 2
|
||
|
}
|