IJCAI2020 & IJCV 2020 :city_sunrise: Unsupervised Scene Adaptation with Memory Regularization in vivo

Overview

Seg_Uncertainty

Python 3.6 License: MIT

In this repo, we provide the code for the two papers, i.e.,

Table of contents

Prerequisites

  • Python 3.6
  • GPU Memory >= 11G (e.g., GTX2080Ti or GTX1080Ti)
  • Pytorch or Paddlepaddle

Prepare Data

Download [GTA5] and [Cityscapes] to run the basic code. Alternatively, you could download extra two datasets from [SYNTHIA] and [OxfordRobotCar].

The data folder is structured as follows:

├── data/
│   ├── Cityscapes/  
|   |   ├── data/
|   |       ├── gtFine/
|   |       ├── leftImg8bit/
│   ├── GTA5/
|   |   ├── images/
|   |   ├── labels/
|   |   ├── ...
│   ├── synthia/ 
|   |   ├── RGB/
|   |   ├── GT/
|   |   ├── Depth/
|   |   ├── ...
│   └── Oxford_Robot_ICCV19
|   |   ├── train/
|   |   ├── ...

Training

Stage-I:

python train_ms.py --snapshot-dir ./snapshots/SE_GN_batchsize2_1024x512_pp_ms_me0_classbalance7_kl0.1_lr2_drop0.1_seg0.5  --drop 0.1 --warm-up 5000 --batch-size 2 --learning-rate 2e-4 --crop-size 1024,512 --lambda-seg 0.5  --lambda-adv-target1 0.0002 --lambda-adv-target2 0.001   --lambda-me-target 0  --lambda-kl-target 0.1  --norm-style gn  --class-balance  --only-hard-label 80  --max-value 7  --gpu-ids 0,1  --often-balance  --use-se  

Generate Pseudo Label:

python generate_plabel_cityscapes.py  --restore-from ./snapshots/SE_GN_batchsize2_1024x512_pp_ms_me0_classbalance7_kl0.1_lr2_drop0.1_seg0.5/GTA5_25000.pth

Stage-II (with recitfying pseudo label):

python train_ft.py --snapshot-dir ./snapshots/1280x640_restore_ft_GN_batchsize9_512x256_pp_ms_me0_classbalance7_kl0_lr1_drop0.2_seg0.5_BN_80_255_0.8_Noaug --restore-from ./snapshots/SE_GN_batchsize2_1024x512_pp_ms_me0_classbalance7_kl0.1_lr2_drop0.1_seg0.5/GTA5_25000.pth --drop 0.2 --warm-up 5000 --batch-size 9 --learning-rate 1e-4 --crop-size 512,256 --lambda-seg 0.5 --lambda-adv-target1 0 --lambda-adv-target2 0 --lambda-me-target 0 --lambda-kl-target 0 --norm-style gn --class-balance --only-hard-label 80 --max-value 7 --gpu-ids 0,1,2 --often-balance  --use-se  --input-size 1280,640  --train_bn  --autoaug False

*** If you want to run the code without rectifying pseudo label, please change [this line] to 'from trainer_ms import AD_Trainer', which would apply the conventional pseudo label learning. ***

Testing

python evaluate_cityscapes.py --restore-from ./snapshots/1280x640_restore_ft_GN_batchsize9_512x256_pp_ms_me0_classbalance7_kl0_lr1_drop0.2_seg0.5_BN_80_255_0.8_Noaug/GTA5_25000.pth

Trained Model

The trained model is available at https://drive.google.com/file/d/1smh1sbOutJwhrfK8dk-tNvonc0HLaSsw/view?usp=sharing

  • The folder with SY in name is for SYNTHIA-to-Cityscapes
  • The folder with RB in name is for Cityscapes-to-Robot Car

One Note for SYNTHIA-to-Cityscapes

Note that the evaluation code I provided for SYNTHIA-to-Cityscapes is still average the IoU by divide 19. Actually, you need to re-calculate the value by divide 16. There are only 16 shared classes for SYNTHIA-to-Cityscapes. In this way, the result is same as the value reported in paper.

The Key Code

Core code is relatively simple, and could be directly applied to other works.

Related Works

We also would like to thank great works as follows:

Citation

