Datasets:
Added Radar
Browse files- Individual-Contest/Radar/.DS_Store +0 -0
- Individual-Contest/Radar/.pytest_cache/.gitignore +2 -0
- Individual-Contest/Radar/.pytest_cache/CACHEDIR.TAG +4 -0
- Individual-Contest/Radar/.pytest_cache/README.md +8 -0
- Individual-Contest/Radar/.pytest_cache/v/cache/lastfailed +3 -0
- Individual-Contest/Radar/.pytest_cache/v/cache/nodeids +3 -0
- Individual-Contest/Radar/Radar.ipynb +564 -0
- Individual-Contest/Radar/Solution/.DS_Store +0 -0
- Individual-Contest/Radar/Solution/Radar_Solution.ipynb +1056 -0
- Individual-Contest/Radar/Solution/Scoring/metrics.py +117 -0
- Individual-Contest/Radar/Solution/figs/IOAI-Logo.png +3 -0
- Individual-Contest/Radar/figs/IOAI-Logo.png +3 -0
- Individual-Contest/Radar/figs/Radar Fig 1.png +3 -0
- Individual-Contest/Radar/figs/Radar Fig 2.png +3 -0
- Individual-Contest/Radar/figs/Radar Fig 3.png +3 -0
Individual-Contest/Radar/.DS_Store
ADDED
|
Binary file (6.15 kB). View file
|
|
|
Individual-Contest/Radar/.pytest_cache/.gitignore
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Created by pytest automatically.
|
| 2 |
+
*
|
Individual-Contest/Radar/.pytest_cache/CACHEDIR.TAG
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Signature: 8a477f597d28d172789f06886806bc55
|
| 2 |
+
# This file is a cache directory tag created by pytest.
|
| 3 |
+
# For information about cache directory tags, see:
|
| 4 |
+
# https://bford.info/cachedir/spec.html
|
Individual-Contest/Radar/.pytest_cache/README.md
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# pytest cache directory #
|
| 2 |
+
|
| 3 |
+
This directory contains data from the pytest's cache plugin,
|
| 4 |
+
which provides the `--lf` and `--ff` options, as well as the `cache` fixture.
|
| 5 |
+
|
| 6 |
+
**Do not** commit this to version control.
|
| 7 |
+
|
| 8 |
+
See [the docs](https://docs.pytest.org/en/stable/how-to/cache.html) for more information.
|
Individual-Contest/Radar/.pytest_cache/v/cache/lastfailed
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"Radar.ipynb::Radar.ipynb": true
|
| 3 |
+
}
|
Individual-Contest/Radar/.pytest_cache/v/cache/nodeids
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
"Radar.ipynb::Radar.ipynb"
|
| 3 |
+
]
|
Individual-Contest/Radar/Radar.ipynb
ADDED
|
@@ -0,0 +1,564 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "markdown",
|
| 5 |
+
"metadata": {},
|
| 6 |
+
"source": [
|
| 7 |
+
"<img src=\"./figs/IOAI-Logo.png\" alt=\"IOAI Logo\" width=\"200\" height=\"auto\">\n",
|
| 8 |
+
"\n",
|
| 9 |
+
"[IOAI 2025 (Beijing, China), Individual Contest](https://ioai-official.org/china-2025)\n",
|
| 10 |
+
"\n",
|
| 11 |
+
"[](https://colab.research.google.com/github/IOAI-official/IOAI-2025/blob/main/Individual-Contest/Radar/Radar.ipynb)"
|
| 12 |
+
]
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"cell_type": "markdown",
|
| 16 |
+
"metadata": {},
|
| 17 |
+
"source": [
|
| 18 |
+
"# Radar\n",
|
| 19 |
+
"\n",
|
| 20 |
+
"## 1. Problem Description \n",
|
| 21 |
+
"\n",
|
| 22 |
+
"Radar is a key technology in wireless communication, with widespread applications such as self-driving cars. It typically involves an antenna that transmits specific signals and receives their reflections from objects in the environment. By processing these signals, the system determines the angular direction, distance, and velocity of target objects.\n",
|
| 23 |
+
"\n",
|
| 24 |
+
"In real-world applications, radar signal processing is challenging due to noise and reflections from non-target objects in the surroundings. For example, when attempting to detect pedestrians, the radar may also receive reflections from trees or other background objects, which can degrade accuracy. Your task is to use AI to analyze the signals received by the radar and identify the presence of a human at each position.\n",
|
| 25 |
+
"\n",
|
| 26 |
+
"In this task, we provide an **indoor radar experiment dataset**, and your objective is to develop a model that performs **radar semantic segmentation**. \n",
|
| 27 |
+
"\n",
|
| 28 |
+
"\n",
|
| 29 |
+
"## 2. Dataset\n",
|
| 30 |
+
"\n",
|
| 31 |
+
"To measure objects surrounding a radar, the following key parameters are used:\n",
|
| 32 |
+
"\n",
|
| 33 |
+
"- **Range**: The straight-line distance between the radar and an object.\n",
|
| 34 |
+
"- **Azimuth**: The horizontal angle (left to right) between the radar and the object.\n",
|
| 35 |
+
"- **Elevation**: The vertical angle (up or down) of the object relative to the radar.\n",
|
| 36 |
+
"- **Velocity**: The speed at which the object is moving toward or away from the radar.\n",
|
| 37 |
+
"\n",
|
| 38 |
+
"<img src=\"./figs/Radar Fig 1.png\" width=\"300\">\n",
|
| 39 |
+
"\n",
|
| 40 |
+
"\n",
|
| 41 |
+
"The radar data is processed into multiple **heatmaps**, each encoding the **received signal strength** at various positions and directions.\n",
|
| 42 |
+
"\n",
|
| 43 |
+
"- **Static heatmaps** emphasize reflections from **stationary** objects.\n",
|
| 44 |
+
"- **Dynamic heatmaps** highlight changes caused by **moving** objects.\n",
|
| 45 |
+
"\n",
|
| 46 |
+
"When no object is present at a specific location, the signal consists mostly of background noise and appears weak. In contrast, reflections from an object increase signal intensity, enabling detection of the object.\n",
|
| 47 |
+
"\n",
|
| 48 |
+
"For example, the **static range-azimuth heatmap** represents signal strength across different distances (**range**) and horizontal angles (**azimuth**), mainly reflected by stationary objects.\n",
|
| 49 |
+
"\n",
|
| 50 |
+
"Each sample in the dataset is stored in a `.mat.pt` file as a tensor of shape $7 \\times 50 \\times 181$, where:\n",
|
| 51 |
+
"\n",
|
| 52 |
+
"- 7 is the number of maps (6 heatmaps + 1 semantic label map),\n",
|
| 53 |
+
"- 50 represents range bins (distance),\n",
|
| 54 |
+
"- 181 represents angular or velocity bins, covering angles from \\-90° to \\+90° in either the horizontal or vertical plane. You can assume that the velocity bins are also remapped from \\-90° to \\+90° for visualization consistency.\n",
|
| 55 |
+
"- each heatmap intensity value is normalized to [0, 1], representing received signal strength.\n",
|
| 56 |
+
"\n",
|
| 57 |
+
"The 6 heatmaps are structured as follows:\n",
|
| 58 |
+
"\n",
|
| 59 |
+
"- **Index 0**: Static range-azimuth heatmap\n",
|
| 60 |
+
"- **Index 1**: Dynamic range-azimuth heatmap\n",
|
| 61 |
+
"- **Index 2**: Static range-elevation heatmap\n",
|
| 62 |
+
"- **Index 3**: Dynamic range-elevation heatmap\n",
|
| 63 |
+
"- **Index 4**: Static range-velocity heatmap\n",
|
| 64 |
+
"- **Index 5**: Dynamic range-velocity heatmap\n",
|
| 65 |
+
"\n",
|
| 66 |
+
"All values in heatmaps are **normalized**, so no unit conversion is required.\n",
|
| 67 |
+
"\n",
|
| 68 |
+
"The **map at Index 6** is the semantic label map, stored in range-azimuth format. \n",
|
| 69 |
+
"\n",
|
| 70 |
+
"- **-1**: Background (no target)\n",
|
| 71 |
+
"- **0**: Suitcase\n",
|
| 72 |
+
"- **1**: Chair\n",
|
| 73 |
+
"- **2**: Human\n",
|
| 74 |
+
"- **3**: Wall\n",
|
| 75 |
+
"\n",
|
| 76 |
+
"This is the visualization of 1.mat.pt in training_set:\n",
|
| 77 |
+
"\n",
|
| 78 |
+
"<img src=\"./figs/Radar Fig 2.png\" width=\"675\">\n",
|
| 79 |
+
"\n",
|
| 80 |
+
"Here is part of a sample from the dataset:\n",
|
| 81 |
+
"\n",
|
| 82 |
+
"<img src=\"./figs/Radar Fig 3.png\" width=\"675\">\n",
|
| 83 |
+
"\n",
|
| 84 |
+
"\n",
|
| 85 |
+
"Data scale: 1800 samples in the training set, 500 samples in the validation set, and 500 samples in the test set.\n",
|
| 86 |
+
"\n",
|
| 87 |
+
"## 3\\. Task\n",
|
| 88 |
+
"\n",
|
| 89 |
+
"Your task is to develop a model that takes the **first six heatmaps** (indices 0 to 5) as input, and predicts the **semantic label map** (index 6) as the output. The goal is to accurately identify what the target is(-1 to 3) at each location in the radar’s field of view.\n",
|
| 90 |
+
"\n",
|
| 91 |
+
"1. **Input**: A tensor of shape $6 \\times 50 \\times 181$, representing six radar heatmaps.\n",
|
| 92 |
+
"2. **Output**: A tensor of shape $50 \\times 181$, representing the target semantic label map.\n",
|
| 93 |
+
"\n",
|
| 94 |
+
"\n",
|
| 95 |
+
"## 4\\. Submission \n",
|
| 96 |
+
"\n",
|
| 97 |
+
"Please submit a file named `submission.ipynb`. The output is a zip file named \"submission.zip\", which contains two tables `submission_val.csv` and `submission_test.csv` corresponding to the prediction results of the validation set and the test set respectively.\n",
|
| 98 |
+
"\n",
|
| 99 |
+
"**Note:** The output table should have a header, the data in the table is not the actual solved data, it is only used as an example of the submission format.\n",
|
| 100 |
+
"\n",
|
| 101 |
+
"| filename | pixel_0 | pixel_1 | ... | pixel_9049 |\n",
|
| 102 |
+
"| :------: | :-----: | ------- | --- | ---------- |\n",
|
| 103 |
+
"| 1.mat.pt | -1 | -1 | ... | -1 |\n",
|
| 104 |
+
"| ... | ... | ... | ... | ... |\n",
|
| 105 |
+
"\n",
|
| 106 |
+
"## 5\\. Score\n",
|
| 107 |
+
"\n",
|
| 108 |
+
"The score is based on the **accuracy of label recognition**. Correctly identifying target points is weighted more heavily than correctly identifying background points. \n",
|
| 109 |
+
"\n",
|
| 110 |
+
"### Scoring Criteria: \n",
|
| 111 |
+
"\n",
|
| 112 |
+
"* Each correctly identified **background pixel** earns **1 point**. \n",
|
| 113 |
+
"\n",
|
| 114 |
+
"* Each correctly identified **non-background pixel** earns **50 points**. \n",
|
| 115 |
+
"\n",
|
| 116 |
+
"* The final score is normalized to a **0-1 point** by comparing it to the maximum possible score. \n",
|
| 117 |
+
"\n",
|
| 118 |
+
"### Formula:\n",
|
| 119 |
+
"$$\n",
|
| 120 |
+
"Score = \\frac{|C_{0,correct}| \\times 1 + |C_{1,correct}| \\times bonus}{|C_0| \\times 1 + |C_1| \\times bonus}\n",
|
| 121 |
+
"$$\n",
|
| 122 |
+
"where:\n",
|
| 123 |
+
"\n",
|
| 124 |
+
"$$\n",
|
| 125 |
+
"\\begin{aligned}\n",
|
| 126 |
+
"I &= \\{1, 2, \\dots, 50\\times 181\\}\\\\\n",
|
| 127 |
+
"C_0 &= \\{i \\in I \\mid y_i = -1\\}\\\\\n",
|
| 128 |
+
"C_1 &= \\{i \\in I \\mid y_i \\neq -1\\}\\\\\n",
|
| 129 |
+
"C_{0,correct} &= \\{i \\in C_0 \\mid p_i = y_i\\}\\\\\n",
|
| 130 |
+
"C_{1,correct} &= \\{i \\in C_1 \\mid p_i = y_i\\}\\\\\n",
|
| 131 |
+
"\\end{aligned}\n",
|
| 132 |
+
"$$\n",
|
| 133 |
+
"\n",
|
| 134 |
+
"\n",
|
| 135 |
+
"### Example\n",
|
| 136 |
+
"\n",
|
| 137 |
+
"For a $3\\times3$ heatmap, assume the Ground Truth is:\n",
|
| 138 |
+
"\n",
|
| 139 |
+
"$$\n",
|
| 140 |
+
"\\begin{bmatrix}\n",
|
| 141 |
+
"-1 & -1 & -1 \\\\\n",
|
| 142 |
+
"1 & 2 & 3 \\\\\n",
|
| 143 |
+
"-1 & -1 & -1\n",
|
| 144 |
+
"\\end{bmatrix}\n",
|
| 145 |
+
"$$\n",
|
| 146 |
+
"\n",
|
| 147 |
+
"The intenteded result is:\n",
|
| 148 |
+
"\n",
|
| 149 |
+
"$$\n",
|
| 150 |
+
"\\begin{bmatrix}\n",
|
| 151 |
+
"-1 & 1 & -1 \\\\\n",
|
| 152 |
+
"-1 & 2 & -1 \\\\\n",
|
| 153 |
+
"-1 & 3 & -1\n",
|
| 154 |
+
"\\end{bmatrix}\n",
|
| 155 |
+
"$$\n",
|
| 156 |
+
"\n",
|
| 157 |
+
"Then there are four correctly identified `-1` and one correctly identified `2`. Your score is 4 + 50 = 54 points. The maximum possible score is 6 + 50 * 3 = 156, that is, the score for six background pixels and three non-background pixels. Your normalized score is 54 / 156 = 0.346.\n",
|
| 158 |
+
"\n",
|
| 159 |
+
"$$\n",
|
| 160 |
+
"Score = \\frac{4 \\times 1 + 1 \\times 50}{6 \\times 1 + 3 \\times 50}=0.346\n",
|
| 161 |
+
"$$\n",
|
| 162 |
+
"\n",
|
| 163 |
+
"## 6. Baseline and Training Set\n",
|
| 164 |
+
"\n",
|
| 165 |
+
"- Below you can find the baseline solution.\n",
|
| 166 |
+
"- The dataset is in `training_set` folder.\n",
|
| 167 |
+
"- The highest score by the Scientific Committee for this task is 0.90 in Leaderboard B, this score is used for score unification.\n",
|
| 168 |
+
"- The baseline score by the Scientific Committee for this task is 0.67 in Leaderboard B, this score is used for score unification."
|
| 169 |
+
]
|
| 170 |
+
},
|
| 171 |
+
{
|
| 172 |
+
"cell_type": "markdown",
|
| 173 |
+
"metadata": {},
|
| 174 |
+
"source": [
|
| 175 |
+
"### Data Loading"
|
| 176 |
+
]
|
| 177 |
+
},
|
| 178 |
+
{
|
| 179 |
+
"cell_type": "code",
|
| 180 |
+
"execution_count": null,
|
| 181 |
+
"metadata": {},
|
| 182 |
+
"outputs": [],
|
| 183 |
+
"source": [
|
| 184 |
+
"import random\n",
|
| 185 |
+
"import numpy as np\n",
|
| 186 |
+
"import torch\n",
|
| 187 |
+
"\n",
|
| 188 |
+
"seed = 42\n",
|
| 189 |
+
"\n",
|
| 190 |
+
"random.seed(seed) # Python built-in random\n",
|
| 191 |
+
"np.random.seed(seed) # NumPy\n",
|
| 192 |
+
"torch.manual_seed(seed) # PyTorch (CPU)\n",
|
| 193 |
+
"torch.cuda.manual_seed(seed) # PyTorch (single GPU)\n",
|
| 194 |
+
"torch.cuda.manual_seed_all(seed) # PyTorch (all GPUs)\n",
|
| 195 |
+
"\n",
|
| 196 |
+
"# Ensures deterministic behavior\n",
|
| 197 |
+
"torch.backends.cudnn.deterministic = True\n",
|
| 198 |
+
"torch.backends.cudnn.benchmark = False"
|
| 199 |
+
]
|
| 200 |
+
},
|
| 201 |
+
{
|
| 202 |
+
"cell_type": "code",
|
| 203 |
+
"execution_count": null,
|
| 204 |
+
"metadata": {},
|
| 205 |
+
"outputs": [],
|
| 206 |
+
"source": [
|
| 207 |
+
"import os\n",
|
| 208 |
+
"import torch\n",
|
| 209 |
+
"from torch.utils.data import Dataset, DataLoader\n",
|
| 210 |
+
"from sklearn.model_selection import train_test_split\n",
|
| 211 |
+
"\n",
|
| 212 |
+
"class CustomDataset(Dataset):\n",
|
| 213 |
+
" def __init__(self, file_paths, transform=None):\n",
|
| 214 |
+
" self.file_paths = file_paths\n",
|
| 215 |
+
" self.transform = transform\n",
|
| 216 |
+
" self.file_names = [os.path.basename(path) for path in file_paths]\n",
|
| 217 |
+
"\n",
|
| 218 |
+
" def __len__(self):\n",
|
| 219 |
+
" return len(self.file_paths)\n",
|
| 220 |
+
"\n",
|
| 221 |
+
" def __getitem__(self, idx):\n",
|
| 222 |
+
" data = torch.load(self.file_paths[idx], weights_only=True)\n",
|
| 223 |
+
" \n",
|
| 224 |
+
" images = data[:6] \n",
|
| 225 |
+
" labels = data[6] \n",
|
| 226 |
+
" \n",
|
| 227 |
+
" images = images.float() \n",
|
| 228 |
+
" labels = labels.long() \n",
|
| 229 |
+
" labels = labels + 1\n",
|
| 230 |
+
"\n",
|
| 231 |
+
" if self.transform:\n",
|
| 232 |
+
" images = self.transform(images)\n",
|
| 233 |
+
" labels = self.transform(labels)\n",
|
| 234 |
+
" \n",
|
| 235 |
+
" return images, labels, self.file_names[idx]\n",
|
| 236 |
+
"\n",
|
| 237 |
+
"class CustomDataset_test(Dataset):\n",
|
| 238 |
+
" def __init__(self, file_paths, transform=None):\n",
|
| 239 |
+
" self.file_paths = file_paths\n",
|
| 240 |
+
" self.transform = transform\n",
|
| 241 |
+
" self.file_names = [os.path.basename(path) for path in file_paths]\n",
|
| 242 |
+
"\n",
|
| 243 |
+
" def __len__(self):\n",
|
| 244 |
+
" return len(self.file_paths)\n",
|
| 245 |
+
"\n",
|
| 246 |
+
" def __getitem__(self, idx):\n",
|
| 247 |
+
" data = torch.load(self.file_paths[idx], weights_only=True)\n",
|
| 248 |
+
" \n",
|
| 249 |
+
" images = data[:6] \n",
|
| 250 |
+
" \n",
|
| 251 |
+
" images = images.float() \n",
|
| 252 |
+
"\n",
|
| 253 |
+
" if self.transform:\n",
|
| 254 |
+
" images = self.transform(images)\n",
|
| 255 |
+
" \n",
|
| 256 |
+
" return images, self.file_names[idx]\n",
|
| 257 |
+
"\n",
|
| 258 |
+
"def generate_file_paths(base_path):\n",
|
| 259 |
+
" file_paths = []\n",
|
| 260 |
+
" for frame in os.listdir(base_path):\n",
|
| 261 |
+
" frame_path = os.path.join(base_path, frame)\n",
|
| 262 |
+
" if frame_path.endswith('.mat.pt'):\n",
|
| 263 |
+
" file_paths.append(frame_path)\n",
|
| 264 |
+
" return [path for path in file_paths if os.path.exists(path)]\n",
|
| 265 |
+
"\n",
|
| 266 |
+
"def load_data(base_path, batch_size=4, num_workers=2, test_size=0.2):\n",
|
| 267 |
+
" file_paths = generate_file_paths(base_path)\n",
|
| 268 |
+
" \n",
|
| 269 |
+
" train_paths, test_paths = train_test_split(file_paths, test_size=test_size, random_state=42)\n",
|
| 270 |
+
" \n",
|
| 271 |
+
" train_dataset = CustomDataset(file_paths=train_paths)\n",
|
| 272 |
+
" test_dataset = CustomDataset(file_paths=test_paths)\n",
|
| 273 |
+
" \n",
|
| 274 |
+
" train_loader = DataLoader(\n",
|
| 275 |
+
" train_dataset, \n",
|
| 276 |
+
" batch_size=batch_size, \n",
|
| 277 |
+
" shuffle=True, \n",
|
| 278 |
+
" num_workers=num_workers, \n",
|
| 279 |
+
" drop_last=True\n",
|
| 280 |
+
" )\n",
|
| 281 |
+
" \n",
|
| 282 |
+
" test_loader = DataLoader(\n",
|
| 283 |
+
" test_dataset, \n",
|
| 284 |
+
" batch_size=batch_size, \n",
|
| 285 |
+
" shuffle=False, \n",
|
| 286 |
+
" num_workers=num_workers, \n",
|
| 287 |
+
" drop_last=True\n",
|
| 288 |
+
" )\n",
|
| 289 |
+
" \n",
|
| 290 |
+
" return train_loader, test_loader"
|
| 291 |
+
]
|
| 292 |
+
},
|
| 293 |
+
{
|
| 294 |
+
"cell_type": "markdown",
|
| 295 |
+
"metadata": {},
|
| 296 |
+
"source": [
|
| 297 |
+
"### Model Definition and Training"
|
| 298 |
+
]
|
| 299 |
+
},
|
| 300 |
+
{
|
| 301 |
+
"cell_type": "code",
|
| 302 |
+
"execution_count": null,
|
| 303 |
+
"metadata": {},
|
| 304 |
+
"outputs": [],
|
| 305 |
+
"source": [
|
| 306 |
+
"import torch\n",
|
| 307 |
+
"import torch.nn as nn\n",
|
| 308 |
+
"import torch.optim as optim\n",
|
| 309 |
+
"\n",
|
| 310 |
+
"class MyModel(nn.Module):\n",
|
| 311 |
+
" def __init__(self):\n",
|
| 312 |
+
" super(MyModel, self).__init__()\n",
|
| 313 |
+
" self.conv1 = nn.Conv2d(in_channels=6, out_channels=16, kernel_size=3, padding=1) \n",
|
| 314 |
+
" self.conv2 = nn.Conv2d(in_channels=16, out_channels=32, kernel_size=3, padding=1) \n",
|
| 315 |
+
" self.conv3 = nn.Conv2d(in_channels=32, out_channels=5, kernel_size=3, padding=1)\n",
|
| 316 |
+
"\n",
|
| 317 |
+
" self.relu = nn.ReLU()\n",
|
| 318 |
+
"\n",
|
| 319 |
+
" def forward(self, x):\n",
|
| 320 |
+
" x = self.relu(self.conv1(x))\n",
|
| 321 |
+
" x = self.relu(self.conv2(x))\n",
|
| 322 |
+
" x = self.conv3(x) \n",
|
| 323 |
+
" return x\n",
|
| 324 |
+
"\n",
|
| 325 |
+
"def train(model, train_loader, test_loader, optimizer, criterion, num_epochs=100):\n",
|
| 326 |
+
" train_losses = []\n",
|
| 327 |
+
" val_losses = []\n",
|
| 328 |
+
" \n",
|
| 329 |
+
" for epoch in range(num_epochs):\n",
|
| 330 |
+
" model.train()\n",
|
| 331 |
+
" epoch_loss = 0.0\n",
|
| 332 |
+
" batch_count = 0\n",
|
| 333 |
+
" \n",
|
| 334 |
+
" for images, labels, _ in train_loader:\n",
|
| 335 |
+
" images = images.cuda() if torch.cuda.is_available() else images\n",
|
| 336 |
+
" labels = labels.cuda() if torch.cuda.is_available() else labels\n",
|
| 337 |
+
" \n",
|
| 338 |
+
" outputs = model(images)\n",
|
| 339 |
+
" outputs = outputs.view(outputs.size(0), outputs.size(1), -1) # [B, C, H*W]\n",
|
| 340 |
+
" labels = labels.view(labels.size(0), -1) # [B, H*W]\n",
|
| 341 |
+
" loss = criterion(outputs, labels)\n",
|
| 342 |
+
" \n",
|
| 343 |
+
" optimizer.zero_grad()\n",
|
| 344 |
+
" loss.backward()\n",
|
| 345 |
+
" optimizer.step()\n",
|
| 346 |
+
" \n",
|
| 347 |
+
" epoch_loss += loss.item()\n",
|
| 348 |
+
" batch_count += 1\n",
|
| 349 |
+
" \n",
|
| 350 |
+
" avg_train_loss = epoch_loss / batch_count\n",
|
| 351 |
+
" train_losses.append(avg_train_loss)\n",
|
| 352 |
+
" \n",
|
| 353 |
+
" model.eval()\n",
|
| 354 |
+
" val_loss = 0.0\n",
|
| 355 |
+
" val_batch_count = 0\n",
|
| 356 |
+
" \n",
|
| 357 |
+
" with torch.no_grad():\n",
|
| 358 |
+
" for images, labels, _ in test_loader:\n",
|
| 359 |
+
" images = images.cuda() if torch.cuda.is_available() else images\n",
|
| 360 |
+
" labels = labels.cuda() if torch.cuda.is_available() else labels\n",
|
| 361 |
+
" \n",
|
| 362 |
+
" outputs = model(images)\n",
|
| 363 |
+
" outputs = outputs.view(outputs.size(0), outputs.size(1), -1)\n",
|
| 364 |
+
" labels = labels.view(labels.size(0), -1)\n",
|
| 365 |
+
" loss = criterion(outputs, labels)\n",
|
| 366 |
+
" \n",
|
| 367 |
+
" val_loss += loss.item()\n",
|
| 368 |
+
" val_batch_count += 1\n",
|
| 369 |
+
" \n",
|
| 370 |
+
" avg_val_loss = val_loss / val_batch_count\n",
|
| 371 |
+
" val_losses.append(avg_val_loss)\n",
|
| 372 |
+
" \n",
|
| 373 |
+
" if (epoch+1) % 2 == 0:\n",
|
| 374 |
+
" print(f'Epoch [{epoch+1}/{num_epochs}], '\n",
|
| 375 |
+
" f'Train Loss: {avg_train_loss:.4f}, '\n",
|
| 376 |
+
" f'Val Loss: {avg_val_loss:.4f}')\n",
|
| 377 |
+
" \n",
|
| 378 |
+
" return train_losses, val_losses\n",
|
| 379 |
+
"TRAIN_PATH = \"./\"\n",
|
| 380 |
+
"# The training set is deployed automatically in the testing machine. \n",
|
| 381 |
+
"# You notebook can access the TRAIN_PATH even if you do not mount it along with notebook.\n",
|
| 382 |
+
"data_path = TRAIN_PATH + 'training_set'\n",
|
| 383 |
+
"\n",
|
| 384 |
+
"train_loader, test_loader = load_data(\n",
|
| 385 |
+
" base_path=data_path,\n",
|
| 386 |
+
" batch_size=4, \n",
|
| 387 |
+
" num_workers=2,\n",
|
| 388 |
+
" test_size=0.2\n",
|
| 389 |
+
")\n",
|
| 390 |
+
"\n",
|
| 391 |
+
"model = MyModel()\n",
|
| 392 |
+
"if torch.cuda.is_available():\n",
|
| 393 |
+
" model = model.cuda()\n",
|
| 394 |
+
"\n",
|
| 395 |
+
"criterion = nn.CrossEntropyLoss()\n",
|
| 396 |
+
"optimizer = optim.Adam(model.parameters(), lr=0.001) \n",
|
| 397 |
+
"\n",
|
| 398 |
+
"train_losses, val_losses = train(\n",
|
| 399 |
+
" model=model,\n",
|
| 400 |
+
" train_loader=train_loader,\n",
|
| 401 |
+
" test_loader=test_loader,\n",
|
| 402 |
+
" optimizer=optimizer,\n",
|
| 403 |
+
" criterion=criterion,\n",
|
| 404 |
+
" num_epochs=40\n",
|
| 405 |
+
")"
|
| 406 |
+
]
|
| 407 |
+
},
|
| 408 |
+
{
|
| 409 |
+
"cell_type": "markdown",
|
| 410 |
+
"metadata": {},
|
| 411 |
+
"source": [
|
| 412 |
+
"### Generate CSV for Submission"
|
| 413 |
+
]
|
| 414 |
+
},
|
| 415 |
+
{
|
| 416 |
+
"cell_type": "code",
|
| 417 |
+
"execution_count": null,
|
| 418 |
+
"metadata": {},
|
| 419 |
+
"outputs": [],
|
| 420 |
+
"source": [
|
| 421 |
+
"# Run inference on validation set and testing set\n",
|
| 422 |
+
"from torch.utils.data import DataLoader\n",
|
| 423 |
+
"import pandas as pd\n",
|
| 424 |
+
"\n",
|
| 425 |
+
"def run_inference(model, data_loader):\n",
|
| 426 |
+
" \"\"\"Run inference and return predictions with filenames\"\"\"\n",
|
| 427 |
+
" model.eval()\n",
|
| 428 |
+
" predictions = []\n",
|
| 429 |
+
" filenames = []\n",
|
| 430 |
+
" \n",
|
| 431 |
+
" with torch.no_grad():\n",
|
| 432 |
+
" for images, file_names in data_loader:\n",
|
| 433 |
+
" images = images.cuda() if torch.cuda.is_available() else images\n",
|
| 434 |
+
" \n",
|
| 435 |
+
" outputs = model(images)\n",
|
| 436 |
+
" preds = torch.argmax(outputs, dim=1)\n",
|
| 437 |
+
" \n",
|
| 438 |
+
" # Convert predictions back to original label range [-1, 3]\n",
|
| 439 |
+
" preds = preds - 1\n",
|
| 440 |
+
" \n",
|
| 441 |
+
" # Flatten predictions for each sample\n",
|
| 442 |
+
" for i, pred in enumerate(preds):\n",
|
| 443 |
+
" predictions.append(pred.cpu().numpy().flatten())\n",
|
| 444 |
+
" filenames.append(file_names[i])\n",
|
| 445 |
+
" \n",
|
| 446 |
+
" return predictions, filenames\n",
|
| 447 |
+
"\n",
|
| 448 |
+
"#DATA_PATH is the secret environment variable to point the address of the validation set and test set on the testing machine. \n",
|
| 449 |
+
"#You cannot access this address locally.\n",
|
| 450 |
+
"if os.environ.get('DATA_PATH'):\n",
|
| 451 |
+
" DATA_PATH = os.environ.get(\"DATA_PATH\") + \"/\" \n",
|
| 452 |
+
"else:\n",
|
| 453 |
+
" DATA_PATH = \"\" # Fallback for local testing\n",
|
| 454 |
+
"# Load validation set\n",
|
| 455 |
+
"val_paths = generate_file_paths(DATA_PATH + 'validation_set')\n",
|
| 456 |
+
"val_dataset = CustomDataset_test(file_paths=val_paths)\n",
|
| 457 |
+
"val_loader = DataLoader(\n",
|
| 458 |
+
" val_dataset,\n",
|
| 459 |
+
" batch_size=1,\n",
|
| 460 |
+
" shuffle=False,\n",
|
| 461 |
+
" num_workers=2\n",
|
| 462 |
+
")\n",
|
| 463 |
+
"\n",
|
| 464 |
+
"# Load testing set\n",
|
| 465 |
+
"test_paths = generate_file_paths(DATA_PATH + 'testing_set')\n",
|
| 466 |
+
"test_dataset = CustomDataset_test(file_paths=test_paths)\n",
|
| 467 |
+
"test_loader = DataLoader(\n",
|
| 468 |
+
" test_dataset,\n",
|
| 469 |
+
" batch_size=1,\n",
|
| 470 |
+
" shuffle=False,\n",
|
| 471 |
+
" num_workers=2\n",
|
| 472 |
+
")\n",
|
| 473 |
+
"\n",
|
| 474 |
+
"# Run inference on validation set\n",
|
| 475 |
+
"print(\"Running inference on validation set...\")\n",
|
| 476 |
+
"val_predictions, val_filenames = run_inference(model, val_loader)\n",
|
| 477 |
+
"\n",
|
| 478 |
+
"# Save validation results to CSV\n",
|
| 479 |
+
"val_results = []\n",
|
| 480 |
+
"for filename, pred in zip(val_filenames, val_predictions):\n",
|
| 481 |
+
" # Create a row with filename and flattened predictions\n",
|
| 482 |
+
" row = {'filename': filename}\n",
|
| 483 |
+
" for i, p in enumerate(pred):\n",
|
| 484 |
+
" row[f'pixel_{i}'] = p\n",
|
| 485 |
+
" val_results.append(row)\n",
|
| 486 |
+
"\n",
|
| 487 |
+
"val_df = pd.DataFrame(val_results)\n",
|
| 488 |
+
"val_df.to_csv('submission_val.csv', index=False)\n",
|
| 489 |
+
"print(f\"Validation results saved to output_validation.csv with shape: {val_df.shape}\")\n",
|
| 490 |
+
"\n",
|
| 491 |
+
"# Run inference on testing set\n",
|
| 492 |
+
"print(\"Running inference on testing set...\")\n",
|
| 493 |
+
"test_predictions, test_filenames = run_inference(model, test_loader)\n",
|
| 494 |
+
"\n",
|
| 495 |
+
"# Save testing results to CSV\n",
|
| 496 |
+
"test_results = []\n",
|
| 497 |
+
"for filename, pred in zip(test_filenames, test_predictions):\n",
|
| 498 |
+
" # Create a row with filename and flattened predictions\n",
|
| 499 |
+
" row = {'filename': filename}\n",
|
| 500 |
+
" for i, p in enumerate(pred):\n",
|
| 501 |
+
" row[f'pixel_{i}'] = p\n",
|
| 502 |
+
" test_results.append(row)\n",
|
| 503 |
+
"\n",
|
| 504 |
+
"test_df = pd.DataFrame(test_results)\n",
|
| 505 |
+
"test_df.to_csv('submission_test.csv', index=False)\n",
|
| 506 |
+
"print(f\"Testing results saved to output_testing.csv with shape: {test_df.shape}\")\n",
|
| 507 |
+
"\n",
|
| 508 |
+
"print(\"\\nInference completed! Results saved to:\")\n",
|
| 509 |
+
"print(\"- submission_val.csv (for validation set leaderboard)\")\n",
|
| 510 |
+
"print(\"- submission_test.csv (for testing set leaderboard)\")"
|
| 511 |
+
]
|
| 512 |
+
},
|
| 513 |
+
{
|
| 514 |
+
"cell_type": "markdown",
|
| 515 |
+
"metadata": {},
|
| 516 |
+
"source": [
|
| 517 |
+
"### Create .zip File"
|
| 518 |
+
]
|
| 519 |
+
},
|
| 520 |
+
{
|
| 521 |
+
"cell_type": "code",
|
| 522 |
+
"execution_count": null,
|
| 523 |
+
"metadata": {},
|
| 524 |
+
"outputs": [],
|
| 525 |
+
"source": [
|
| 526 |
+
"import zipfile\n",
|
| 527 |
+
"import os\n",
|
| 528 |
+
"\n",
|
| 529 |
+
"# Define the files to zip and the zip file name.\n",
|
| 530 |
+
"files_to_zip = ['submission_val.csv', 'submission_test.csv']\n",
|
| 531 |
+
"zip_filename = 'submission.zip'\n",
|
| 532 |
+
"\n",
|
| 533 |
+
"# Create a zip file\n",
|
| 534 |
+
"with zipfile.ZipFile(zip_filename, 'w') as zipf:\n",
|
| 535 |
+
" for file in files_to_zip:\n",
|
| 536 |
+
" # Add the file to the zip fil\n",
|
| 537 |
+
" zipf.write(file, os.path.basename(file))\n",
|
| 538 |
+
"\n",
|
| 539 |
+
"print(f'{zip_filename} Created successfully!')"
|
| 540 |
+
]
|
| 541 |
+
}
|
| 542 |
+
],
|
| 543 |
+
"metadata": {
|
| 544 |
+
"kernelspec": {
|
| 545 |
+
"display_name": "Python 3 (ipykernel)",
|
| 546 |
+
"language": "python",
|
| 547 |
+
"name": "python3"
|
| 548 |
+
},
|
| 549 |
+
"language_info": {
|
| 550 |
+
"codemirror_mode": {
|
| 551 |
+
"name": "ipython",
|
| 552 |
+
"version": 3
|
| 553 |
+
},
|
| 554 |
+
"file_extension": ".py",
|
| 555 |
+
"mimetype": "text/x-python",
|
| 556 |
+
"name": "python",
|
| 557 |
+
"nbconvert_exporter": "python",
|
| 558 |
+
"pygments_lexer": "ipython3",
|
| 559 |
+
"version": "3.12.9"
|
| 560 |
+
}
|
| 561 |
+
},
|
| 562 |
+
"nbformat": 4,
|
| 563 |
+
"nbformat_minor": 4
|
| 564 |
+
}
|
Individual-Contest/Radar/Solution/.DS_Store
ADDED
|
Binary file (6.15 kB). View file
|
|
|
Individual-Contest/Radar/Solution/Radar_Solution.ipynb
ADDED
|
@@ -0,0 +1,1056 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "markdown",
|
| 5 |
+
"id": "ab23242e-3c5e-4ba6-9cb9-dfc4d8c22321",
|
| 6 |
+
"metadata": {},
|
| 7 |
+
"source": [
|
| 8 |
+
"<img src=\"./figs/IOAI-Logo.png\" alt=\"IOAI Logo\" width=\"200\" height=\"auto\">\n",
|
| 9 |
+
"\n",
|
| 10 |
+
"[IOAI 2025 (Beijing, China), Individual Contest](https://ioai-official.org/china-2025)\n",
|
| 11 |
+
"\n",
|
| 12 |
+
"[](https://colab.research.google.com/github/IOAI-official/IOAI-2025/blob/main/Individual-Contest/Radar/Solution/Radar_Solution.ipynb)"
|
| 13 |
+
]
|
| 14 |
+
},
|
| 15 |
+
{
|
| 16 |
+
"cell_type": "markdown",
|
| 17 |
+
"id": "f2ea67c2-ec81-4ced-b8a4-a19b591376bb",
|
| 18 |
+
"metadata": {},
|
| 19 |
+
"source": [
|
| 20 |
+
"# Radar: Reference Solution"
|
| 21 |
+
]
|
| 22 |
+
},
|
| 23 |
+
{
|
| 24 |
+
"cell_type": "markdown",
|
| 25 |
+
"id": "97ae6685",
|
| 26 |
+
"metadata": {},
|
| 27 |
+
"source": [
|
| 28 |
+
"## Configs"
|
| 29 |
+
]
|
| 30 |
+
},
|
| 31 |
+
{
|
| 32 |
+
"cell_type": "code",
|
| 33 |
+
"execution_count": null,
|
| 34 |
+
"id": "4243ca5d",
|
| 35 |
+
"metadata": {
|
| 36 |
+
"jupyter": {
|
| 37 |
+
"source_hidden": false
|
| 38 |
+
}
|
| 39 |
+
},
|
| 40 |
+
"outputs": [],
|
| 41 |
+
"source": [
|
| 42 |
+
"radar_configs = {\n",
|
| 43 |
+
" 'c': 3e8, \n",
|
| 44 |
+
" 'startFreq': 77e9, \n",
|
| 45 |
+
" 'Tr': 60e-6, # Sweeping frequency time\n",
|
| 46 |
+
" 'Idle_time': 100e-6, # free time\n",
|
| 47 |
+
" 'Fs': 10e6, # Sampling frequency\n",
|
| 48 |
+
" 'Slope': 29.982e12, # chirp slope\n",
|
| 49 |
+
" 'Bandwidth': 60e-6 * 29.982e12, # Transmission signal bandwidth\n",
|
| 50 |
+
" 'BandwidthValid': 0.767539200e9,# Effective bandwidth of the transmitted signal\n",
|
| 51 |
+
" 'range_size': 256, # range size\n",
|
| 52 |
+
" 'azimuth_size': 181, # azimuth size\n",
|
| 53 |
+
" 'elevation_size': 181, # elevation size\n",
|
| 54 |
+
" 'crop_num': 3, # crop some indices in range domain\n",
|
| 55 |
+
" 'n_chirps': 128, # number of chirps in one frame\n",
|
| 56 |
+
" 'min_azimuth': -90, # min radar azimuth\n",
|
| 57 |
+
" 'max_azimuth': 90, # max radar azimuth\n",
|
| 58 |
+
" 'min_elevation': -90, # min radar elevation\n",
|
| 59 |
+
" 'max_elevation': 90, # max radar elevation \n",
|
| 60 |
+
" 'min_range': 1.0, # min radar range\n",
|
| 61 |
+
" 'max_range': 25.0, # max radar range\n",
|
| 62 |
+
" 'range_res': 3e8/(2*0.767539200e9), \n",
|
| 63 |
+
" 'angle_res': 1\n",
|
| 64 |
+
"}\n",
|
| 65 |
+
"\n",
|
| 66 |
+
"dimssnet_configs = {\n",
|
| 67 |
+
" 'n_epoch': 10,\n",
|
| 68 |
+
" 'batch_size': 2,\n",
|
| 69 |
+
" 'learning_rate': 1e-5,\n",
|
| 70 |
+
" 'range_size': 50,\n",
|
| 71 |
+
" 'azimuth_size': 181,\n",
|
| 72 |
+
" 'elevation_size': 181,\n",
|
| 73 |
+
" 'doppler_size': 181, \n",
|
| 74 |
+
" 'min_azimuth': -90, # min radar azimuth\n",
|
| 75 |
+
" 'max_azimuth': 90, # max radar azimuth\n",
|
| 76 |
+
" 'min_elevation': -90, # min radar elevation\n",
|
| 77 |
+
" 'max_elevation': 90, # max radar elevation \n",
|
| 78 |
+
" 'min_range': 1.0, # min radar range\n",
|
| 79 |
+
" 'max_range': 25.0, # max radar range\n",
|
| 80 |
+
"}\n",
|
| 81 |
+
"\n",
|
| 82 |
+
"n_class = 5\n",
|
| 83 |
+
"class_table = {\n",
|
| 84 |
+
" -1: 'background', \n",
|
| 85 |
+
" 0: 'suicase', \n",
|
| 86 |
+
" 1: 'chair', \n",
|
| 87 |
+
" 2: 'person',\n",
|
| 88 |
+
" 3: 'wall'\n",
|
| 89 |
+
"}"
|
| 90 |
+
]
|
| 91 |
+
},
|
| 92 |
+
{
|
| 93 |
+
"cell_type": "markdown",
|
| 94 |
+
"id": "c39a54f5",
|
| 95 |
+
"metadata": {},
|
| 96 |
+
"source": [
|
| 97 |
+
"## Models"
|
| 98 |
+
]
|
| 99 |
+
},
|
| 100 |
+
{
|
| 101 |
+
"cell_type": "code",
|
| 102 |
+
"execution_count": null,
|
| 103 |
+
"id": "10817ce8",
|
| 104 |
+
"metadata": {
|
| 105 |
+
"jupyter": {
|
| 106 |
+
"source_hidden": false
|
| 107 |
+
}
|
| 108 |
+
},
|
| 109 |
+
"outputs": [],
|
| 110 |
+
"source": [
|
| 111 |
+
"import torch\n",
|
| 112 |
+
"import torch.nn as nn\n",
|
| 113 |
+
"import torch.nn.functional as F\n",
|
| 114 |
+
"\n",
|
| 115 |
+
"class SRA_Encode(nn.Module):\n",
|
| 116 |
+
" def __init__(self):\n",
|
| 117 |
+
" super(SRA_Encode, self).__init__()\n",
|
| 118 |
+
" self.conv1a = nn.Conv2d(in_channels=1, out_channels=64, \n",
|
| 119 |
+
" kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n",
|
| 120 |
+
" self.conv1b = nn.Conv2d(in_channels=64, out_channels=64, \n",
|
| 121 |
+
" kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))\n",
|
| 122 |
+
" self.conv2a = nn.Conv2d(in_channels=64, out_channels=128, \n",
|
| 123 |
+
" kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n",
|
| 124 |
+
" self.conv2b = nn.Conv2d(in_channels=128, out_channels=128, \n",
|
| 125 |
+
" kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))\n",
|
| 126 |
+
" self.conv3a = nn.Conv2d(in_channels=128, out_channels=256, \n",
|
| 127 |
+
" kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n",
|
| 128 |
+
" self.conv3b = nn.Conv2d(in_channels=256, out_channels=256, \n",
|
| 129 |
+
" kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))\n",
|
| 130 |
+
"\n",
|
| 131 |
+
" self.bn1a = nn.BatchNorm2d(num_features=64)\n",
|
| 132 |
+
" self.bn1b = nn.BatchNorm2d(num_features=64)\n",
|
| 133 |
+
" self.bn2a = nn.BatchNorm2d(num_features=128)\n",
|
| 134 |
+
" self.bn2b = nn.BatchNorm2d(num_features=128)\n",
|
| 135 |
+
" self.bn3a = nn.BatchNorm2d(num_features=256)\n",
|
| 136 |
+
" self.bn3b = nn.BatchNorm2d(num_features=256)\n",
|
| 137 |
+
"\n",
|
| 138 |
+
" self.relu = nn.ReLU()\n",
|
| 139 |
+
" \n",
|
| 140 |
+
" def forward(self, x):\n",
|
| 141 |
+
" x = self.relu(self.bn1a(self.conv1a(x)))\n",
|
| 142 |
+
" x = self.relu(self.bn1b(self.conv1b(x)))\n",
|
| 143 |
+
" x = self.relu(self.bn2a(self.conv2a(x)))\n",
|
| 144 |
+
" x = self.relu(self.bn2b(self.conv2b(x)))\n",
|
| 145 |
+
" x = self.relu(self.bn3a(self.conv3a(x)))\n",
|
| 146 |
+
" x = self.relu(self.bn3b(self.conv3b(x)))\n",
|
| 147 |
+
" \n",
|
| 148 |
+
" return x\n",
|
| 149 |
+
"\n",
|
| 150 |
+
"class SRA_Decode(nn.Module):\n",
|
| 151 |
+
" def __init__(self):\n",
|
| 152 |
+
" super(SRA_Decode, self).__init__()\n",
|
| 153 |
+
" self.convt1 = nn.ConvTranspose2d(in_channels=256, out_channels=128,\n",
|
| 154 |
+
" kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))\n",
|
| 155 |
+
" self.convt2 = nn.ConvTranspose2d(in_channels=128, out_channels=64,\n",
|
| 156 |
+
" kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))\n",
|
| 157 |
+
" self.convt3 = nn.ConvTranspose2d(in_channels=64, out_channels=32,\n",
|
| 158 |
+
" kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))\n",
|
| 159 |
+
" self.prelu = nn.PReLU()\n",
|
| 160 |
+
" self.sigmoid = nn.Sigmoid()\n",
|
| 161 |
+
" self.upsample = nn.Upsample(size=(dimssnet_configs['range_size'],\n",
|
| 162 |
+
" dimssnet_configs['azimuth_size']), mode='nearest')\n",
|
| 163 |
+
"\n",
|
| 164 |
+
" def forward(self, x):\n",
|
| 165 |
+
" x = self.prelu(self.convt1(x))\n",
|
| 166 |
+
" x = self.prelu(self.convt2(x))\n",
|
| 167 |
+
" x = self.prelu(self.convt3(x))\n",
|
| 168 |
+
"\n",
|
| 169 |
+
" return x\n",
|
| 170 |
+
"\n",
|
| 171 |
+
"class DRA_Encode(nn.Module):\n",
|
| 172 |
+
" def __init__(self):\n",
|
| 173 |
+
" super(DRA_Encode, self).__init__()\n",
|
| 174 |
+
" self.conv1a = nn.Conv2d(in_channels=1, out_channels=64, \n",
|
| 175 |
+
" kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)) # (1 50 181)->(64 50 181)\n",
|
| 176 |
+
" self.conv1b = nn.Conv2d(in_channels=64, out_channels=64, \n",
|
| 177 |
+
" kernel_size=(3, 3), stride=(2, 2), padding=(1, 1)) # (64 50 181)->(64 25 91)\n",
|
| 178 |
+
" self.conv2a = nn.Conv2d(in_channels=64, out_channels=128, \n",
|
| 179 |
+
" kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)) # (64 25 91)->(128 25 91)\n",
|
| 180 |
+
" self.conv2b = nn.Conv2d(in_channels=128, out_channels=128, \n",
|
| 181 |
+
" kernel_size=(3, 3), stride=(2, 2), padding=(1, 1)) # (128 25 91)->(128 13 46)\n",
|
| 182 |
+
" self.conv3a = nn.Conv2d(in_channels=128, out_channels=256, \n",
|
| 183 |
+
" kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)) # (128 13 46)->(256 13 46)\n",
|
| 184 |
+
" self.conv3b = nn.Conv2d(in_channels=256, out_channels=256, \n",
|
| 185 |
+
" kernel_size=(3, 3), stride=(2, 2), padding=(1, 1)) # (256 13 46)->(256 7 23)\n",
|
| 186 |
+
"\n",
|
| 187 |
+
" self.bn1a = nn.BatchNorm2d(num_features=64)\n",
|
| 188 |
+
" self.bn1b = nn.BatchNorm2d(num_features=64)\n",
|
| 189 |
+
" self.bn2a = nn.BatchNorm2d(num_features=128)\n",
|
| 190 |
+
" self.bn2b = nn.BatchNorm2d(num_features=128)\n",
|
| 191 |
+
" self.bn3a = nn.BatchNorm2d(num_features=256)\n",
|
| 192 |
+
" self.bn3b = nn.BatchNorm2d(num_features=256)\n",
|
| 193 |
+
"\n",
|
| 194 |
+
" self.relu = nn.ReLU()\n",
|
| 195 |
+
" \n",
|
| 196 |
+
" def forward(self, x):\n",
|
| 197 |
+
" x = self.relu(self.bn1a(self.conv1a(x)))\n",
|
| 198 |
+
" x = self.relu(self.bn1b(self.conv1b(x)))\n",
|
| 199 |
+
" x = self.relu(self.bn2a(self.conv2a(x)))\n",
|
| 200 |
+
" x = self.relu(self.bn2b(self.conv2b(x)))\n",
|
| 201 |
+
" x = self.relu(self.bn3a(self.conv3a(x)))\n",
|
| 202 |
+
" x = self.relu(self.bn3b(self.conv3b(x)))\n",
|
| 203 |
+
"\n",
|
| 204 |
+
" return x\n",
|
| 205 |
+
"\n",
|
| 206 |
+
"class DRA_Decode(nn.Module):\n",
|
| 207 |
+
" def __init__(self):\n",
|
| 208 |
+
" super(DRA_Decode, self).__init__()\n",
|
| 209 |
+
" self.convt1 = nn.ConvTranspose2d(in_channels=256, out_channels=128,\n",
|
| 210 |
+
" kernel_size=(3, 3), stride=(2, 2), padding=(1, 1)) # (256 7 23)->(128 13 45)\n",
|
| 211 |
+
" self.convt2 = nn.ConvTranspose2d(in_channels=128, out_channels=64,\n",
|
| 212 |
+
" kernel_size=(3, 3), stride=(2, 2), padding=(1, 1)) # (128 13 45)->(64 25 89)\n",
|
| 213 |
+
" self.convt3 = nn.ConvTranspose2d(in_channels=64, out_channels=32,\n",
|
| 214 |
+
" kernel_size=(3, 3), stride=(2, 2), padding=(1, 1)) # (64 25 89)->(32 49 177)\n",
|
| 215 |
+
" self.prelu = nn.PReLU()\n",
|
| 216 |
+
" self.sigmoid = nn.Sigmoid()\n",
|
| 217 |
+
" self.upsample = nn.Upsample(size=(dimssnet_configs['range_size'],\n",
|
| 218 |
+
" dimssnet_configs['elevation_size']), mode='nearest')\n",
|
| 219 |
+
"\n",
|
| 220 |
+
" def forward(self, x):\n",
|
| 221 |
+
" x = self.prelu(self.convt1(x))\n",
|
| 222 |
+
" x = self.prelu(self.convt2(x))\n",
|
| 223 |
+
" x = self.prelu(self.convt3(x))\n",
|
| 224 |
+
"\n",
|
| 225 |
+
" return x\n",
|
| 226 |
+
"\n",
|
| 227 |
+
"class SRE_Encode(nn.Module):\n",
|
| 228 |
+
" def __init__(self):\n",
|
| 229 |
+
" super(SRE_Encode, self).__init__()\n",
|
| 230 |
+
" self.conv1a = nn.Conv2d(in_channels=1, out_channels=64, \n",
|
| 231 |
+
" kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n",
|
| 232 |
+
" self.conv1b = nn.Conv2d(in_channels=64, out_channels=64, \n",
|
| 233 |
+
" kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))\n",
|
| 234 |
+
" self.conv2a = nn.Conv2d(in_channels=64, out_channels=128, \n",
|
| 235 |
+
" kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n",
|
| 236 |
+
" self.conv2b = nn.Conv2d(in_channels=128, out_channels=128, \n",
|
| 237 |
+
" kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))\n",
|
| 238 |
+
" self.conv3a = nn.Conv2d(in_channels=128, out_channels=256, \n",
|
| 239 |
+
" kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n",
|
| 240 |
+
" self.conv3b = nn.Conv2d(in_channels=256, out_channels=256, \n",
|
| 241 |
+
" kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))\n",
|
| 242 |
+
"\n",
|
| 243 |
+
" self.bn1a = nn.BatchNorm2d(num_features=64)\n",
|
| 244 |
+
" self.bn1b = nn.BatchNorm2d(num_features=64)\n",
|
| 245 |
+
" self.bn2a = nn.BatchNorm2d(num_features=128)\n",
|
| 246 |
+
" self.bn2b = nn.BatchNorm2d(num_features=128)\n",
|
| 247 |
+
" self.bn3a = nn.BatchNorm2d(num_features=256)\n",
|
| 248 |
+
" self.bn3b = nn.BatchNorm2d(num_features=256)\n",
|
| 249 |
+
"\n",
|
| 250 |
+
" self.relu = nn.ReLU()\n",
|
| 251 |
+
" \n",
|
| 252 |
+
" def forward(self, x):\n",
|
| 253 |
+
" x = self.relu(self.bn1a(self.conv1a(x)))\n",
|
| 254 |
+
" x = self.relu(self.bn1b(self.conv1b(x)))\n",
|
| 255 |
+
" x = self.relu(self.bn2a(self.conv2a(x)))\n",
|
| 256 |
+
" x = self.relu(self.bn2b(self.conv2b(x)))\n",
|
| 257 |
+
" x = self.relu(self.bn3a(self.conv3a(x)))\n",
|
| 258 |
+
" x = self.relu(self.bn3b(self.conv3b(x)))\n",
|
| 259 |
+
"\n",
|
| 260 |
+
" return x\n",
|
| 261 |
+
"\n",
|
| 262 |
+
"class SRE_Decode(nn.Module):\n",
|
| 263 |
+
" def __init__(self):\n",
|
| 264 |
+
" super(SRE_Decode, self).__init__()\n",
|
| 265 |
+
" self.convt1 = nn.ConvTranspose2d(in_channels=256, out_channels=128,\n",
|
| 266 |
+
" kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))\n",
|
| 267 |
+
" self.convt2 = nn.ConvTranspose2d(in_channels=128, out_channels=64,\n",
|
| 268 |
+
" kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))\n",
|
| 269 |
+
" self.convt3 = nn.ConvTranspose2d(in_channels=64, out_channels=32,\n",
|
| 270 |
+
" kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))\n",
|
| 271 |
+
" self.prelu = nn.PReLU()\n",
|
| 272 |
+
" self.sigmoid = nn.Sigmoid()\n",
|
| 273 |
+
" self.upsample = nn.Upsample(size=(dimssnet_configs['range_size'],\n",
|
| 274 |
+
" dimssnet_configs['elevation_size']), mode='nearest')\n",
|
| 275 |
+
"\n",
|
| 276 |
+
" def forward(self, x):\n",
|
| 277 |
+
" x = self.prelu(self.convt1(x))\n",
|
| 278 |
+
" x = self.prelu(self.convt2(x))\n",
|
| 279 |
+
" x = self.prelu(self.convt3(x))\n",
|
| 280 |
+
"\n",
|
| 281 |
+
" return x\n",
|
| 282 |
+
" \n",
|
| 283 |
+
"class DRE_Encode(nn.Module):\n",
|
| 284 |
+
" def __init__(self):\n",
|
| 285 |
+
" super(DRE_Encode, self).__init__()\n",
|
| 286 |
+
" self.conv1a = nn.Conv2d(in_channels=1, out_channels=64, \n",
|
| 287 |
+
" kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n",
|
| 288 |
+
" self.conv1b = nn.Conv2d(in_channels=64, out_channels=64, \n",
|
| 289 |
+
" kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))\n",
|
| 290 |
+
" self.conv2a = nn.Conv2d(in_channels=64, out_channels=128, \n",
|
| 291 |
+
" kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n",
|
| 292 |
+
" self.conv2b = nn.Conv2d(in_channels=128, out_channels=128, \n",
|
| 293 |
+
" kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))\n",
|
| 294 |
+
" self.conv3a = nn.Conv2d(in_channels=128, out_channels=256, \n",
|
| 295 |
+
" kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n",
|
| 296 |
+
" self.conv3b = nn.Conv2d(in_channels=256, out_channels=256, \n",
|
| 297 |
+
" kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))\n",
|
| 298 |
+
"\n",
|
| 299 |
+
" self.bn1a = nn.BatchNorm2d(num_features=64)\n",
|
| 300 |
+
" self.bn1b = nn.BatchNorm2d(num_features=64)\n",
|
| 301 |
+
" self.bn2a = nn.BatchNorm2d(num_features=128)\n",
|
| 302 |
+
" self.bn2b = nn.BatchNorm2d(num_features=128)\n",
|
| 303 |
+
" self.bn3a = nn.BatchNorm2d(num_features=256)\n",
|
| 304 |
+
" self.bn3b = nn.BatchNorm2d(num_features=256)\n",
|
| 305 |
+
"\n",
|
| 306 |
+
" self.relu = nn.ReLU()\n",
|
| 307 |
+
" \n",
|
| 308 |
+
" def forward(self, x):\n",
|
| 309 |
+
" x = self.relu(self.bn1a(self.conv1a(x)))\n",
|
| 310 |
+
" x = self.relu(self.bn1b(self.conv1b(x)))\n",
|
| 311 |
+
" x = self.relu(self.bn2a(self.conv2a(x)))\n",
|
| 312 |
+
" x = self.relu(self.bn2b(self.conv2b(x)))\n",
|
| 313 |
+
" x = self.relu(self.bn3a(self.conv3a(x)))\n",
|
| 314 |
+
" x = self.relu(self.bn3b(self.conv3b(x)))\n",
|
| 315 |
+
"\n",
|
| 316 |
+
" return x\n",
|
| 317 |
+
"\n",
|
| 318 |
+
"class DRE_Decode(nn.Module):\n",
|
| 319 |
+
" def __init__(self):\n",
|
| 320 |
+
" super(DRE_Decode, self).__init__()\n",
|
| 321 |
+
" self.convt1 = nn.ConvTranspose2d(in_channels=256, out_channels=128,\n",
|
| 322 |
+
" kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))\n",
|
| 323 |
+
" self.convt2 = nn.ConvTranspose2d(in_channels=128, out_channels=64,\n",
|
| 324 |
+
" kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))\n",
|
| 325 |
+
" self.convt3 = nn.ConvTranspose2d(in_channels=64, out_channels=32,\n",
|
| 326 |
+
" kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))\n",
|
| 327 |
+
" self.prelu = nn.PReLU()\n",
|
| 328 |
+
" self.sigmoid = nn.Sigmoid()\n",
|
| 329 |
+
" self.upsample = nn.Upsample(size=(dimssnet_configs['range_size'],\n",
|
| 330 |
+
" dimssnet_configs['elevation_size']), mode='nearest')\n",
|
| 331 |
+
"\n",
|
| 332 |
+
" def forward(self, x):\n",
|
| 333 |
+
" x = self.prelu(self.convt1(x))\n",
|
| 334 |
+
" x = self.prelu(self.convt2(x))\n",
|
| 335 |
+
" x = self.prelu(self.convt3(x))\n",
|
| 336 |
+
"\n",
|
| 337 |
+
" return x\n",
|
| 338 |
+
" \n",
|
| 339 |
+
"class SRD_Encode(nn.Module):\n",
|
| 340 |
+
" def __init__(self):\n",
|
| 341 |
+
" super(SRD_Encode, self).__init__()\n",
|
| 342 |
+
" self.conv1a = nn.Conv2d(in_channels=1, out_channels=64, \n",
|
| 343 |
+
" kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n",
|
| 344 |
+
" self.conv1b = nn.Conv2d(in_channels=64, out_channels=64, \n",
|
| 345 |
+
" kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))\n",
|
| 346 |
+
" self.conv2a = nn.Conv2d(in_channels=64, out_channels=128, \n",
|
| 347 |
+
" kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n",
|
| 348 |
+
" self.conv2b = nn.Conv2d(in_channels=128, out_channels=128, \n",
|
| 349 |
+
" kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))\n",
|
| 350 |
+
" self.conv3a = nn.Conv2d(in_channels=128, out_channels=256, \n",
|
| 351 |
+
" kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n",
|
| 352 |
+
" self.conv3b = nn.Conv2d(in_channels=256, out_channels=256, \n",
|
| 353 |
+
" kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))\n",
|
| 354 |
+
"\n",
|
| 355 |
+
" self.bn1a = nn.BatchNorm2d(num_features=64)\n",
|
| 356 |
+
" self.bn1b = nn.BatchNorm2d(num_features=64)\n",
|
| 357 |
+
" self.bn2a = nn.BatchNorm2d(num_features=128)\n",
|
| 358 |
+
" self.bn2b = nn.BatchNorm2d(num_features=128)\n",
|
| 359 |
+
" self.bn3a = nn.BatchNorm2d(num_features=256)\n",
|
| 360 |
+
" self.bn3b = nn.BatchNorm2d(num_features=256)\n",
|
| 361 |
+
"\n",
|
| 362 |
+
" self.relu = nn.ReLU()\n",
|
| 363 |
+
" \n",
|
| 364 |
+
" def forward(self, x):\n",
|
| 365 |
+
" x = self.relu(self.bn1a(self.conv1a(x)))\n",
|
| 366 |
+
" x = self.relu(self.bn1b(self.conv1b(x)))\n",
|
| 367 |
+
" x = self.relu(self.bn2a(self.conv2a(x)))\n",
|
| 368 |
+
" x = self.relu(self.bn2b(self.conv2b(x)))\n",
|
| 369 |
+
" x = self.relu(self.bn3a(self.conv3a(x)))\n",
|
| 370 |
+
" x = self.relu(self.bn3b(self.conv3b(x)))\n",
|
| 371 |
+
"\n",
|
| 372 |
+
" return x\n",
|
| 373 |
+
"\n",
|
| 374 |
+
"class SRD_Decode(nn.Module):\n",
|
| 375 |
+
" def __init__(self):\n",
|
| 376 |
+
" super(SRD_Decode, self).__init__()\n",
|
| 377 |
+
" self.convt1 = nn.ConvTranspose2d(in_channels=256, out_channels=128,\n",
|
| 378 |
+
" kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))\n",
|
| 379 |
+
" self.convt2 = nn.ConvTranspose2d(in_channels=128, out_channels=64,\n",
|
| 380 |
+
" kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))\n",
|
| 381 |
+
" self.convt3 = nn.ConvTranspose2d(in_channels=64, out_channels=32,\n",
|
| 382 |
+
" kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))\n",
|
| 383 |
+
" self.prelu = nn.PReLU()\n",
|
| 384 |
+
" self.sigmoid = nn.Sigmoid()\n",
|
| 385 |
+
" self.upsample = nn.Upsample(size=(dimssnet_configs['range_size'],\n",
|
| 386 |
+
" dimssnet_configs['doppler_size']), mode='nearest')\n",
|
| 387 |
+
"\n",
|
| 388 |
+
" def forward(self, x):\n",
|
| 389 |
+
" x = self.prelu(self.convt1(x))\n",
|
| 390 |
+
" x = self.prelu(self.convt2(x))\n",
|
| 391 |
+
" x = self.prelu(self.convt3(x))\n",
|
| 392 |
+
"\n",
|
| 393 |
+
" return x\n",
|
| 394 |
+
" \n",
|
| 395 |
+
"class DRD_Encode(nn.Module):\n",
|
| 396 |
+
" def __init__(self):\n",
|
| 397 |
+
" super(DRD_Encode, self).__init__()\n",
|
| 398 |
+
" self.conv1a = nn.Conv2d(in_channels=1, out_channels=64, \n",
|
| 399 |
+
" kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n",
|
| 400 |
+
" self.conv1b = nn.Conv2d(in_channels=64, out_channels=64, \n",
|
| 401 |
+
" kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))\n",
|
| 402 |
+
" self.conv2a = nn.Conv2d(in_channels=64, out_channels=128, \n",
|
| 403 |
+
" kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n",
|
| 404 |
+
" self.conv2b = nn.Conv2d(in_channels=128, out_channels=128, \n",
|
| 405 |
+
" kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))\n",
|
| 406 |
+
" self.conv3a = nn.Conv2d(in_channels=128, out_channels=256, \n",
|
| 407 |
+
" kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n",
|
| 408 |
+
" self.conv3b = nn.Conv2d(in_channels=256, out_channels=256, \n",
|
| 409 |
+
" kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))\n",
|
| 410 |
+
"\n",
|
| 411 |
+
" self.bn1a = nn.BatchNorm2d(num_features=64)\n",
|
| 412 |
+
" self.bn1b = nn.BatchNorm2d(num_features=64)\n",
|
| 413 |
+
" self.bn2a = nn.BatchNorm2d(num_features=128)\n",
|
| 414 |
+
" self.bn2b = nn.BatchNorm2d(num_features=128)\n",
|
| 415 |
+
" self.bn3a = nn.BatchNorm2d(num_features=256)\n",
|
| 416 |
+
" self.bn3b = nn.BatchNorm2d(num_features=256)\n",
|
| 417 |
+
"\n",
|
| 418 |
+
" self.relu = nn.ReLU()\n",
|
| 419 |
+
" \n",
|
| 420 |
+
" def forward(self, x):\n",
|
| 421 |
+
" x = self.relu(self.bn1a(self.conv1a(x)))\n",
|
| 422 |
+
" x = self.relu(self.bn1b(self.conv1b(x)))\n",
|
| 423 |
+
" x = self.relu(self.bn2a(self.conv2a(x)))\n",
|
| 424 |
+
" x = self.relu(self.bn2b(self.conv2b(x)))\n",
|
| 425 |
+
" x = self.relu(self.bn3a(self.conv3a(x)))\n",
|
| 426 |
+
" x = self.relu(self.bn3b(self.conv3b(x)))\n",
|
| 427 |
+
"\n",
|
| 428 |
+
" return x\n",
|
| 429 |
+
"\n",
|
| 430 |
+
"class DRD_Decode(nn.Module):\n",
|
| 431 |
+
" def __init__(self):\n",
|
| 432 |
+
" super(DRD_Decode, self).__init__()\n",
|
| 433 |
+
" self.convt1 = nn.ConvTranspose2d(in_channels=256, out_channels=128,\n",
|
| 434 |
+
" kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))\n",
|
| 435 |
+
" self.convt2 = nn.ConvTranspose2d(in_channels=128, out_channels=64,\n",
|
| 436 |
+
" kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))\n",
|
| 437 |
+
" self.convt3 = nn.ConvTranspose2d(in_channels=64, out_channels=32,\n",
|
| 438 |
+
" kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))\n",
|
| 439 |
+
" self.prelu = nn.PReLU()\n",
|
| 440 |
+
" self.sigmoid = nn.Sigmoid()\n",
|
| 441 |
+
" self.upsample = nn.Upsample(size=(dimssnet_configs['range_size'],\n",
|
| 442 |
+
" dimssnet_configs['doppler_size']), mode='nearest')\n",
|
| 443 |
+
"\n",
|
| 444 |
+
" def forward(self, x):\n",
|
| 445 |
+
" x = self.prelu(self.convt1(x))\n",
|
| 446 |
+
" x = self.prelu(self.convt2(x))\n",
|
| 447 |
+
" x = self.prelu(self.convt3(x))\n",
|
| 448 |
+
"\n",
|
| 449 |
+
" return x"
|
| 450 |
+
]
|
| 451 |
+
},
|
| 452 |
+
{
|
| 453 |
+
"cell_type": "code",
|
| 454 |
+
"execution_count": null,
|
| 455 |
+
"id": "483a5ba6",
|
| 456 |
+
"metadata": {
|
| 457 |
+
"jupyter": {
|
| 458 |
+
"source_hidden": false
|
| 459 |
+
}
|
| 460 |
+
},
|
| 461 |
+
"outputs": [],
|
| 462 |
+
"source": [
|
| 463 |
+
"class DIMSSNet(nn.Module):\n",
|
| 464 |
+
" def __init__(self):\n",
|
| 465 |
+
" super(DIMSSNet, self).__init__()\n",
|
| 466 |
+
" self.encode_sra = SRA_Encode()\n",
|
| 467 |
+
" self.decode_sra = SRA_Decode()\n",
|
| 468 |
+
" self.encode_dra = DRA_Encode()\n",
|
| 469 |
+
" self.decode_dra = DRA_Decode()\n",
|
| 470 |
+
" self.encode_sre = SRE_Encode()\n",
|
| 471 |
+
" self.decode_sre = SRE_Decode()\n",
|
| 472 |
+
" self.encode_dre = DRE_Encode()\n",
|
| 473 |
+
" self.decode_dre = DRE_Decode()\n",
|
| 474 |
+
" self.encode_srd = SRD_Encode()\n",
|
| 475 |
+
" self.decode_srd = SRD_Decode()\n",
|
| 476 |
+
" self.encode_drd = DRD_Encode()\n",
|
| 477 |
+
" self.decode_drd = DRD_Decode()\n",
|
| 478 |
+
" self.fuse_fea = Fuse_fea()\n",
|
| 479 |
+
" # self.fuse_fea = Fuse_fea_2D()\n",
|
| 480 |
+
" \n",
|
| 481 |
+
" def forward(self, x_sra, x_dra, x_sre, x_dre, x_srd, x_drd):\n",
|
| 482 |
+
" x_sra = self.encode_sra(x_sra)\n",
|
| 483 |
+
" feas_sra = self.decode_sra(x_sra) # (B, 32, 50, 181)\n",
|
| 484 |
+
" \n",
|
| 485 |
+
" x_dra = self.encode_dra(x_dra)\n",
|
| 486 |
+
" feas_dra = self.decode_dra(x_dra) # (B, 32, 50, 181)\n",
|
| 487 |
+
" \n",
|
| 488 |
+
" x_sre = self.encode_sre(x_sre)\n",
|
| 489 |
+
" feas_sre = self.decode_sre(x_sre) # (B, 32, 50, 181)\n",
|
| 490 |
+
" \n",
|
| 491 |
+
" x_dre = self.encode_dre(x_dre)\n",
|
| 492 |
+
" feas_dre = self.decode_dre(x_dre) # (B, 32, 50, 181)\n",
|
| 493 |
+
"\n",
|
| 494 |
+
" x_srd = self.encode_sre(x_srd)\n",
|
| 495 |
+
" feas_srd = self.decode_sre(x_srd) # (B, 32, 50, 181)\n",
|
| 496 |
+
" \n",
|
| 497 |
+
" x_drd = self.encode_dre(x_drd)\n",
|
| 498 |
+
" feas_drd = self.decode_dre(x_drd) # (B, 32, 50, 181) \n",
|
| 499 |
+
" \n",
|
| 500 |
+
" feas = self.fuse_fea(feas_sra, feas_dra, feas_sre, feas_dre, feas_srd, feas_drd) # (B, 32, 50, 181)\n",
|
| 501 |
+
"\n",
|
| 502 |
+
" return feas"
|
| 503 |
+
]
|
| 504 |
+
},
|
| 505 |
+
{
|
| 506 |
+
"cell_type": "code",
|
| 507 |
+
"execution_count": null,
|
| 508 |
+
"id": "ddb913e6",
|
| 509 |
+
"metadata": {
|
| 510 |
+
"jupyter": {
|
| 511 |
+
"source_hidden": false
|
| 512 |
+
}
|
| 513 |
+
},
|
| 514 |
+
"outputs": [],
|
| 515 |
+
"source": [
|
| 516 |
+
"range_size=radar_configs['range_size']\n",
|
| 517 |
+
"azimuth_size=radar_configs['azimuth_size']\n",
|
| 518 |
+
"elevation_size=radar_configs['elevation_size']\n",
|
| 519 |
+
"\n",
|
| 520 |
+
"class Fuse_fea(nn.Module):\n",
|
| 521 |
+
" def __init__(self):\n",
|
| 522 |
+
" super(Fuse_fea, self).__init__()\n",
|
| 523 |
+
" self.convt1 = nn.Conv2d(in_channels=192, out_channels=96,\n",
|
| 524 |
+
" kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n",
|
| 525 |
+
" self.convt2 = nn.Conv2d(in_channels=96, out_channels=48,\n",
|
| 526 |
+
" kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n",
|
| 527 |
+
" self.convt3 = nn.Conv2d(in_channels=48, out_channels=24,\n",
|
| 528 |
+
" kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n",
|
| 529 |
+
" self.convt4 = nn.Conv2d(in_channels=24, out_channels=n_class,\n",
|
| 530 |
+
" kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)) \n",
|
| 531 |
+
" self.relu = nn.ReLU()\n",
|
| 532 |
+
" self.sigmoid = nn.Sigmoid()\n",
|
| 533 |
+
"\n",
|
| 534 |
+
" def forward(self, feas_sra, feas_dra, feas_sre, feas_dre, feas_srd, feas_drd):\n",
|
| 535 |
+
" feas_sre = torch.sum(feas_sre, 3, keepdim=True) # (B, 32, 50, 181) -> (B, 32, 50, 1)\n",
|
| 536 |
+
" feas_sre = feas_sre.expand(-1, -1, -1, azimuth_size)\n",
|
| 537 |
+
" \n",
|
| 538 |
+
" feas_dre = torch.sum(feas_dre, 3, keepdim=True) # (B, 32, 50, 181) -> (B, 32, 50, 1)\n",
|
| 539 |
+
" feas_dre = feas_dre.expand(-1, -1, -1, azimuth_size)\n",
|
| 540 |
+
"\n",
|
| 541 |
+
" feas_srd = torch.sum(feas_srd, 3, keepdim=True) # (B, 32, 50, 181) -> (B, 32, 50, 1)\n",
|
| 542 |
+
" feas_srd = feas_srd.expand(-1, -1, -1, azimuth_size)\n",
|
| 543 |
+
"\n",
|
| 544 |
+
" feas_drd = torch.sum(feas_drd, 3, keepdim=True) # (B, 32, 50, 181) -> (B, 32, 50, 1)\n",
|
| 545 |
+
" feas_drd = feas_drd.expand(-1, -1, -1, azimuth_size)\n",
|
| 546 |
+
"\n",
|
| 547 |
+
" # Resize using bilinear interpolation\n",
|
| 548 |
+
" feas_sra = F.interpolate(feas_sra, size=(range_size, azimuth_size), mode='bilinear', align_corners=False)\n",
|
| 549 |
+
" feas_dra = F.interpolate(feas_dra, size=(range_size, azimuth_size), mode='bilinear', align_corners=False)\n",
|
| 550 |
+
" feas_sre = F.interpolate(feas_sre, size=(range_size, azimuth_size), mode='bilinear', align_corners=False)\n",
|
| 551 |
+
" feas_dre = F.interpolate(feas_dre, size=(range_size, azimuth_size), mode='bilinear', align_corners=False)\n",
|
| 552 |
+
" feas_srd = F.interpolate(feas_srd, size=(range_size, azimuth_size), mode='bilinear', align_corners=False)\n",
|
| 553 |
+
" feas_drd = F.interpolate(feas_drd, size=(range_size, azimuth_size), mode='bilinear', align_corners=False)\n",
|
| 554 |
+
" \n",
|
| 555 |
+
" feas_ra = torch.cat((feas_sra, feas_dra, feas_sre, feas_dre, feas_srd, feas_drd), 1) # 6*(B, 32, 50, 181) -> (B, 192, 50, 181)\n",
|
| 556 |
+
"\n",
|
| 557 |
+
" x = self.relu(self.convt1(feas_ra)) # (B, 192, 50, 181) -> (B, 96, 50, 181)\n",
|
| 558 |
+
" x = self.relu(self.convt2(x)) # (B, 96, 50, 181) -> (B, 48, 50, 181)\n",
|
| 559 |
+
" x = self.relu(self.convt3(x)) # (B, 48, 50, 181) -> (B, 24, 50, 181) \n",
|
| 560 |
+
" x = self.sigmoid(self.convt4(x)) # (B, 24, 50, 181) -> (B, 5, 50, 181)\n",
|
| 561 |
+
" \n",
|
| 562 |
+
" return x\n",
|
| 563 |
+
" "
|
| 564 |
+
]
|
| 565 |
+
},
|
| 566 |
+
{
|
| 567 |
+
"cell_type": "markdown",
|
| 568 |
+
"id": "b8d86ece",
|
| 569 |
+
"metadata": {},
|
| 570 |
+
"source": [
|
| 571 |
+
"## Utils"
|
| 572 |
+
]
|
| 573 |
+
},
|
| 574 |
+
{
|
| 575 |
+
"cell_type": "code",
|
| 576 |
+
"execution_count": null,
|
| 577 |
+
"id": "49705a8f",
|
| 578 |
+
"metadata": {
|
| 579 |
+
"jupyter": {
|
| 580 |
+
"source_hidden": false
|
| 581 |
+
}
|
| 582 |
+
},
|
| 583 |
+
"outputs": [],
|
| 584 |
+
"source": [
|
| 585 |
+
"import scipy.io\n",
|
| 586 |
+
"import numpy as np\n",
|
| 587 |
+
"\n",
|
| 588 |
+
"# Define the target size\n",
|
| 589 |
+
"TARGET_HEIGHT = 50\n",
|
| 590 |
+
"TARGET_WIDTH = 181\n",
|
| 591 |
+
"\n",
|
| 592 |
+
"def load_raw_data(file_path):\n",
|
| 593 |
+
" data = scipy.io.loadmat(file_path)\n",
|
| 594 |
+
"\n",
|
| 595 |
+
" # Range-Azimuth Static\n",
|
| 596 |
+
" range_az_static = data['range_az_static']\n",
|
| 597 |
+
" range_az_static_prob = data['range_az_music_average_static_probability']\n",
|
| 598 |
+
" range_az_static_class2_prob = range_az_static_prob[:, :, 1] # 椅子的概率\n",
|
| 599 |
+
"\n",
|
| 600 |
+
" # Range-Elevation Static\n",
|
| 601 |
+
" range_ele_static = data['range_ele_static_all']\n",
|
| 602 |
+
"\n",
|
| 603 |
+
" # Range-Azimuth Dynamic\n",
|
| 604 |
+
" range_az_dynamic = data['range_az_dynamic']\n",
|
| 605 |
+
" range_az_dynamic_prob = data['range_az_music_average_dynamic_probability']\n",
|
| 606 |
+
" range_az_dynamic_class1_prob = range_az_dynamic_prob[:, :, 0] # 人的概率\n",
|
| 607 |
+
"\n",
|
| 608 |
+
" # Range-Elevation Dynamic\n",
|
| 609 |
+
" range_ele_dynamic = data['range_ele_dynamic_all'] \n",
|
| 610 |
+
"\n",
|
| 611 |
+
" return [range_az_static, range_az_dynamic, range_ele_static,\n",
|
| 612 |
+
" range_ele_dynamic, range_az_dynamic_class1_prob, range_az_static_class2_prob]\n",
|
| 613 |
+
"\n",
|
| 614 |
+
"def generate_parameter():\n",
|
| 615 |
+
" parameter = {\n",
|
| 616 |
+
" 'c': 3e8, # the speed of light\n",
|
| 617 |
+
" 'start_freq': 77e9, # starting frequency\n",
|
| 618 |
+
" 'tr': 60e-6, # Sweeping time, that is, the cycle\n",
|
| 619 |
+
" 'samples': 256, # sampling point\n",
|
| 620 |
+
" 'fs': 10e6, # Sampling rate\n",
|
| 621 |
+
" 'tframe_set': 80e-3, # Frame period\n",
|
| 622 |
+
" 'range_bin': 256, # range bin\n",
|
| 623 |
+
" 'chirps': 128, # chirp number\n",
|
| 624 |
+
" 'doppler_bin': 128, # doppler bin\n",
|
| 625 |
+
" 'slope': 29.982e12, # chirp slope\n",
|
| 626 |
+
" 'bandwidth': 29.982e12 * 60e-6, # Effective bandwidth of the transmitted signal\n",
|
| 627 |
+
" 'bandwidth_valid': 256 / 10e6 * 29.982e12, # Transmission signal bandwidth\n",
|
| 628 |
+
" 'center_freq': 77e9 + (29.982e12 * 60e-6) / 2, # center frequency\n",
|
| 629 |
+
" 'lambda': 3e8 / (77e9 + (29.982e12 * 60e-6) / 2), # wavelength\n",
|
| 630 |
+
" 'tx_antenna': [1, 1, 1], # The number of transmitting antennas\n",
|
| 631 |
+
" 'rx_antenna': [1, 1, 1, 1], # Number of receiving antennas\n",
|
| 632 |
+
" 'tx_num': 3, # The number of transmitting antennas\n",
|
| 633 |
+
" 'rx_num': 4, # The number of receiving antennas\n",
|
| 634 |
+
" 'virtual_antenna': 12, # Number of virtual antennas\n",
|
| 635 |
+
" 'dz': (3e8 / (77e9 + (29.982e12 * 60e-6) / 2)) / 2, # Pitch spacing of the receiving antenna\n",
|
| 636 |
+
" 'dx': (3e8 / (77e9 + (29.982e12 * 60e-6) / 2)) / 2, # Horizontal spacing of receiving antennas\n",
|
| 637 |
+
" 'num_cpi': 50, # 帧数\n",
|
| 638 |
+
" }\n",
|
| 639 |
+
" return parameter\n",
|
| 640 |
+
"\n"
|
| 641 |
+
]
|
| 642 |
+
},
|
| 643 |
+
{
|
| 644 |
+
"cell_type": "markdown",
|
| 645 |
+
"id": "c266f24b",
|
| 646 |
+
"metadata": {},
|
| 647 |
+
"source": [
|
| 648 |
+
"## Dataloaders"
|
| 649 |
+
]
|
| 650 |
+
},
|
| 651 |
+
{
|
| 652 |
+
"cell_type": "code",
|
| 653 |
+
"execution_count": null,
|
| 654 |
+
"id": "892cfb3a",
|
| 655 |
+
"metadata": {},
|
| 656 |
+
"outputs": [],
|
| 657 |
+
"source": [
|
| 658 |
+
"import os\n",
|
| 659 |
+
"from torch.utils.data import Dataset, DataLoader\n",
|
| 660 |
+
"from sklearn.model_selection import train_test_split\n",
|
| 661 |
+
"\n",
|
| 662 |
+
"class CustomDataset(Dataset):\n",
|
| 663 |
+
" def __init__(self, file_paths, transform=None):\n",
|
| 664 |
+
" self.file_paths = file_paths\n",
|
| 665 |
+
" self.transform = transform\n",
|
| 666 |
+
" self.file_names = [os.path.basename(path) for path in file_paths]\n",
|
| 667 |
+
"\n",
|
| 668 |
+
" def __len__(self):\n",
|
| 669 |
+
" return len(self.file_paths)\n",
|
| 670 |
+
"\n",
|
| 671 |
+
" def __getitem__(self, idx):\n",
|
| 672 |
+
" data = torch.load(self.file_paths[idx], weights_only=True)\n",
|
| 673 |
+
" \n",
|
| 674 |
+
" images = data[:6] #first 6 channels are the heatmaps\n",
|
| 675 |
+
" labels = data[6] #last channel is the label\n",
|
| 676 |
+
" \n",
|
| 677 |
+
" images = images.float() \n",
|
| 678 |
+
" labels = labels.long() \n",
|
| 679 |
+
" labels = labels + 1 #labels are -1 to 3, add 1 to make them 0 to 4\n",
|
| 680 |
+
"\n",
|
| 681 |
+
" if self.transform:\n",
|
| 682 |
+
" images = self.transform(images)\n",
|
| 683 |
+
" labels = self.transform(labels)\n",
|
| 684 |
+
" \n",
|
| 685 |
+
" return images, labels, self.file_names[idx]\n",
|
| 686 |
+
"\n",
|
| 687 |
+
"class CustomDataset_test(Dataset):\n",
|
| 688 |
+
" def __init__(self, file_paths, transform=None):\n",
|
| 689 |
+
" self.file_paths = file_paths\n",
|
| 690 |
+
" self.transform = transform\n",
|
| 691 |
+
" self.file_names = [os.path.basename(path) for path in file_paths]\n",
|
| 692 |
+
"\n",
|
| 693 |
+
" def __len__(self):\n",
|
| 694 |
+
" return len(self.file_paths)\n",
|
| 695 |
+
"\n",
|
| 696 |
+
" def __getitem__(self, idx):\n",
|
| 697 |
+
" data = torch.load(self.file_paths[idx], weights_only=True)\n",
|
| 698 |
+
" \n",
|
| 699 |
+
" images = data[:6] #only load first 6 channels, labels are not in val_set and test_set\n",
|
| 700 |
+
" \n",
|
| 701 |
+
" images = images.float() \n",
|
| 702 |
+
"\n",
|
| 703 |
+
" if self.transform:\n",
|
| 704 |
+
" images = self.transform(images)\n",
|
| 705 |
+
" \n",
|
| 706 |
+
" return images, self.file_names[idx]\n",
|
| 707 |
+
"\n",
|
| 708 |
+
"# extend base_path to file_path\n",
|
| 709 |
+
"def generate_file_paths(base_path):\n",
|
| 710 |
+
" file_paths = []\n",
|
| 711 |
+
" for frame in os.listdir(base_path):\n",
|
| 712 |
+
" frame_path = os.path.join(base_path, frame)\n",
|
| 713 |
+
" if frame_path.endswith('.mat.pt'):\n",
|
| 714 |
+
" file_paths.append(frame_path)\n",
|
| 715 |
+
" return [path for path in file_paths if os.path.exists(path)]\n",
|
| 716 |
+
"\n",
|
| 717 |
+
"def load_data(base_path, batch_size=4, num_workers=2, test_size=0.2):\n",
|
| 718 |
+
" file_paths = generate_file_paths(base_path)\n",
|
| 719 |
+
" \n",
|
| 720 |
+
" train_paths, test_paths = train_test_split(file_paths, test_size=test_size, random_state=42)\n",
|
| 721 |
+
" \n",
|
| 722 |
+
" train_dataset = CustomDataset(file_paths=train_paths)\n",
|
| 723 |
+
" test_dataset = CustomDataset(file_paths=test_paths)\n",
|
| 724 |
+
" \n",
|
| 725 |
+
" train_loader = DataLoader(\n",
|
| 726 |
+
" train_dataset, \n",
|
| 727 |
+
" batch_size=batch_size, \n",
|
| 728 |
+
" shuffle=True, \n",
|
| 729 |
+
" num_workers=num_workers, \n",
|
| 730 |
+
" drop_last=True\n",
|
| 731 |
+
" )\n",
|
| 732 |
+
" \n",
|
| 733 |
+
" test_loader = DataLoader(\n",
|
| 734 |
+
" test_dataset, \n",
|
| 735 |
+
" batch_size=batch_size, \n",
|
| 736 |
+
" shuffle=False, \n",
|
| 737 |
+
" num_workers=num_workers, \n",
|
| 738 |
+
" drop_last=True\n",
|
| 739 |
+
" )\n",
|
| 740 |
+
" \n",
|
| 741 |
+
" return train_loader, test_loader\n"
|
| 742 |
+
]
|
| 743 |
+
},
|
| 744 |
+
{
|
| 745 |
+
"cell_type": "markdown",
|
| 746 |
+
"id": "67cd6c15",
|
| 747 |
+
"metadata": {},
|
| 748 |
+
"source": [
|
| 749 |
+
"## Loss Function"
|
| 750 |
+
]
|
| 751 |
+
},
|
| 752 |
+
{
|
| 753 |
+
"cell_type": "code",
|
| 754 |
+
"execution_count": null,
|
| 755 |
+
"id": "4c573803",
|
| 756 |
+
"metadata": {},
|
| 757 |
+
"outputs": [],
|
| 758 |
+
"source": [
|
| 759 |
+
"#Used to handle the problem of class imbalance\n",
|
| 760 |
+
"\n",
|
| 761 |
+
"def to_one_hot(tensor, nClasses):\n",
|
| 762 |
+
" n, h, w = tensor.size()\n",
|
| 763 |
+
" one_hot = torch.zeros(n, nClasses, h, w, device=tensor.device)\n",
|
| 764 |
+
" index_tensor = tensor.long().view(n, 1, h, w)\n",
|
| 765 |
+
" one_hot = one_hot.scatter_(1, index_tensor, 1)\n",
|
| 766 |
+
" return one_hot\n",
|
| 767 |
+
"\n",
|
| 768 |
+
"def _neg_loss(pred, gt):\n",
|
| 769 |
+
" pred = torch.clamp(pred, 1e-5, 1-1e-5)\n",
|
| 770 |
+
"\n",
|
| 771 |
+
" pos_inds = gt.eq(1).float()\n",
|
| 772 |
+
" neg_inds = gt.eq(0).float()\n",
|
| 773 |
+
"\n",
|
| 774 |
+
" balance_cof = 1.0\n",
|
| 775 |
+
" pos_loss = torch.log(pred) * torch.pow(1 - pred, 2) * pos_inds * balance_cof\n",
|
| 776 |
+
" neg_loss = torch.log(1 - pred) * torch.pow(pred, 2) * neg_inds\n",
|
| 777 |
+
" num_pos = pos_inds.float().sum()\n",
|
| 778 |
+
" pos_loss_sum = pos_loss.sum()\n",
|
| 779 |
+
" neg_loss_sum = neg_loss.sum()\n",
|
| 780 |
+
" if num_pos == 0:\n",
|
| 781 |
+
" loss = -neg_loss_sum\n",
|
| 782 |
+
" else:\n",
|
| 783 |
+
" loss = -(pos_loss_sum + neg_loss_sum) / num_pos\n",
|
| 784 |
+
" return loss\n",
|
| 785 |
+
"\n",
|
| 786 |
+
"class FocalLoss(nn.Module):\n",
|
| 787 |
+
" def __init__(self):\n",
|
| 788 |
+
" super(FocalLoss, self).__init__()\n",
|
| 789 |
+
" self.neg_loss = _neg_loss\n",
|
| 790 |
+
"\n",
|
| 791 |
+
" def forward(self, out, target):\n",
|
| 792 |
+
" return self.neg_loss(out, target)"
|
| 793 |
+
]
|
| 794 |
+
},
|
| 795 |
+
{
|
| 796 |
+
"cell_type": "markdown",
|
| 797 |
+
"id": "dec2b582",
|
| 798 |
+
"metadata": {},
|
| 799 |
+
"source": [
|
| 800 |
+
"## Train"
|
| 801 |
+
]
|
| 802 |
+
},
|
| 803 |
+
{
|
| 804 |
+
"cell_type": "code",
|
| 805 |
+
"execution_count": null,
|
| 806 |
+
"id": "7c2f0301",
|
| 807 |
+
"metadata": {},
|
| 808 |
+
"outputs": [],
|
| 809 |
+
"source": [
|
| 810 |
+
"import torch.optim as optim\n",
|
| 811 |
+
"import matplotlib.pyplot as plt\n",
|
| 812 |
+
"import time\n",
|
| 813 |
+
"\n",
|
| 814 |
+
"device = torch.device(\"cuda:0\" if torch.cuda.is_available() else \"cpu\")\n",
|
| 815 |
+
"\n",
|
| 816 |
+
"num_epochs = 20\n",
|
| 817 |
+
"\n",
|
| 818 |
+
"base_path = '/bohr/train-22pn/v2/training_set'\n",
|
| 819 |
+
"train_loader, test_loader = load_data(\n",
|
| 820 |
+
" base_path=base_path,\n",
|
| 821 |
+
" batch_size=4,\n",
|
| 822 |
+
" num_workers=2,\n",
|
| 823 |
+
" test_size=0.2\n",
|
| 824 |
+
")\n",
|
| 825 |
+
"\n",
|
| 826 |
+
"dimssnet = DIMSSNet().to(device)\n",
|
| 827 |
+
"criterion = FocalLoss()\n",
|
| 828 |
+
"optimizer = optim.Adam(dimssnet.parameters(), lr=0.001)\n",
|
| 829 |
+
"start_time = time.time()\n",
|
| 830 |
+
"test_loss_record = []\n",
|
| 831 |
+
"train_loss_record = []\n",
|
| 832 |
+
"\n",
|
| 833 |
+
"for epoch in range(num_epochs):\n",
|
| 834 |
+
" dimssnet.train()\n",
|
| 835 |
+
" running_loss = 0.0\n",
|
| 836 |
+
" for images, labels, _ in train_loader:\n",
|
| 837 |
+
" images = images.to(device)\n",
|
| 838 |
+
" labels = labels.to(device)\n",
|
| 839 |
+
" \n",
|
| 840 |
+
" images = [image.unsqueeze(1) for image in images]\n",
|
| 841 |
+
" images = torch.stack(images, dim=0)\n",
|
| 842 |
+
" images = images.float()\n",
|
| 843 |
+
" \n",
|
| 844 |
+
" outputs = dimssnet(images[:, 0, :, :], images[:, 1, :, :], images[:, 2, :, :],\n",
|
| 845 |
+
" images[:, 3, :, :], images[:, 4, :, :], images[:, 5, :, :])\n",
|
| 846 |
+
"\n",
|
| 847 |
+
" outputs_resized = F.interpolate(outputs, size=(TARGET_HEIGHT, TARGET_WIDTH), mode='bilinear', align_corners=False)\n",
|
| 848 |
+
" labels = to_one_hot(labels, n_class)\n",
|
| 849 |
+
" \n",
|
| 850 |
+
" loss = criterion(outputs_resized, labels.long())\n",
|
| 851 |
+
" optimizer.zero_grad()\n",
|
| 852 |
+
" loss.backward()\n",
|
| 853 |
+
" optimizer.step()\n",
|
| 854 |
+
" \n",
|
| 855 |
+
" running_loss += loss.item()\n",
|
| 856 |
+
"\n",
|
| 857 |
+
" test_loss = 0.0\n",
|
| 858 |
+
" dimssnet.eval()\n",
|
| 859 |
+
" with torch.no_grad():\n",
|
| 860 |
+
" for images, labels, _ in test_loader:\n",
|
| 861 |
+
" images = images.to(device)\n",
|
| 862 |
+
" labels = labels.to(device)\n",
|
| 863 |
+
" \n",
|
| 864 |
+
" images = [image.unsqueeze(1) for image in images]\n",
|
| 865 |
+
" images = torch.stack(images, dim=0)\n",
|
| 866 |
+
" images = images.float()\n",
|
| 867 |
+
" \n",
|
| 868 |
+
" outputs = dimssnet(images[:, 0, :, :], images[:, 1, :, :], images[:, 2, :, :],\n",
|
| 869 |
+
" images[:, 3, :, :], images[:, 4, :, :], images[:, 5, :, :])\n",
|
| 870 |
+
" \n",
|
| 871 |
+
" outputs_resized = F.interpolate(outputs, size=(TARGET_HEIGHT, TARGET_WIDTH), mode='bilinear', align_corners=False)\n",
|
| 872 |
+
" labels = to_one_hot(labels, n_class)\n",
|
| 873 |
+
" \n",
|
| 874 |
+
" loss = criterion(outputs_resized, labels.long())\n",
|
| 875 |
+
" test_loss += loss.item()\n",
|
| 876 |
+
" \n",
|
| 877 |
+
" test_loss_record.append(test_loss/len(test_loader))\n",
|
| 878 |
+
" train_loss_record.append(running_loss/len(train_loader))\n",
|
| 879 |
+
" print(f\"Epoch {epoch+1}/{num_epochs}, Training Loss: {running_loss/len(train_loader):.4f}, Test Loss: {test_loss/len(test_loader):.4f}\")\n",
|
| 880 |
+
"\n",
|
| 881 |
+
"# Create a new state_dict and add the \"model\" prefix, in order to match the loading method in metrics\n",
|
| 882 |
+
"new_state_dict = {}\n",
|
| 883 |
+
"for k, v in dimssnet.state_dict().items():\n",
|
| 884 |
+
" new_key = f\"model.{k}\" \n",
|
| 885 |
+
" new_state_dict[new_key] = v\n",
|
| 886 |
+
"\n",
|
| 887 |
+
"print(\"dimssnet successfully saved!\") \n",
|
| 888 |
+
"print(\"Training finished.\")\n",
|
| 889 |
+
"end_time = time.time()\n",
|
| 890 |
+
"total_time = end_time - start_time\n",
|
| 891 |
+
"print(f\"Training completed in {total_time} seconds\")"
|
| 892 |
+
]
|
| 893 |
+
},
|
| 894 |
+
{
|
| 895 |
+
"cell_type": "markdown",
|
| 896 |
+
"id": "f001aee8",
|
| 897 |
+
"metadata": {},
|
| 898 |
+
"source": [
|
| 899 |
+
"## Inference"
|
| 900 |
+
]
|
| 901 |
+
},
|
| 902 |
+
{
|
| 903 |
+
"cell_type": "code",
|
| 904 |
+
"execution_count": null,
|
| 905 |
+
"id": "8b330819",
|
| 906 |
+
"metadata": {},
|
| 907 |
+
"outputs": [],
|
| 908 |
+
"source": [
|
| 909 |
+
"# Run inference on validation set and testing set\n",
|
| 910 |
+
"import pandas as pd\n",
|
| 911 |
+
"\n",
|
| 912 |
+
"def run_inference(model, data_loader):\n",
|
| 913 |
+
" model.eval()\n",
|
| 914 |
+
" predictions = []\n",
|
| 915 |
+
" filenames = []\n",
|
| 916 |
+
" \n",
|
| 917 |
+
" with torch.no_grad():\n",
|
| 918 |
+
" for images, file_names in data_loader:\n",
|
| 919 |
+
" images = images.cuda() if torch.cuda.is_available() else images\n",
|
| 920 |
+
" \n",
|
| 921 |
+
" x = [image.unsqueeze(1) for image in images]\n",
|
| 922 |
+
" x = torch.stack(x, dim=0)\n",
|
| 923 |
+
" x = x.float()\n",
|
| 924 |
+
" \n",
|
| 925 |
+
" # Forward propagation\n",
|
| 926 |
+
" outputs = model(x[:, 0, :, :], x[:, 1, :, :], x[:, 2, :, :],\n",
|
| 927 |
+
" x[:, 3, :, :], x[:, 4, :, :], x[:, 5, :, :])\n",
|
| 928 |
+
" \n",
|
| 929 |
+
" # Adjust the output size\n",
|
| 930 |
+
" outputs = F.interpolate(outputs, size=(50, 181), mode='bilinear', align_corners=False)\n",
|
| 931 |
+
"\n",
|
| 932 |
+
" preds = torch.argmax(outputs, dim=1)\n",
|
| 933 |
+
" \n",
|
| 934 |
+
" preds = preds - 1\n",
|
| 935 |
+
" \n",
|
| 936 |
+
" for i, pred in enumerate(preds):\n",
|
| 937 |
+
" predictions.append(pred.cpu().numpy().flatten())\n",
|
| 938 |
+
" filenames.append(file_names[i])\n",
|
| 939 |
+
" \n",
|
| 940 |
+
" return predictions, filenames\n",
|
| 941 |
+
"\n",
|
| 942 |
+
"# Load validation set\n",
|
| 943 |
+
"if os.environ.get('DATA_PATH'):\n",
|
| 944 |
+
" DATA_PATH = os.environ.get(\"DATA_PATH\") + \"/\" \n",
|
| 945 |
+
"else:\n",
|
| 946 |
+
" DATA_PATH = \"\" # Fallback for local testing\n",
|
| 947 |
+
"# Load validation set\n",
|
| 948 |
+
"val_paths = generate_file_paths(DATA_PATH + 'validation_set')\n",
|
| 949 |
+
"val_dataset = CustomDataset_test(file_paths=val_paths)\n",
|
| 950 |
+
"val_loader = DataLoader(\n",
|
| 951 |
+
" val_dataset,\n",
|
| 952 |
+
" batch_size=1,\n",
|
| 953 |
+
" shuffle=False,\n",
|
| 954 |
+
" num_workers=0\n",
|
| 955 |
+
")\n",
|
| 956 |
+
"\n",
|
| 957 |
+
"# Load testing set\n",
|
| 958 |
+
"if os.environ.get('DATA_PATH'):\n",
|
| 959 |
+
" DATA_PATH = os.environ.get(\"DATA_PATH\") + \"/\" \n",
|
| 960 |
+
"else:\n",
|
| 961 |
+
" DATA_PATH = \"\" # Fallback for local testing\n",
|
| 962 |
+
"# Load testing set\n",
|
| 963 |
+
"test_paths = generate_file_paths(DATA_PATH + 'testing_set')\n",
|
| 964 |
+
"test_dataset = CustomDataset_test(file_paths=test_paths)\n",
|
| 965 |
+
"test_loader = DataLoader(\n",
|
| 966 |
+
" test_dataset,\n",
|
| 967 |
+
" batch_size=1,\n",
|
| 968 |
+
" shuffle=False,\n",
|
| 969 |
+
" num_workers=0\n",
|
| 970 |
+
")\n",
|
| 971 |
+
"\n",
|
| 972 |
+
"# Run inference on validation set\n",
|
| 973 |
+
"print(\"Running inference on validation set...\")\n",
|
| 974 |
+
"val_predictions, val_filenames = run_inference(dimssnet, val_loader)\n",
|
| 975 |
+
"\n",
|
| 976 |
+
"# Save validation results to CSV\n",
|
| 977 |
+
"val_results = []\n",
|
| 978 |
+
"for filename, pred in zip(val_filenames, val_predictions):\n",
|
| 979 |
+
" # Create a row with filename and flattened predictions\n",
|
| 980 |
+
" row = {'filename': filename}\n",
|
| 981 |
+
" for i, p in enumerate(pred):\n",
|
| 982 |
+
" row[f'pixel_{i}'] = p\n",
|
| 983 |
+
" val_results.append(row)\n",
|
| 984 |
+
"\n",
|
| 985 |
+
"val_df = pd.DataFrame(val_results)\n",
|
| 986 |
+
"val_df.to_csv('submission_val.csv', index=False)\n",
|
| 987 |
+
"print(f\"Validation results saved to output_validation.csv with shape: {val_df.shape}\")\n",
|
| 988 |
+
"\n",
|
| 989 |
+
"# Run inference on testing set\n",
|
| 990 |
+
"print(\"Running inference on testing set...\")\n",
|
| 991 |
+
"test_predictions, test_filenames = run_inference(dimssnet, test_loader)\n",
|
| 992 |
+
"\n",
|
| 993 |
+
"# Save testing results to CSV\n",
|
| 994 |
+
"test_results = []\n",
|
| 995 |
+
"for filename, pred in zip(test_filenames, test_predictions):\n",
|
| 996 |
+
" # Create a row with filename and flattened predictions\n",
|
| 997 |
+
" row = {'filename': filename}\n",
|
| 998 |
+
" for i, p in enumerate(pred):\n",
|
| 999 |
+
" row[f'pixel_{i}'] = p\n",
|
| 1000 |
+
" test_results.append(row)\n",
|
| 1001 |
+
"\n",
|
| 1002 |
+
"test_df = pd.DataFrame(test_results)\n",
|
| 1003 |
+
"test_df.to_csv('submission_test.csv', index=False)\n",
|
| 1004 |
+
"print(f\"Testing results saved to output_testing.csv with shape: {test_df.shape}\")\n",
|
| 1005 |
+
"\n",
|
| 1006 |
+
"print(\"\\nInference completed! Results saved to:\")\n",
|
| 1007 |
+
"print(\"- submission_val_ref.csv (for validation set leaderboard)\")\n",
|
| 1008 |
+
"print(\"- submission_test_ref.csv (for testing set leaderboard)\")"
|
| 1009 |
+
]
|
| 1010 |
+
},
|
| 1011 |
+
{
|
| 1012 |
+
"cell_type": "code",
|
| 1013 |
+
"execution_count": null,
|
| 1014 |
+
"id": "72fde72d",
|
| 1015 |
+
"metadata": {},
|
| 1016 |
+
"outputs": [],
|
| 1017 |
+
"source": [
|
| 1018 |
+
"import zipfile\n",
|
| 1019 |
+
"import os\n",
|
| 1020 |
+
"\n",
|
| 1021 |
+
"# Define the files to zip and the zip file name.\n",
|
| 1022 |
+
"files_to_zip = ['submission_val.csv', 'submission_test.csv']\n",
|
| 1023 |
+
"zip_filename = 'submission.zip'\n",
|
| 1024 |
+
"\n",
|
| 1025 |
+
"# Create a zip file\n",
|
| 1026 |
+
"with zipfile.ZipFile(zip_filename, 'w') as zipf:\n",
|
| 1027 |
+
" for file in files_to_zip:\n",
|
| 1028 |
+
" # Add the file to the zip fil\n",
|
| 1029 |
+
" zipf.write(file, os.path.basename(file))\n",
|
| 1030 |
+
"\n",
|
| 1031 |
+
"print(f'{zip_filename} Created successfully!')"
|
| 1032 |
+
]
|
| 1033 |
+
}
|
| 1034 |
+
],
|
| 1035 |
+
"metadata": {
|
| 1036 |
+
"kernelspec": {
|
| 1037 |
+
"display_name": "Python 3 (ipykernel)",
|
| 1038 |
+
"language": "python",
|
| 1039 |
+
"name": "python3"
|
| 1040 |
+
},
|
| 1041 |
+
"language_info": {
|
| 1042 |
+
"codemirror_mode": {
|
| 1043 |
+
"name": "ipython",
|
| 1044 |
+
"version": 3
|
| 1045 |
+
},
|
| 1046 |
+
"file_extension": ".py",
|
| 1047 |
+
"mimetype": "text/x-python",
|
| 1048 |
+
"name": "python",
|
| 1049 |
+
"nbconvert_exporter": "python",
|
| 1050 |
+
"pygments_lexer": "ipython3",
|
| 1051 |
+
"version": "3.12.9"
|
| 1052 |
+
}
|
| 1053 |
+
},
|
| 1054 |
+
"nbformat": 4,
|
| 1055 |
+
"nbformat_minor": 5
|
| 1056 |
+
}
|
Individual-Contest/Radar/Solution/Scoring/metrics.py
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import numpy as np
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
def load_ground_truth_from_csv(csv_path):
|
| 7 |
+
"""Load ground truth labels from CSV file"""
|
| 8 |
+
df = pd.read_csv(csv_path)
|
| 9 |
+
|
| 10 |
+
ground_truth = {}
|
| 11 |
+
for _, row in df.iterrows():
|
| 12 |
+
filename = row['filename']
|
| 13 |
+
|
| 14 |
+
# Extract ground truth labels (all columns except filename)
|
| 15 |
+
gt_cols = [col for col in df.columns if col.startswith('pixel_')]
|
| 16 |
+
gt_labels = row[gt_cols].values.astype(int)
|
| 17 |
+
|
| 18 |
+
ground_truth[filename] = gt_labels
|
| 19 |
+
|
| 20 |
+
print(f"Loaded {len(ground_truth)} samples from CSV")
|
| 21 |
+
return ground_truth
|
| 22 |
+
|
| 23 |
+
def calculate_score_from_csv(csv_path, ground_truth, bonus=50):
|
| 24 |
+
df = pd.read_csv(csv_path)
|
| 25 |
+
|
| 26 |
+
total_score = 0
|
| 27 |
+
total_theo = 0
|
| 28 |
+
|
| 29 |
+
for _, row in df.iterrows():
|
| 30 |
+
filename = row['filename']
|
| 31 |
+
if filename not in ground_truth:
|
| 32 |
+
raise ValueError(f"Missing ground truth for file: {filename}")
|
| 33 |
+
|
| 34 |
+
pred_cols = [col for col in df.columns if col.startswith('pixel_')]
|
| 35 |
+
if len(pred_cols) == 0:
|
| 36 |
+
raise ValueError("No prediction columns found (e.g., pixel_0, pixel_1, ...)")
|
| 37 |
+
|
| 38 |
+
predictions = row[pred_cols].values.astype(int)
|
| 39 |
+
gt_labels = ground_truth[filename]
|
| 40 |
+
|
| 41 |
+
if len(predictions) != len(gt_labels):
|
| 42 |
+
raise ValueError(f"Length mismatch for {filename}: prediction({len(predictions)}), ground truth({len(gt_labels)})")
|
| 43 |
+
|
| 44 |
+
equal_mask = predictions == gt_labels
|
| 45 |
+
neg_one_mask = gt_labels == -1
|
| 46 |
+
|
| 47 |
+
score_neg_one = np.sum(equal_mask & neg_one_mask) * 1
|
| 48 |
+
score_other = np.sum(equal_mask & ~neg_one_mask) * bonus
|
| 49 |
+
score_theo = np.sum(neg_one_mask) * 1 + np.sum(~neg_one_mask) * bonus
|
| 50 |
+
|
| 51 |
+
total_score += score_neg_one + score_other
|
| 52 |
+
total_theo += score_theo
|
| 53 |
+
|
| 54 |
+
if total_theo == 0:
|
| 55 |
+
print("Warning: Theoretical total score is zero. Returning score 0.0")
|
| 56 |
+
return 0.0
|
| 57 |
+
|
| 58 |
+
score = total_score / total_theo
|
| 59 |
+
|
| 60 |
+
if not np.isfinite(score) or score < 0 or score > 1:
|
| 61 |
+
print(f"Warning: Score {score} is invalid. Returning 0.0")
|
| 62 |
+
return 0.0
|
| 63 |
+
|
| 64 |
+
return score
|
| 65 |
+
|
| 66 |
+
def main():
|
| 67 |
+
"""Main function to calculate scores for both validation and testing sets"""
|
| 68 |
+
bonus = 50 # Score weights for non-background categories
|
| 69 |
+
if os.environ.get('METRIC_PATH'):
|
| 70 |
+
METRIC_PATH = os.environ.get("METRIC_PATH")+"/"
|
| 71 |
+
else:
|
| 72 |
+
METRIC_PATH =""
|
| 73 |
+
# Paths for predictions
|
| 74 |
+
val_csv_path = 'submission_val.csv'
|
| 75 |
+
test_csv_path = 'submission_test.csv'
|
| 76 |
+
|
| 77 |
+
# Paths for ground truth CSV files
|
| 78 |
+
val_gt_csv_path = METRIC_PATH + 'ground_truth_val.csv'
|
| 79 |
+
test_gt_csv_path = METRIC_PATH + 'ground_truth_test.csv'
|
| 80 |
+
|
| 81 |
+
# Load ground truth for validation set from CSV
|
| 82 |
+
val_ground_truth = load_ground_truth_from_csv(val_gt_csv_path)
|
| 83 |
+
|
| 84 |
+
# Load ground truth for testing set from CSV
|
| 85 |
+
test_ground_truth = load_ground_truth_from_csv(test_gt_csv_path)
|
| 86 |
+
|
| 87 |
+
# Calculate scores
|
| 88 |
+
print("\nCalculating scores...")
|
| 89 |
+
|
| 90 |
+
# Validation set score
|
| 91 |
+
val_score = calculate_score_from_csv(val_csv_path, val_ground_truth, bonus)
|
| 92 |
+
print(f"Validation set score: {val_score:.4f}")
|
| 93 |
+
if val_score > 1:
|
| 94 |
+
val_score = 0
|
| 95 |
+
|
| 96 |
+
# Testing set score
|
| 97 |
+
test_score = calculate_score_from_csv(test_csv_path, test_ground_truth, bonus)
|
| 98 |
+
print(f"Testing set score: {test_score:.4f}")
|
| 99 |
+
if test_score > 1:
|
| 100 |
+
test_score = 0
|
| 101 |
+
|
| 102 |
+
# Save results
|
| 103 |
+
score = {
|
| 104 |
+
"public_a": val_score,
|
| 105 |
+
"private_b": test_score,
|
| 106 |
+
}
|
| 107 |
+
ret_json = {
|
| 108 |
+
"status": True,
|
| 109 |
+
"score": score,
|
| 110 |
+
"msg": "Success!",
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
with open('score.json', 'w') as f:
|
| 114 |
+
json.dump(ret_json, f, indent=2)
|
| 115 |
+
|
| 116 |
+
if __name__ == '__main__':
|
| 117 |
+
main()
|
Individual-Contest/Radar/Solution/figs/IOAI-Logo.png
ADDED
|
Git LFS Details
|
Individual-Contest/Radar/figs/IOAI-Logo.png
ADDED
|
Git LFS Details
|
Individual-Contest/Radar/figs/Radar Fig 1.png
ADDED
|
Git LFS Details
|
Individual-Contest/Radar/figs/Radar Fig 2.png
ADDED
|
Git LFS Details
|
Individual-Contest/Radar/figs/Radar Fig 3.png
ADDED
|
Git LFS Details
|