# Aidea 自動駕駛比賽
###### tags: `自動駕駛`
## 比賽介紹
1. **評分標準**
+ 資格賽比 $mIOU$ 分數,公式如下
$$
mIOU = \frac{1}{n-1} \sum_{i \not\in bg} IOU_i = \frac{1}{n-1} \sum_{i \not\in bg} \frac{|Y_i \cap \hat{Y}_i|}{|Y_i \ \cup \hat{Y}_i|}
$$ 其中
$$
\left\{
\begin{aligned}
Y_i &= 所有類別為 \ i \ 的像素\\
\hat{Y}_i & = 所有預測為類別 \ i \ 的像素 \\
\end{aligned}
\right.
$$
$n$ 為類別數量,$bg$ 為背景類別。
+ 決賽比 $mIOU$,能耗,速度。
2. **資料**
+ $35500$ 筆
+ 解析度: $(720, 1280)$
+ $6$ 個類別
3. [**比賽連結**](https://aidea-web.tw/topic/121d8ddd-2557-4f10-b130-2e6520016361?focus=intro)
## 研究動機
1. **藉比賽研究新技術**
+ **DropBlock**
+ **DropPath**
+ **SegFormer**
2. **醫學影像切割 (國泰醫院)**

3. **Imbalanced Loss (智慧醫療戰情室)**
+ **Dice Loss**
+ **mIOU loss**
+ **SSLoss (sensitivity-specificity loss)**
## 專案介紹
1. **資料增強**
+ **Augmentation1**: color jitter, gaussian noise, gaussian blur
+ **Augmentation2**: perspective, shift, rotation (label 也要跟著變)
+ **package**: **kornia**

2. **前處理**
+ **Normalize**
3. **模型介紹 (Unet)**
+ **input shape**: $(3, H, W)$, **output shape**: $(n, H, W)$
+ **Encoder-Decoder 架構**
+ **Encoder**: 傳統卷積層,用於提取語意訊息
+ **Decoder**: 還原空間訊息
+ **Skip-Connection**

+ **DeepLab**
+ **Transformer: SegFormer, PVT, Swin Transformer**
4. **技術改進**
+ **DropBlock**: 對卷積層進行正則化,通常會加在 **convolution block** 間,或 **skip connection** 之前。
+ **條件隨機場**: 損失函數中加入 **pair loss**,會讓模型的輸出更加平滑。

+ **Spatial Attention**: 學習空間的 **Attention** 使模型專注於重要區域,通常加在 **Encoder**, **Decoder** 之間。

5. **損失函數**
+ **Cross Entropy**
$$
CE(y_i, \hat{y}_i) =\frac{1}{H \cdot W} \sum_{i =1}^{HW} CE(y_i, \hat{y}_i).
$$
+ **Weighted Cross Entropy**
$$
WCE(y_i, \hat{y}_i) =\alpha \sum_{i =1}^{HW} w_{\hat{y}_i} \cdot CE(y_i, \hat{y}_i).
$$
+ **SSLoss**
$$
SSLoss = w * sensitivity + (1-w)*specificity.
$$其中
$$
\left\{
\begin{aligned}
sensitivity & = & \frac{TP}{TP + FN} \\
specificity & = & \frac{TN}{TN + FP}
\end{aligned}
\right.
$$
+ **SoftDice Loss**
$$
DiceLoss = 1 - \frac{1}{n-1}\sum_{i \not \in bg} 2 \cdot \frac{|Y_i \cap \hat{Y}_i|}{|Y_i| + |\hat{Y}_i|}.
$$
:::info
Dice Score 可視為 soft F1-score
$$
2 \cdot \frac{|Y \cap \hat{Y}|}{|Y| + |\hat{Y}|} \approx \frac{2TP}{2TP + FP + FN} = F_1-score
$$
:::
+ **IOU Loss**
$$
IOULoss = 1 - \frac{1}{n-1}\sum_{i \not \in bg} \frac{|Y_i \cap \hat{Y}_i|}{|Y_i \cup \hat{Y}_i|}.
$$
## 後續改進
1. **提高圖片解析度**
3. **探索新模型**
+ **SegFormer**
## 參考資料
1. https://github.com/JunMa11/SegLoss
2. https://discuss.pytorch.org/t/how-the-pytorch-freeze-network-in-some-layers-only-the-rest-of-the-training/7088/8
3. https://arxiv.org/abs/1505.04597
4. https://distill.pub/2016/deconv-checkerboard/
5. https://arxiv.org/abs/2006.14822
6. https://arxiv.org/abs/1502.03240
7. https://arxiv.org/abs/2004.03696