@inproceedings{zheng2019unsupervised,
  title={Unsupervised Scene Adaptation with Memory Regularization in vivo},
  author={Zheng, Zhedong and Yang, Yi},
  booktitle={IJCAI},
  year={2020}
}
@article{zheng2020unsupervised,
  title={Rectifying Pseudo Label Learning via Uncertainty Estimation for Domain Adaptive Semantic Segmentation },
  author={Zheng, Zhedong and Yang, Yi},
  journal={International Journal of Computer Vision (IJCV)},
  doi={10.1007/s11263-020-01395-y},
  year={2020}
}
Comments
  • How to change class balance parameters according to input size

    How to change class balance parameters according to input size

    Hi, thank you for your great work on domain adaptation! The origin input image is 1024512, but now I want to train on higher resolution, like 19201080. How should I change the class balance parameters like max_value and 6464n. In my opinion, it will be better to use ratio threshold instead of a hard assigned number like 64 like this: for i in range(self.num_classes): count[i] = torch.sum(labels==i) if count[i]/(nhw) < 1/128.0: #small classes, original train size is 1024512 weight[i] = self.max_value and 6464/(5121024) = 1/128 But I get worse results than default settings trained with input size (1024512). Is there anything that I missed? Any help will be appreciated.

    opened by qimw 7
  • can not get good performance

    can not get good performance

    Hi, I have some problems 1.for your release model: stage 1 model (SE_GN_batchsize2_1024x512_pp_ms_me0_classbalance7_kl0.1_lr2_drop0.1_seg0.5), I test this model using your code, the mIoU is only 38.07, much lower than 45.5(stage 1 miou in MRNet paper). stage2 model(1280x640_restore_ft_GN_batchsize9_512x256_pp_ms_me0_classbalance7_kl0_lr1_drop0.2_seg0.5_BN_80_255_0.8_Noaug) is 50.34 , which is same as the report result in second paper. 2. train result I use your released stage 1 model to generate pseudo label, then train stage 2, However, the performance is low: 43.89 for 25000.pth, 42.69 for 50000.pth, 41.98 for 100000.pth, much lower than the result in your paper. And I do not change any code except variable DATA_DIRECTORY

    opened by panzhang0212 6
  • Question about stage2

    Question about stage2

    Nice work! I am a novice in the domain adaptation field. I have a question about stage2. In my understanding about your paper, uncertainty estimation is used for target domain images. But in your code trainer_ms_variance.py, it seems to be calculated on the image of the source domain.

        def gen_update(self, images, images_t, labels, labels_t, i_iter):
                self.gen_opt.zero_grad()
    
                pred1, pred2 = self.G(images)
                pred1 = self.interp(pred1)
                pred2 = self.interp(pred2)
    
                if self.class_balance:            
                    self.seg_loss = self.update_class_criterion(labels)
    
                loss_seg1 = self.update_variance(labels, pred1, pred2) 
                loss_seg2 = self.update_variance(labels, pred2, pred1)
     
                loss = loss_seg2 + self.lambda_seg * loss_seg1
    
    opened by zhangbin0917 4
  • Question about stage 3

    Question about stage 3

    Hi, thanks for your great job! Recently I've been reading your code and I have a question about stage 2(rectifying). You set lambda_adv_target1 and lambda_adv_target2 to 0 which means there is no adv training in stage 2(Right?), but you keep training generator with false instruction from discriminator(the weight of discriminators is not loaded in stage 3), you annotated here which means you keep training G, but here you never updated D, is this the right behavior or maybe I misunderstood sth?

    opened by wtupc96 4
  • load state dict error

    load state dict error

    When conducting experiments of stage 1 training, state dicts of self.G model is inconsistent with the pretrained model in 'http://vllab.ucmerced.edu/ytsai/CVPR18/DeepLab_resnet_pretrained_init-f81d91e8.pth'. For example, key of state dict of self.G is 'layer5.conv2d_list.0.0.weight' and 'layer6.bottleneck.0.se.0.weight', but key of the pretrained model is 'layer5.conv2d_list.0.weight' and there is no module 'layer6.bottleneck.0.se.0.weight'. Should I set the strict as False in load_state_dict()?

    opened by valencebond 3
  • tabular data/ noisy instances

    tabular data/ noisy instances

    Hi, thanks for sharing your implementation. I have two questions about it:

    1. Does it also work on tabular data?
    2. Is it possible to identify the noisy instances (return the noisy IDs or the clean set)?

    Thanks!

    opened by nazaretl 2
  • Question about Pseudo-labels are source domain but not target domain in the code

    Question about Pseudo-labels are source domain but not target domain in the code

    Hi, thanks for the nice code~ I have some questions about the pseudo-labels training part of the code,

    this is the pseudo labeling loss of the source data as Eq.11 in paper: loss_seg1 = self.update_variance(labels, pred1, pred2), in which the labels come from the source domain.

    the target domain does not use the pseudo-labels but the entropy minimization: loss_kl = ( self.kl_loss(self.log_sm(pred_target2) , mean_pred) + self.kl_loss(self.log_sm(pred_target1) , mean_pred))/(nhw)

    opened by jingzhengli 1
  • About data loading

    About data loading

    Hello, thank for sharing the great work. I have a quick question. I find that ''random scale'' and ''mirror'' are used for preprocessing data, which is a little different from previous works.

    • So, for what reason did you adopt these strategies?

    • Have you conducted experiments to verify how much performance improvement they bring?

    Thanks!

    opened by BinhuiXie 1
  • About rectification in stage 2

    About rectification in stage 2

    Hi, thanks for the code! I was wondering why in stage 2 the loss weight lambda-kl-target is set to 0. From my understanding, the rectification is done by using this term. Thanks in advance.

    opened by adricarda 1
  • Without recitfying pseudo label in Stage 2

    Without recitfying pseudo label in Stage 2

    If I want to run the code without rectifying the pseudo label, I am confused that why in stage 2 the loss weight lambda-kl-target is set to 0? (From README) From Eq.9 of the IJCAI2020 paper, I understand the KL-divergence loss is should be used. Thanks

    opened by yihong-97 1
  • AttributeError: 'Namespace' object has no attribute 'sync_bn'

    AttributeError: 'Namespace' object has no attribute 'sync_bn'

    Thank you for sharing this code! I have a small question, when I run the train_ms_robot. py file, I always get an error, AttributeError: 'Namespace' object has no attribute 'sync_bn'.

    opened by xmz123456 1
  • Prediction variance and Prediction confidence

    Prediction variance and Prediction confidence

    Hello,

    could you maybe explain the difference between prediction variance and prediction Confidence? In the paper, Figure 5 visualizes both, but I'm not sure how do you calculate them. I assume the KL term divergence is used as variance, then how to get the confidence?

    Thanks in advance.

    opened by SnowdenLee 1
  • Where is the code for MC-Dropout?

    Where is the code for MC-Dropout?

    Hi @layumi , I noticed that in your paper, the uncertainty is obtained by computing both MC-Dropout and difference between two classifiers, but I cannot find the code used for MC-Dropout, could you please kindly tell me?

    opened by mitming 1
  • Question about no folder of

    Question about no folder of "ground truth" of SYNTHIA dataset

    Sorry to bother you, when I downloaded the SYNTHIA dataset and decompressed it. I found there was no folder with "ground truth"(GT). I want to know if someone else is in this situation.

    opened by jingzhengli 1
