Company Cloud Server.

root

8becaE7a

211.41.73.13

# 2021 AI Champion
![image](images/header.png)  
Source code of the 1st place solution for [2021AIChamp](http://aifactory.space/competition/detail/1864)

# 1. INSTALLATION
+ AI Server 1  
    - HARDWARE: 2 X NVIDIA TESLA V100 32GB GPU, 36x CPUs, 188GB RAM;  
    - CentOS 8.3  
    - CUDA 11.3  
+ AI Server 2  
    - HARDWARE: 1 X NVIDIA TESLA V100 32GB GPU, 20x CPUs, 62GB RAM;   
    - Ubuntu 18.04.5 LTS  
    - CUDA 11.2  
+ **Local PC for running demo**  
    - HARDWARE: 1 X GeForce RTX 3090 24GB GPU, 8x CPUs, 32GB RAM; 
    - Ubuntu 20.04.3 LTS  
    - CUDA 11.3  
+ python packages are detailed separately in [requirements](requirements.txt)

`$ conda create -n envs python=3.7.11`  
`$ conda activate envs`  
`$ conda install -c conda-forge gdcm`  
`$ pip install -r requirements.txt`  

# 2. DATASET
- Download competition dataset at [link](http://aifactory.space/competition/detail/1864), then extract
- Update TRAIN_IMAGE_DIR, DIR and SAVE_DIR in src/prepare_data  

`$ cd src/prepare_data`  
`$ python prepare_data.py`  

# 3. SOLUTION SUMMARY
![image](images/proposed_method.jpg)
# 4. TRAIN MODEL
## 4.1. STATUS MODEL
- Update configs
- Update TRAIN_PATH, TEST_PATH in [dataset.py](src/status_models/dataset.py)
- Update TRAIN_PATH, TEST_PATH, train_org in [train.py](src/status_models/train.py)
- Update TRAIN_PATH, TEST_PATH, test in [inference.py](src/status_models/inference.py)  

`$ cd src/status_model`  
`$ bash train.sh`  

- For evaluation only  

`$ python inference.py --cfg='configs/xxxx.yaml`  

- Cross-validation scores

![image](images/status_models.png)  

## 4.2. TYPE MODEL
- Update configs
- Update TRAIN_PATH, TEST_PATH in [dataset.py](src/type_model/dataset.py)
- Update TRAIN_PATH, TEST_PATH, train_org in [train.py](src/type_model/train.py)
- Update TRAIN_PATH, TEST_PATH, test in [inference.py](src/type_model/inference.py)  

`$ cd src/status_model`  
`$ bash train.sh`  

- For evaluation only  

`$ python inference.py --cfg='configs/xxxx.yaml`  

- Cross-validation scores

![image](images/type_models.png)  

## 4.3. FAULT MODEL
- Update configs
- Update TRAIN_PATH, TEST_PATH in [dataset.py](src/fault_model/dataset.py)
- Update TRAIN_PATH, TEST_PATH, train_org in [train.py](src/fault_model/train.py)
- Update TRAIN_PATH, TEST_PATH, test in [inference.py](src/fault_model/inference.py)  

`$ cd src/fault_model`  
`$ bash train.sh`  

- For evaluation only  

`$ python inference.py --cfg='configs/xxxx.yaml`  

- Cross-validation scores

![image](images/fault_models.png)  

# 5. ENSEMBLE MODELS
## 1. Single best models
- We uploaded three best trained models weight in this [link](https://drive.google.com/drive/folders/1JQ23PDhOCwQ-KrqIz6OsC2RSlxEFtIvC?usp=sharing), after download, put it into it corressponding folder (status, type and fault). 

`$ cd /src/status_model`  
`$ python inference.py --cfg='configs/resnext.yaml`  

`$ cd /src/type_model`  
`$ python inference.py --cfg='configs/efficientnet.yaml`  

`$ cd /src/fault_model`  
`$ python inference.py --cfg='configs/resnext.yaml`  

- After inference, lets convert results into competition submission format by using [single_ensemble](src/ensemble/single_model_submission.ipynb). 
## 2. Ensemble models 
- We trained more than 70 models , and ensemble for achiving higher scores. We uploaded the prediction probabilities for ensemble in this [link](https://drive.google.com/drive/folders/1JQ23PDhOCwQ-KrqIz6OsC2RSlxEFtIvC?usp=sharing). 
- Using [ensemble](src/ensemble/ensemble_models_to_submission.ipynb) for ensembling and convert into competition submission formart.
- Check [oof_visualize](src/ensemble/oof_visualize.ipynb) for choosing the weights more approriate.

![image](images/oof_type.png)

# 6. FINAL SUBMISSION
## 1. Single best models
    - Status: ResNext50_32x4d with image size 768 and TalorCrossEntropy loss, as well as weak augmentation (Normalize, H,VFlips)
    - Type: EfficientNetv2_s_in21k with image size 512 and TaylorCrossEntropy loss, as well as weak augmentation (Normalize, H,VFlips)
    - Fault: ResNext50_32x4d with image size 768 and TalorCrossEntropy loss, as well as weak augmentation (Normalize, H,VFlips)
    - We achived the 1st rank.

-> **LB: 0.948649** - [1st](src/ensemble/temp/updated_test_output_sample.csv)

## 2. Ensemble models 
With this ensemble [strategy](src/ensemble/ensemble_models_to_submission.ipynb), we achived the 1st rank.  
-> **LB: 0.954054** - [1st](src/ensemble/temp_single/updated_test_output_sample.csv)
