Adversarial Learning for Semi-supervised Semantic Segmentation, BMVC 2018

Overview

Adversarial Learning for Semi-supervised Semantic Segmentation

This repo is the pytorch implementation of the following paper:

Adversarial Learning for Semi-supervised Semantic Segmentation
Wei-Chih Hung, Yi-Hsuan Tsai, Yan-Ting Liou, Yen-Yu Lin, and Ming-Hsuan Yang
Proceedings of the British Machine Vision Conference (BMVC), 2018.

Contact: Wei-Chih Hung (whung8 at ucmerced dot edu)

The code are heavily borrowed from a pytorch DeepLab implementation (Link). The baseline model is DeepLabv2-Resnet101 without multiscale training and CRF post processing, which yields meanIOU 73.6% on the VOC2012 validation set.

Please cite our paper if you find it useful for your research.

@inproceedings{Hung_semiseg_2018,
  author = {W.-C. Hung and Y.-H. Tsai and Y.-T. Liou and Y.-Y. Lin and M.-H. Yang},
  booktitle = {Proceedings of the British Machine Vision Conference (BMVC)},
  title = {Adversarial Learning for Semi-supervised Semantic Segmentation},
  year = {2018}
}

Prerequisite

  • CUDA/CUDNN
  • pytorch >= 0.2 (We only support 0.4 for evaluation. Will migrate the code to 0.4 soon.)
  • python-opencv >=3.4.0 (3.3 will cause extra GPU memory on multithread data loader)

Installation

  • Clone this repo
git clone https://github.com/hfslyc/AdvSemiSeg.git
  • Place VOC2012 dataset in AdvSemiSeg/dataset/VOC2012. For training, you will need the augmented labels (Download). The folder structure should be like:
AdvSemiSeg/dataset/VOC2012/JPEGImages
                          /SegmentationClassAug

Testing on VOC2012 validation set with pretrained models

python evaluate_voc.py --pretrained-model semi0.125 --save-dir results

It will download the pretrained model with 1/8 training data and evaluate on the VOC2012 val set. The colorized images will be saved in results/ and the detailed class IOU will be saved in results/result.txt. The mean IOU should be around 68.8%.

  • Available --pretrained-model options: semi0.125, semi0.25, semi0.5 , advFull.

Example visualization results

Training on VOC2012

python train.py --snapshot-dir snapshots \
                --partial-data 0.125 \
                --num-steps 20000 \
                --lambda-adv-pred 0.01 \
                --lambda-semi 0.1 --semi-start 5000 --mask-T 0.2

The parameters correspond to those in Table 5 of the paper.

To evaluate trained model, execute the following:

python evaluate_voc.py --restore-from snapshots/VOC_20000.pth \
                       --save-dir results

Changelog

  • 07/24/2018: Update BMVC results
