# Reliability Does Matter: An End-to-End Weakly Supervised Semantic Segmentation Approach
AAAI 2020 (Spotlight).

The code of the new extended work now is available. In the further, I will try to merge these two works so that making the whole project is more elegant.

Paper of the extended work will come soon.

This project is based on [Regularized loss](https://github.com/meng-tang/rloss) and [PSA](https://github.com/jiwoon-ahn/psa).

## Before Running, build python extension module:
```
cd wrapper/bilateralfilter
swig -python -c++ bilateralfilter.i
python setup.py install
```
More details please see [here](https://github.com/meng-tang/rloss/tree/master/pytorch)

## Download pretrained models to ./netWeights:
Google: due to the coronavirus outbreak in China, I will upload models after I can enter my lab. But you can
download “[ilsvrc-cls_rna-a1_cls1000_ep-0001.params]” and “[res38_cls.pth]” from [here](https://github.com/jiwoon-ahn/psa).

[BaiduYun](https://pan.baidu.com/s/15AwO6Jn9vQQtThE02QOefw)

 [ilsvrc-cls_rna-a1_cls1000_ep-0001.params] is an init pretained model.
 
 [res38_cls.pth] is a classification model pretrained on VOC 2012 dataset.
 
 [RRM_final.pth] is the final model (AAAI).
 
 [RRM(attention)_final.pth] is the final model of the new extended work (64.7 mIoU on Pascal Voc 2012 val set).

## Training of the New Extended Work:

### Training from init model:
you need 4 GPUs and the pretrained model [ilsvrc-cls_rna-a1_cls1000_ep-0001.params]:
```
python train_from_init(attention).py --voc12_root /your/path/VOCdevkit/VOC2012
```
 
### Training from a pretrained classification model:
you only need 2 GPU and the pretrained model [res38_cls.pth]
```
python train_from_cls_weight(attention).py --IMpath /your/path/VOCdevkit/VOC2012/JPEGImages
```

## Training of the AAAI Work:
I suggest that it is better to use the 2nd method due to lower computing costs.
### Training from init model:
you need 4 GPUs and the pretrained model [ilsvrc-cls_rna-a1_cls1000_ep-0001.params]:
```
python train_from_init.py --voc12_root /your/path/VOCdevkit/VOC2012
```
 
### Training from a pretrained classification model:
you only need 1 GPU and the pretrained model [res38_cls.pth]
```
python train_from_cls_weight.py --IMpath /your/path/VOCdevkit/VOC2012/JPEGImages
```
## Inferencing of the extended work:
you need 1 GPU and the final model [RRM(attention)_final.pth]:
```
python infer_RRM.py --IMpath /your/path/VOCdevkit/VOC2012/JPEGImages
```
## Inferencing of the AAAI work:
you need 1 GPU and the final model [RRM_final.pth]:
```
python infer_RRM.py --IMpath /your/path/VOCdevkit/VOC2012/JPEGImages