Owner
Zhedong Zheng
Hi, I am a PhD student at University of Technology Sydney. My work focuses on computer vision, especially representation learning.
Zhedong Zheng
The Dual Memory is build from a simple CNN for the deep memory and Linear Regression fro the fast Memory

Simple-DMA a simple Dual Memory Architecture for classifications. based on the paper Dual-Memory Deep Learning Architectures for Lifelong Learning of

null 1 Jan 27, 2022
IAST: Instance Adaptive Self-training for Unsupervised Domain Adaptation (ECCV 2020)

This repo is the official implementation of our paper "Instance Adaptive Self-training for Unsupervised Domain Adaptation". The purpose of this repo is to better communicate with you and respond to your questions. This repo is almost the same with Another-Version, and you can also refer to that version.

CVSM Group -  email: czhu@bupt.edu.cn 84 Dec 12, 2022
A Comprehensive Analysis of Weakly-Supervised Semantic Segmentation in Different Image Domains (IJCV submission)

wsss-analysis The code of: A Comprehensive Analysis of Weakly-Supervised Semantic Segmentation in Different Image Domains, arXiv pre-print 2019 paper.

Lyndon Chan 48 Dec 18, 2022
Synthetic Humans for Action Recognition, IJCV 2021

SURREACT: Synthetic Humans for Action Recognition from Unseen Viewpoints Gül Varol, Ivan Laptev and Cordelia Schmid, Andrew Zisserman, Synthetic Human

Gul Varol 59 Dec 14, 2022
The implementation for the SportsCap (IJCV 2021)