Comments
  • How to train model   afresh ?

    How to train model afresh ?

    Hi, when I use your code by your README, I find that the model training is fintuning on your well-trained model. When I choose not to fintuning , and want to retrain the data VOC2012. Some wrongs with the loss. The losses don't converge. I want to konw if anything wrong with your code? emmm, I with you to test your code. Thanks.

    opened by rhp228228 16
  • What does the confident map mean?

    What does the confident map mean?

    It is not a bug. I just want to ask this question to make more clearly understand. Your discriminator network produces a spatial map by using fully convolution layer.

    1. Does the spatial map same as the confident map? Or confident map generates by unlabeled data?
    2. Does the value of the spatial map (from D network) in range 0 to 1 or just {0,1}?
    opened by John1231983 12
  • Mean IoU values not matching

    Mean IoU values not matching

    When I run the evaluation code, I get a mean IoU of 47% as against 68.8% as mentioned. This was done using pretrained model using 1/8 training data. Is there something that I have done wrong or some changes that have to be made to the code before running evaluation? The dataset was VOC2012.

    opened by suddu22 8
  • The adv_loss curve is strange.

    The adv_loss curve is strange.

    Hi! First, I'd like to thank you for the very helpful repo. During training with the same discriminator as yours, I have met some problems which I can't figure out. 1. The discriminator loss of pred and GT are almost unchanged for most of the time. So I am wondering if this phenomenon is normal. Btw, I haven't added semi data yet.

    adv_loss

    opened by Pyten 7
  • Loss_adv_p increasing, while loss_D decreasing. Is it correct?

    Loss_adv_p increasing, while loss_D decreasing. Is it correct?

    Hello, I want to ask one question related to the loss_adv_p and loss_D. As the log, the loss_adv_p tends to increase while the loss_D tends to decrease. We expect that loss_D will decrease, it is correct; however, how about the loss_adv_p? I found one interesting thing that is args.lambda_adv_pred, you can set it to 0.5, then the loss_adv_p will decrease but the loss loss_D will increase. They looks opposite side Thanks

    iter =        0/   20000, loss_seg = 3.045, loss_adv_p = 0.695, loss_D = 0.693, loss_semi = 0.000
    

    and at 180 iters

    iter =      180/   20000, loss_seg = 0.490, loss_adv_p = 1.358, loss_D = 0.572, loss_semi = 0.000
    
    opened by John1231983 6
  • Some questions I would like to ask you

    Some questions I would like to ask you

    Hello, I am planning to use your data to run your network but it fails. My data is in two categories. One is for the background and the other is set to 0 and 1, respectively. For the single channel label map, use your The network has been trained, but the test result output is all 0. May I ask if I need to adjust some parameters, thank you

    opened by watchmexiang 5
  • RuntimeError: CUDNN_STATUS_MAPPING_ERROR

    RuntimeError: CUDNN_STATUS_MAPPING_ERROR

    Hey , When I try to validate the results , I am getting this error

      output = model(Variable(image, volatile=True).cuda(gpu0))
    Traceback (most recent call last):
      File "evaluate_voc.py", line 235, in <module>
        main()
      File "evaluate_voc.py", line 214, in main
        output = model(Variable(image, volatile=True).cuda(gpu0))
      File "/home/ubuntu/.local/lib/python2.7/site-packages/torch/nn/modules/module.py", line 491, in __call__
        result = self.forward(*input, **kwargs)
      File "/home/ubuntu/summer_interns/jose/AdvSemiSeg/model/deeplab.py", line 167, in forward
        x = self.conv1(x)
      File "/home/ubuntu/.local/lib/python2.7/site-packages/torch/nn/modules/module.py", line 491, in __call__
        result = self.forward(*input, **kwargs)
      File "/home/ubuntu/.local/lib/python2.7/site-packages/torch/nn/modules/conv.py", line 301, in forward
        self.padding, self.dilation, self.groups)
    RuntimeError: CUDNN_STATUS_MAPPING_ERROR
    
    
    opened by jeya-maria-jose 5
  • ModuleNotFoundError: No module named 'copy_reg'

    ModuleNotFoundError: No module named 'copy_reg'

    Thanks for sharing your work. I used evaluate code and I got the error

        import copy_reg
    ModuleNotFoundError: No module named 'copy_reg'
    

    I am using python 3.6 from conda install, Ubuntu 16.04. How can I fix it? Thanks

    opened by John1231983 5
  • how to run on cpu

    how to run on cpu

    raise RuntimeError('Attempting to deserialize object on a CUDA ' RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is False. If you are running on a CPU-only machine, please use torch.load with map_location=torch.device('cpu') to map your storages to the CPU.

    How can i run it on cpu.Hlep me,please.Thank you!

    opened by wwwmmmqqq 4
  • Questions about ignore_mask = (y.numpy() == 255) ?

    Questions about ignore_mask = (y.numpy() == 255) ?

    Hello, first of all, thank you for sharing your work. I have a question in the process of looking at the code.ignore_mask = (y.numpy() == 255) Can you explain this to me? If my label y has a value of 0-9, can it be written like this? I look forward to your reply. Thank you very much.

    opened by sunshineymt 4
  • confidence map

    confidence map

    Excuse me, There are one more questions...hope it not bothing you too much... "The output of D is a probability map with values ranges from 0-1. When the input is unlabeled data, we use the D output map as the indicator for semi-supervised learning."

    D_out = interp(model_D(F.softmax(pred))) D_out_sigmoid = F.sigmoid(D_out).data.cpu().numpy().squeeze(axis=1) ##following is used to draw the confindence map in your papar Figure3 for i in range(args.batch_size): plt.imshow(D_out_sigmoid[i], cmap='jet') plt.show() Can I interpret the D_out_sigmoid is the confidence map you mentioned? I use VOC_20000.pth and VOC_20000_D.pth(when use these two model the evaluatation mIOU is 0.709) as the parameters for RESTORE_FROM and RESTORE_FROM_D,and tried to get the figure of confidence map,but it looks not matching so well,it looks weird ,can you explain how you get the confidence map in your paper?

    opened by LeiyuanMa 4
  • Quenstion on Loss

    Quenstion on Loss

    Hi, sir. I have a quenstion about loss semi. In training process, my loss_semi is initialy about 0.4 but after long training it significantly decreases. Now in range [0.000 0.006]. Is everything ok or I compile wrong ?

    opened by Holmes2002 0
  • Facing Issue for running Adversarial Semi-Segmentation code on Custom dataset or CityScapes dataset

    Facing Issue for running Adversarial Semi-Segmentation code on Custom dataset or CityScapes dataset

    Hello everyone, Recently, I have managed to run the code correctly on Pascal VOC dataset, but when I tried to run the code on my own custom dataset or CityScape dataset, I am unable to run and faced debugging issues. Since I am working on python3.6, I made the following changes in the source code:

    • substitute Enumerate.next() by Enumerate.next()
    • substitute xrange by range

    Also, I change the tensor type from gpu to cpu, e.g. images = Variable(images).cuda(args.gpu) to images = Variable(images).cpu(). As I searched on the internet, I noticed there might be some issue with the number of class. But then I guessed that I have correctly chosen the number of classes, as 30 classes in cityscapes case; or I changed the number of class to 31, but even then facing the same error. BTW, I'm running the code on GoogleColab, and it worked successfully for Pascal VOC dataset. The Error report is as below,

    /usr/local/lib/python3.7/dist-packages/torch/optim/sgd.py:105: UserWarning: optimizer contains a parameter group with duplicate parameters; in future, this will cause an error; see github.com/pytorch/pytorch/issues/40967 for more information super(SGD, self).init(params, defaults) train.py:379: UserWarning: Implicit dimension choice for softmax has been deprecated. Change the call to include dim=X as an argument. D_out = interp(model_D(F.softmax(pred))) /usr/local/lib/python3.7/dist-packages/torch/nn/functional.py:1960: UserWarning: nn.functional.sigmoid is deprecated. Use torch.sigmoid instead. warnings.warn("nn.functional.sigmoid is deprecated. Use torch.sigmoid instead.") train.py:382: DeprecationWarning: np.bool is a deprecated alias for the builtin bool. To silence this warning, use bool by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use np.bool_ here. Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations ignore_mask_remain = np.zeros(D_out_sigmoid.shape).astype(np.bool) /usr/local/lib/python3.7/dist-packages/torch/nn/_reduction.py:42: UserWarning: size_average and reduce args will be deprecated, please use reduction='mean' instead. warnings.warn(warning.format(ret)) pred_train = 88 label_train = 88 Traceback (most recent call last): File "train.py", line 524, in main() File "train.py", line 435, in main loss_seg = loss_calc(pred, labels) File "train.py", line 178, in loss_calc return criterion(pred, label) File "/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py", line 1130, in _call_impl return forward_call(*input, **kwargs) File "/content/drive/MyDrive/Tasweer_Research/Adversarial_Learning_Semi_supervised/AdvSemiSeg/utils/loss.py", line 49, in forward loss = F.cross_entropy(predict, target, weight=weight, size_average=self.size_average) File "/usr/local/lib/python3.7/dist-packages/torch/nn/functional.py", line 3014, in cross_entropy return torch._C._nn.cross_entropy_loss(input, target, weight, _Reduction.get_enum(reduction), ignore_index, label_smoothing) IndexError: Target 119 is out of bounds.

    opened by tasveerahmad 0
  • Problem in deeplab model

    Problem in deeplab model

    The DeepLab implementation seems to have a long-lasting unobserved issue in Classifier_Module: in line 116 the out variable is returned in the first iteration of the loop. So it only sums up the output of the first and second atrous convolutions in ASPP module (not all 4 of them). The source of this problem probably is a bug in the original implementation which was fixed later.

    Unfortunately many other researchers have been used this implementation (or the original implementation before its bug being fixed). So whoever reads this issue better be cautious about the DeepLabv2 pytorch implementation used in other repositories too.

    opened by dlotfi 0
  • Fix ASPP

    Fix ASPP

    Thank you for sharing your implementation. I would like to fix the ASPP part. This change makes Classifier_Module to use all of the four dilated convolutions properly.

    In speedinghzl/Pytorch-Deeplab, which this repository is based on, the ASPP code was fixed in the same way. https://github.com/speedinghzl/Pytorch-Deeplab/commit/cf1d48afe9c611c90f8cabba014697bb0aac5284#diff-246517e88085928a3e2b3e706e7ba4c7d7803f0e7d2e5fd59e5a414abe048cab

    I am sorry if I may be mistaken.

    opened by y60 0
  • all losses are NaN

    all losses are NaN

    why all my losses in experiment are NaN? I used the same code, parameters and dataset. like this "iter = 19998/20000, loss_seg = nan, loss_adv_p = nan, loss_D = nan, loss_semi = nan, loss_semi_adv = nan semi ratio: 1.0000"

    opened by aoaoaoaoa 0
Owner
Wayne Hung
Wayne Hung
Shape-aware Semi-supervised 3D Semantic Segmentation for Medical Images

SASSnet Code for paper: Shape-aware Semi-supervised 3D Semantic Segmentation for Medical Images(MICCAI 2020) Our code is origin from UA-MT You can fin

klein 125 Jan 3, 2023
Semi-supervised Semantic Segmentation with Directional Context-aware Consistency (CVPR 2021)

Semi-supervised Semantic Segmentation with Directional Context-aware Consistency (CAC) Xin Lai*, Zhuotao Tian*, Li Jiang, Shu Liu, Hengshuang Zhao, Li

Jia Research Lab 137 Dec 14, 2022
Anti-Adversarially Manipulated Attributions for Weakly and Semi-Supervised Semantic Segmentation (CVPR 2021)

Anti-Adversarially Manipulated Attributions for Weakly and Semi-Supervised Semantic Segmentation Input Image Initial CAM Successive Maps with adversar

Jungbeom Lee 110 Dec 7, 2022
Semi-supervised Semantic Segmentation with Directional Context-aware Consistency (CVPR 2021)

Semi-supervised Semantic Segmentation with Directional Context-aware Consistency (CAC) Xin Lai*, Zhuotao Tian*, Li Jiang, Shu Liu, Hengshuang Zhao, Li

DV Lab 137 Dec 14, 2022
[CVPR 2021] Semi-Supervised Semantic Segmentation with Cross Pseudo Supervision

TorchSemiSeg [CVPR 2021] Semi-Supervised Semantic Segmentation with Cross Pseudo Supervision by Xiaokang Chen1, Yuhui Yuan2, Gang Zeng1, Jingdong Wang

Chen XiaoKang 387 Jan 8, 2023
ST++: Make Self-training Work Better for Semi-supervised Semantic Segmentation

ST++ This is the official PyTorch implementation of our paper: ST++: Make Self-training Work Better for Semi-supervised Semantic Segmentation. Lihe Ya

Lihe Yang 147 Jan 3, 2023
[ICCV 2021] A Simple Baseline for Semi-supervised Semantic Segmentation with Strong Data Augmentation

[ICCV 2021] A Simple Baseline for Semi-supervised Semantic Segmentation with Strong Data Augmentation

CodingMan 45 Dec 12, 2022
[CVPR 2022] Semi-Supervised Semantic Segmentation Using Unreliable Pseudo-Labels

Using Unreliable Pseudo Labels Official PyTorch implementation of Semi-Supervised Semantic Segmentation Using Unreliable Pseudo Labels, CVPR 2022. Ple

Haochen Wang 268 Dec 24, 2022
[cvpr22] Perturbed and Strict Mean Teachers for Semi-supervised Semantic Segmentation

PS-MT [cvpr22] Perturbed and Strict Mean Teachers for Semi-supervised Semantic Segmentation by Yuyuan Liu, Yu Tian, Yuanhong Chen, Fengbei Liu, Vasile

Yuyuan Liu 132 Jan 3, 2023
Project looking into use of autoencoder for semi-supervised learning and comparing data requirements compared to supervised learning.

Project looking into use of autoencoder for semi-supervised learning and comparing data requirements compared to supervised learning.

Tom-R.T.Kvalvaag 2 Dec 17, 2021
Semi-supervised Representation Learning for Remote Sensing Image Classification Based on Generative Adversarial Networks

SSRL-for-image-classification Semi-supervised Representation Learning for Remote Sensing Image Classification Based on Generative Adversarial Networks

Feng 2 Nov 19, 2021
[BMVC 2021] Official PyTorch Implementation of Self-supervised learning of Image Scale and Orientation Estimation

Self-Supervised Learning of Image Scale and Orientation Estimation (BMVC 2021) This is the official implementation of the paper "Self-Supervised Learn

Jongmin Lee 17 Nov 10, 2022
Boosting Adversarial Attacks with Enhanced Momentum (BMVC 2021)

EMI-FGSM This repository contains code to reproduce results from the paper: Boosting Adversarial Attacks with Enhanced Momentum (BMVC 2021) Xiaosen Wa

John Hopcroft Lab at HUST 10 Sep 26, 2022
UniMoCo: Unsupervised, Semi-Supervised and Full-Supervised Visual Representation Learning

UniMoCo: Unsupervised, Semi-Supervised and Full-Supervised Visual Representation Learning This is the official PyTorch implementation for UniMoCo pape

dddzg 49 Jan 2, 2023
Recall Loss for Semantic Segmentation (This repo implements the paper: Recall Loss for Semantic Segmentation)

Recall Loss for Semantic Segmentation (This repo implements the paper: Recall Loss for Semantic Segmentation) Download Synthia dataset The model uses

null 32 Sep 21, 2022
Semi Supervised Learning for Medical Image Segmentation, a collection of literature reviews and code implementations.

Semi-supervised-learning-for-medical-image-segmentation. Recently, semi-supervised image segmentation has become a hot topic in medical image computin

Healthcare Intelligence Laboratory 1.3k Jan 3, 2023
Hybrid CenterNet - Hybrid-supervised object detection / Weakly semi-supervised object detection

Hybrid-Supervised Object Detection System Object detection system trained by hybrid-supervision/weakly semi-supervision (HSOD/WSSOD): This project is

null 5 Dec 10, 2022
code for paper"A High-precision Semantic Segmentation Method Combining Adversarial Learning and Attention Mechanism"

PyTorch implementation of UAGAN(U-net Attention Generative Adversarial Networks) This repository contains the source code for the paper "A High-precis

Tong 8 Apr 25, 2022
Visualizer using audio and semantic analysis to explore BigGAN (Brock et al., 2018) latent space.

BigGAN Audio Visualizer Description This visualizer explores BigGAN (Brock et al., 2018) latent space by using pitch/tempo of an audio file to generat

Rush Kapoor 2 Nov 21, 2022