SportsCap: Monocular 3D Human Motion Capture and Fine-grained Understanding in Challenging Sports Videos ProjectPage | Paper | Video | Dataset (Part01

Chen Xin 79 Dec 16, 2022
[TIP 2020] Multi-Temporal Scene Classification and Scene Change Detection with Correlation based Fusion

Multi-Temporal Scene Classification and Scene Change Detection with Correlation based Fusion Code for Multi-Temporal Scene Classification and Scene Ch

Lixiang Ru 33 Dec 12, 2022
Orthogonal Jacobian Regularization for Unsupervised Disentanglement in Image Generation (ICCV 2021)

Orthogonal Jacobian Regularization for Unsupervised Disentanglement in Image Generation Home | PyTorch BigGAN Discovery | TensorFlow ProGAN Regulariza

Yuxiang Wei 54 Dec 30, 2022
The code release of paper 'Domain Generalization for Medical Imaging Classification with Linear-Dependency Regularization' NIPS 2020.

Domain Generalization for Medical Imaging Classification with Linear Dependency Regularization The code release of paper 'Domain Generalization for Me

Yufei Wang 56 Dec 28, 2022
Segcache: a memory-efficient and scalable in-memory key-value cache for small objects

Segcache: a memory-efficient and scalable in-memory key-value cache for small objects This repo contains the code of Segcache described in the followi

TheSys Group @ CMU CS 78 Jan 7, 2023
PyTorch Code of "Memory In Memory: A Predictive Neural Network for Learning Higher-Order Non-Stationarity from Spatiotemporal Dynamics"

Memory In Memory Networks It is based on the paper Memory In Memory: A Predictive Neural Network for Learning Higher-Order Non-Stationarity from Spati

Yang Li 12 May 30, 2022
Episodic-memory - Ego4D Episodic Memory Benchmark

Ego4D Episodic Memory Benchmark EGO4D is the world's largest egocentric (first p

null 3 Feb 18, 2022
Implementation of a memory efficient multi-head attention as proposed in the paper, "Self-attention Does Not Need O(n²) Memory"

Memory Efficient Attention Pytorch Implementation of a memory efficient multi-head attention as proposed in the paper, Self-attention Does Not Need O(

Phil Wang 180 Jan 5, 2023
code for our paper "Source Data-absent Unsupervised Domain Adaptation through Hypothesis Transfer and Labeling Transfer"

SHOT++ Code for our TPAMI submission "Source Data-absent Unsupervised Domain Adaptation through Hypothesis Transfer and Labeling Transfer" that is ext

null 75 Dec 16, 2022
The official codes of "Semi-supervised Models are Strong Unsupervised Domain Adaptation Learners".

SSL models are Strong UDA learners Introduction This is the official code of paper "Semi-supervised Models are Strong Unsupervised Domain Adaptation L

Yabin Zhang 26 Dec 26, 2022
A PyTorch implementation for Unsupervised Domain Adaptation by Backpropagation(DANN), support Office-31 and Office-Home dataset

DANN A PyTorch implementation for Unsupervised Domain Adaptation by Backpropagation Prerequisites Linux or OSX NVIDIA GPU + CUDA (may CuDNN) and corre

null 8 Apr 16, 2022
(CVPR2021) DANNet: A One-Stage Domain Adaptation Network for Unsupervised Nighttime Semantic Segmentation

DANNet: A One-Stage Domain Adaptation Network for Unsupervised Nighttime Semantic Segmentation CVPR2021(oral) [arxiv] Requirements python3.7 pytorch==

W-zx-Y 85 Dec 7, 2022
Unified unsupervised and semi-supervised domain adaptation network for cross-scenario face anti-spoofing, Pattern Recognition

USDAN The implementation of Unified unsupervised and semi-supervised domain adaptation network for cross-scenario face anti-spoofing, which is accepte

null 11 Nov 3, 2022
Code of TVT: Transferable Vision Transformer for Unsupervised Domain Adaptation

TVT Code of TVT: Transferable Vision Transformer for Unsupervised Domain Adaptation Datasets: Digit: MNIST, SVHN, USPS Object: Office, Office-Home, Vi

null 37 Dec 15, 2022
CDTrans: Cross-domain Transformer for Unsupervised Domain Adaptation

CDTrans: Cross-domain Transformer for Unsupervised Domain Adaptation [arxiv] This is the official repository for CDTrans: Cross-domain Transformer for

null 238 Dec 22, 2022