Semantic Segmentation in Pytorch

Related tags

Deep Learning semseg
Overview

PyTorch Semantic Segmentation

Introduction

This repository is a PyTorch implementation for semantic segmentation / scene parsing. The code is easy to use for training and testing on various datasets. The codebase mainly uses ResNet50/101/152 as backbone and can be easily adapted to other basic classification structures. Implemented networks including PSPNet and PSANet, which ranked 1st places in ImageNet Scene Parsing Challenge 2016 @ECCV16, LSUN Semantic Segmentation Challenge 2017 @CVPR17 and WAD Drivable Area Segmentation Challenge 2018 @CVPR18. Sample experimented datasets are ADE20K, PASCAL VOC 2012 and Cityscapes.

Update

  • 2020.05.15: Branch master, use official nn.SyncBatchNorm, only multiprocessing training is supported, tested with pytorch 1.4.0.
  • 2019.05.29: Branch 1.0.0, both multithreading training (nn.DataParallel) and multiprocessing training (nn.parallel.DistributedDataParallel) (recommended) are supported. And the later one is much faster. Use syncbn from EncNet and apex, tested with pytorch 1.0.0.

Usage

  1. Highlight:

  2. Requirement:

    • Hardware: 4-8 GPUs (better with >=11G GPU memory)
    • Software: PyTorch>=1.1.0, Python3, tensorboardX,
  3. Clone the repository:

    git clone https://github.com/hszhao/semseg.git
  4. Train:

    • Download related datasets and symlink the paths to them as follows (you can alternatively modify the relevant paths specified in folder config):

      cd semseg
      mkdir -p dataset
      ln -s /path_to_ade20k_dataset dataset/ade20k
      
    • Download ImageNet pre-trained models and put them under folder initmodel for weight initialization. Remember to use the right dataset format detailed in FAQ.md.

    • Specify the gpu used in config then do training:

      sh tool/train.sh ade20k pspnet50
    • If you are using SLURM for nodes manager, uncomment lines in train.sh and then do training:

      sbatch tool/train.sh ade20k pspnet50
  5. Test:

    • Download trained segmentation models and put them under folder specified in config or modify the specified paths.

    • For full testing (get listed performance):

      sh tool/test.sh ade20k pspnet50
    • Quick demo on one image:

      PYTHONPATH=./ python tool/demo.py --config=config/ade20k/ade20k_pspnet50.yaml --image=figure/demo/ADE_val_00001515.jpg TEST.scales '[1.0]'
  6. Visualization: tensorboardX incorporated for better visualization.

    tensorboard --logdir=exp/ade20k
  7. Other:

    • Resources: GoogleDrive LINK contains shared models, visual predictions and data lists.
    • Models: ImageNet pre-trained models and trained segmentation models can be accessed. Note that our ImageNet pretrained models are slightly different from original ResNet implementation in the beginning part.
    • Predictions: Visual predictions of several models can be accessed.
    • Datasets: attributes (names and colors) are in folder dataset and some sample lists can be accessed.
    • Some FAQs: FAQ.md.
    • Former video predictions: high accuracy -- PSPNet, PSANet; high efficiency -- ICNet.

Performance

Description: mIoU/mAcc/aAcc stands for mean IoU, mean accuracy of each class and all pixel accuracy respectively. ss denotes single scale testing and ms indicates multi-scale testing. Training time is measured on a sever with 8 GeForce RTX 2080 Ti. General parameters cross different datasets are listed below:

  • Train Parameters: sync_bn(True), scale_min(0.5), scale_max(2.0), rotate_min(-10), rotate_max(10), zoom_factor(8), ignore_label(255), aux_weight(0.4), batch_size(16), base_lr(1e-2), power(0.9), momentum(0.9), weight_decay(1e-4).
  • Test Parameters: ignore_label(255), scales(single: [1.0], multiple: [0.5 0.75 1.0 1.25 1.5 1.75]).
  1. ADE20K: Train Parameters: classes(150), train_h(473/465-PSP/A), train_w(473/465-PSP/A), epochs(100). Test Parameters: classes(150), test_h(473/465-PSP/A), test_w(473/465-PSP/A), base_size(512).

    • Setting: train on train (20210 images) set and test on val (2000 images) set.
    Network mIoU/mAcc/aAcc(ss) mIoU/mAcc/pAcc(ms) Training Time
    PSPNet50 0.4189/0.5227/0.8039. 0.4284/0.5266/0.8106. 14h
    PSANet50 0.4229/0.5307/0.8032. 0.4305/0.5312/0.8101. 14h
    PSPNet101 0.4310/0.5375/0.8107. 0.4415/0.5426/0.8172. 20h
    PSANet101 0.4337/0.5385/0.8102. 0.4414/0.5392/0.8170. 20h
  2. PSACAL VOC 2012: Train Parameters: classes(21), train_h(473/465-PSP/A), train_w(473/465-PSP/A), epochs(50). Test Parameters: classes(21), test_h(473/465-PSP/A), test_w(473/465-PSP/A), base_size(512).

    • Setting: train on train_aug (10582 images) set and test on val (1449 images) set.
    Network mIoU/mAcc/aAcc(ss) mIoU/mAcc/pAcc(ms) Training Time
    PSPNet50 0.7705/0.8513/0.9489. 0.7802/0.8580/0.9513. 3.3h
    PSANet50 0.7725/0.8569/0.9491. 0.7787/0.8606/0.9508. 3.3h
    PSPNet101 0.7907/0.8636/0.9534. 0.7963/0.8677/0.9550. 5h
    PSANet101 0.7870/0.8642/0.9528. 0.7966/0.8696/0.9549. 5h
  3. Cityscapes: Train Parameters: classes(19), train_h(713/709-PSP/A), train_w(713/709-PSP/A), epochs(200). Test Parameters: classes(19), test_h(713/709-PSP/A), test_w(713/709-PSP/A), base_size(2048).

    • Setting: train on fine_train (2975 images) set and test on fine_val (500 images) set.
    Network mIoU/mAcc/aAcc(ss) mIoU/mAcc/pAcc(ms) Training Time
    PSPNet50 0.7730/0.8431/0.9597. 0.7838/0.8486/0.9617. 7h
    PSANet50 0.7745/0.8461/0.9600. 0.7818/0.8487/0.9622. 7.5h
    PSPNet101 0.7863/0.8577/0.9614. 0.7929/0.8591/0.9638. 10h
    PSANet101 0.7842/0.8599/0.9621. 0.7940/0.8631/0.9644. 10.5h

Citation

If you find the code or trained models useful, please consider citing:

@misc{semseg2019,
  author={Zhao, Hengshuang},
  title={semseg},
  howpublished={\url{https://github.com/hszhao/semseg}},
  year={2019}
}
@inproceedings{zhao2017pspnet,
  title={Pyramid Scene Parsing Network},
  author={Zhao, Hengshuang and Shi, Jianping and Qi, Xiaojuan and Wang, Xiaogang and Jia, Jiaya},
  booktitle={CVPR},
  year={2017}
}
@inproceedings{zhao2018psanet,
  title={{PSANet}: Point-wise Spatial Attention Network for Scene Parsing},
  author={Zhao, Hengshuang and Zhang, Yi and Liu, Shu and Shi, Jianping and Loy, Chen Change and Lin, Dahua and Jia, Jiaya},
  booktitle={ECCV},
  year={2018}
}

Question

Some FAQ.md collected. You are welcome to send pull requests or give some advices. Contact information: hengshuangzhao at gmail.com.

Comments
  • Training performance drop on cityscapes with default parameters.

    Training performance drop on cityscapes with default parameters.

    Training log. [2019-06-14 18:10:31,725 INFO train.py line 154 10613] arch: psp aux_weight: 0.4 base_lr: 0.01 base_size: 2048 batch_size: 16 batch_size_val: 1 classes: 19 colors_path: dataset/cityscapes/cityscapes_colors.txt data_root: datasets/cityscapes/ dist_backend: nccl dist_url: tcp://127.0.0.1:6789 distributed: True epochs: 200 evaluate: False has_prediction: False ignore_label: 255 index_split: 5 index_start: 0 index_step: 0 keep_batchnorm_fp32: None layers: 50 loss_scale: None manual_seed: None model_path: exp/cityscapes/pspnet50/model/train_epoch_200.pth momentum: 0.9 multiprocessing_distributed: True names_path: dataset/cityscapes/cityscapes_names.txt ngpus_per_node: 8 opt_level: O0 power: 0.9 print_freq: 10 rank: 0 resume: None rotate_max: 10 rotate_min: -10 save_folder: exp/cityscapes/pspnet50/result/epoch_200/val/ss save_freq: 1 save_path: exp/cityscapes/pspnet50/model scale_max: 2.0 scale_min: 0.5 scales: [1.0] split: val start_epoch: 0 sync_bn: True test_gpu: [0] test_h: 713 test_list: semseg-master/dataset/cityscapes/fine_val.txt test_w: 713 train_gpu: [0, 1, 2, 3, 4, 5, 6, 7] train_h: 713 train_list: semseg-master/dataset/cityscapes/fine_train.txt train_w: 713 use_apex: True val_list: semseg-master/dataset/cityscapes/fine_val.txt weight: None weight_decay: 0.0001 workers: 16 world_size: 8 zoom_factor: 8

    Test log [2019-06-16 08:08:38,259 INFO test.py line 249 23114] Eval result: mIoU/mAcc/allAcc 0.7695/0.8400/0.9603. [2019-06-16 08:08:38,259 INFO test.py line 251 23114] Class_0 result: iou/accuracy 0.9804/0.9881, name: road. [2019-06-16 08:08:38,259 INFO test.py line 251 23114] Class_1 result: iou/accuracy 0.8454/0.9255, name: sidewalk. [2019-06-16 08:08:38,259 INFO test.py line 251 23114] Class_2 result: iou/accuracy 0.9235/0.9677, name: building. [2019-06-16 08:08:38,259 INFO test.py line 251 23114] Class_3 result: iou/accuracy 0.5557/0.6280, name: wall. [2019-06-16 08:08:38,259 INFO test.py line 251 23114] Class_4 result: iou/accuracy 0.6037/0.6966, name: fence. [2019-06-16 08:08:38,260 INFO test.py line 251 23114] Class_5 result: iou/accuracy 0.6419/0.7436, name: pole. [2019-06-16 08:08:38,260 INFO test.py line 251 23114] Class_6 result: iou/accuracy 0.7032/0.8118, name: traffic light. [2019-06-16 08:08:38,260 INFO test.py line 251 23114] Class_7 result: iou/accuracy 0.7856/0.8581, name: traffic sign. [2019-06-16 08:08:38,260 INFO test.py line 251 23114] Class_8 result: iou/accuracy 0.9260/0.9675, name: vegetation. [2019-06-16 08:08:38,260 INFO test.py line 251 23114] Class_9 result: iou/accuracy 0.6553/0.7457, name: terrain. [2019-06-16 08:08:38,260 INFO test.py line 251 23114] Class_10 result: iou/accuracy 0.9460/0.9770, name: sky. [2019-06-16 08:08:38,260 INFO test.py line 251 23114] Class_11 result: iou/accuracy 0.8237/0.9218, name: person. [2019-06-16 08:08:38,260 INFO test.py line 251 23114] Class_12 result: iou/accuracy 0.6327/0.7595, name: rider. [2019-06-16 08:08:38,260 INFO test.py line 251 23114] Class_13 result: iou/accuracy 0.9490/0.9782, name: car. [2019-06-16 08:08:38,260 INFO test.py line 251 23114] Class_14 result: iou/accuracy 0.7279/0.7737, name: truck. [2019-06-16 08:08:38,260 INFO test.py line 251 23114] Class_15 result: iou/accuracy 0.8610/0.9364, name: bus. [2019-06-16 08:08:38,260 INFO test.py line 251 23114] Class_16 result: iou/accuracy 0.6388/0.6618, name: train. [2019-06-16 08:08:38,260 INFO test.py line 251 23114] Class_17 result: iou/accuracy 0.6448/0.7306, name: motorcycle. [2019-06-16 08:08:38,260 INFO test.py line 251 23114] Class_18 result: iou/accuracy 0.7760/0.8881, name: bicycle.

    By the way, training time is much longer than your report. ( i use 8 P40)

    opened by jianlong-yuan 16
  • RuntimeError: CUDA out of memory.

    RuntimeError: CUDA out of memory.

    Totally 20210 samples in train set.
    Starting Checking image&label pair train list...
    Checking image&label pair train list done!
    Traceback (most recent call last):
      File "tool/train.py", line 426, in <module>
        main()
      File "tool/train.py", line 107, in main
        main_worker(args.train_gpu, args.ngpus_per_node, args)
      File "tool/train.py", line 236, in main_worker
        loss_train, mIoU_train, mAcc_train, allAcc_train = train(train_loader, model, optimizer, epoch)
      File "tool/train.py", line 281, in train
        output, main_loss, aux_loss = model(input, target)
      File "/home/xrlin/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 547, in __call__
        result = self.forward(*input, **kwargs)
      File "/home/xrlin/anaconda3/lib/python3.7/site-packages/torch/nn/parallel/data_parallel.py", line 150, in forward
        return self.module(*inputs[0], **kwargs[0])
      File "/home/xrlin/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 547, in __call__
        result = self.forward(*input, **kwargs)
      File "/home/xrlin/Desktop/semseg/model/pspnet.py", line 91, in forward
        x = self.layer4(x_tmp)
      File "/home/xrlin/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 547, in __call__
        result = self.forward(*input, **kwargs)
      File "/home/xrlin/anaconda3/lib/python3.7/site-packages/torch/nn/modules/container.py", line 92, in forward
        input = module(input)
      File "/home/xrlin/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 547, in __call__
        result = self.forward(*input, **kwargs)
      File "/home/xrlin/Desktop/semseg/model/resnet.py", line 87, in forward
        out = self.bn3(out)
      File "/home/xrlin/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 547, in __call__
        result = self.forward(*input, **kwargs)
      File "/home/xrlin/anaconda3/lib/python3.7/site-packages/torch/nn/modules/batchnorm.py", line 81, in forward
        exponential_average_factor, self.eps)
      File "/home/xrlin/anaconda3/lib/python3.7/site-packages/torch/nn/functional.py", line 1656, in batch_norm
        training, momentum, eps, torch.backends.cudnn.enabled
    RuntimeError: CUDA out of memory. Tried to allocate 450.00 MiB (GPU 0; 23.65 GiB total capacity; 22.42 GiB already allocated; 105.12 MiB free; 311.16 MiB cached)
    
    

    I tried to run every configuration in this project with one GPU (Titan RTX with 24GB memory), but it shows CUDA out of memory, which is wired because there are no other programs using the GPU. Do you have any suggestions for this issue?

    opened by convnets 10
  • OMP: Error #13: Assertion failure at z_Linux_util.cpp(2361).

    OMP: Error #13: Assertion failure at z_Linux_util.cpp(2361).

    When trying to use multithread, the following error occurs:

    OMP: Hint Please submit a bug report with this message, compile and run commands used, and machine configuration info including native compiler and ope│··································
    rating system versions. Faster response will be obtained by including all program sources. For information on submitting this issue, please see http://│··································
    www.intel.com/software/products/support/.                                                                                                              │··································
    OMP: Error #13: Assertion failure at z_Linux_util.cpp(2361).                                                                                           │··································
    OMP: Hint Please submit a bug report with this message, compile and run commands used, and machine configuration info including native compiler and ope│··································
    rating system versions. Faster response will be obtained by including all program sources. For information on submitting this issue, please see http://│··································
    www.intel.com/software/products/support/.                                                                                                              │··································
    OMP: Error #13: Assertion failure at z_Linux_util.cpp(2361).                                                                                           │··································
    OMP: Hint Please submit a bug report with this message, compile and run commands used, and machine configuration info including native compiler and ope│··································
    rating system versions. Faster response will be obtained by including all program sources. For information on submitting this issue, please see http://│··································
    www.intel.com/software/products/support/.                                                                                                              │··································
    OMP: Error #13: Assertion failure at z_Linux_util.cpp(2361).                                                                                           │··································
    OMP: Hint Please submit a bug report with this message, compile and run commands used, and machine configuration info including native compiler and ope│··································
    rating system versions. Faster response will be obtained by including all program sources. For information on submitting this issue, please see http://│··································
    www.intel.com/software/products/support/.                                                                                                              │··································
    OMP: Error #13: Assertion failure at z_Linux_util.cpp(2361).                                                                                           │··································
    OMP: Hint Please submit a bug report with this message, compile and run commands used, and machine configuration info including native compiler and ope│··································
    rating system versions. Faster response will be obtained by including all program sources. For information on submitting this issue, please see http://│··································
    www.intel.com/software/products/support/.                                                                                                              │··································
    OMP: Error #13: Assertion failure at z_Linux_util.cpp(2361).                                                                                           │··································
    OMP: Hint Please submit a bug report with this message, compile and run commands used, and machine configuration info including native compiler and ope│··································
    rating system versions. Faster response will be obtained by including all program sources. For information on submitting this issue, please see http://│··································
    www.intel.com/software/products/support/.                                                                                                              │··································
    OMP: Error #13: Assertion failure at z_Linux_util.cpp(2361).                                                                                           │··································
    OMP: Hint Please submit a bug report with this message, compile and run commands used, and machine configuration info including native compiler and ope│··································
    rating system versions. Faster response will be obtained by including all program sources. For information on submitting this issue, please see http://│··································
    www.intel.com/software/products/support/.                                                                                                              │··································
    OMP: Error #13: Assertion failure at z_Linux_util.cpp(2361).                                                                                           │··································
    OMP: Hint Please submit a bug report with this message, compile and run commands used, and machine configuration info including native compiler and ope│··································
    rating system versions. Faster response will be obtained by including all program sources. For information on submitting this issue, please see http://│··································
    www.intel.com/software/products/support/.                                                                                                              │··································
    Traceback (most recent call last):                                                                                                                     │··································
      File "tool/train.py", line 456, in <module>                                                                                                          │··································
        main()                                                                                                                                             │··································
      File "tool/train.py", line 106, in main                                                                                                              │··································
        mp.spawn(main_worker, nprocs=args.ngpus_per_node, args=(args.ngpus_per_node, args))                                                                │··································
      File "/home/lzx/.conda/envs/pytorchseg10/lib/python3.7/site-packages/torch/multiprocessing/spawn.py", line 171, in spawn                             │··································
        while not spawn_context.join():                                                                                                                    │··································
      File "/home/lzx/.conda/envs/pytorchseg10/lib/python3.7/site-packages/torch/multiprocessing/spawn.py", line 107, in join                              │··································
        (error_index, name)                                                                                                                                │··································
    Exception: process 2 terminated with signal SIGABRT
    

    This will happen when multiprocessing_distributed and use_apex are True. Configuration details:

    TRAIN:
      arch: psp
      layers: 101
      sync_bn: False  # adopt syncbn or not
      train_h: 585
      train_w: 585
      scale_min: 0.5  # minimum random scale
      scale_max: 2.0  # maximum random scale
      rotate_min: -10  # minimum random rotate
      rotate_max: 10  # maximum random rotate
      zoom_factor: 8  # zoom factor for final prediction during training, be in [1, 2, 4, 8]
      ignore_label: 255
      aux_weight: 0.4
      train_gpu: [0, 1, 2, 3, 4, 5, 6, 7]
      workers: 16  # data loader workers
      batch_size: 16  # batch size for training
      batch_size_val: 8  # batch size for validation during training, memory and speed tradeoff
      base_lr: 0.01
      epochs: 200
      start_epoch: 0
      new_epoch: 300  # for resume, how many new epochs to train
      power: 0.9
      momentum: 0.9
      weight_decay: 0.0001
      manual_seed: 520
      print_freq: 10
      save_freq: 1
      save_path: exp/cityscapes/pspnet101/model
      weight:  # path to initial weight (default: none)
      resume:  # path to latest checkpoint (default: none)
      evaluate: True # evaluate on validation set, extra gpu memory needed and small batch_size_val is recommend
    Distributed:
      dist_url: tcp://127.0.0.1:6789
      dist_backend: 'nccl'
      multiprocessing_distributed: True
      world_size: 1
      rank: 0
      use_apex: True
      opt_level: 'O0'
      keep_batchnorm_fp32:
      loss_scale:
    

    I have tried to do some search but they are not working.

    Could you please give me some advice?

    Thanks a lot!

    opened by zhixuanli 6
  • Resume training performance drop

    Resume training performance drop

    Hi, I'm trying to use your fantastic code but encountered something confused when I try to load a checkpoint of 200 epoch training.

    The mIoU of training reached 0.739 at epoch 200. But when I try to load this checkpoint and continually training, the performance dropped from 0.739 to 0.563 at epoch 201.

    It's quite hard for me to understand this phenomenon, could you give me some advices? Thank you so much!

    Here is my config file:

    DATA:
      data_root: /datasets-ssd/cityscapes
      train_list: dataset/cityscapes/list/fine_train.txt
      val_list: dataset/cityscapes/list/fine_val.txt
      classes: 19
    
    TRAIN:
      arch: psp
      layers: 101
      sync_bn: True  # adopt syncbn or not
      train_h: 513
      train_w: 513
      scale_min: 0.5  # minimum random scale
      scale_max: 2.0  # maximum random scale
      rotate_min: -10  # minimum random rotate
      rotate_max: 10  # maximum random rotate
      zoom_factor: 8  # zoom factor for final prediction during training, be in [1, 2, 4, 8]
      ignore_label: 255
      aux_weight: 0.4
    #  train_gpu: [0, 1, 2, 3, 4, 5, 6, 7]
      train_gpu: [0]
      workers: 6  # data loader workers
      batch_size: 2  # batch size for training
      batch_size_val: 1  # batch size for validation during training, memory and speed tradeoff
      base_lr: 0.01
      epochs: 400
      start_epoch: 200
      power: 0.9
      momentum: 0.9
      weight_decay: 0.0001
      manual_seed: 520
      print_freq: 10
      save_freq: 1
      save_path: exp/cityscapes/pspnet101/model
      weight:  # path to initial weight (default: none)
      resume:  exp/cityscapes/pspnet101/model/train_epoch_200.pth # path to latest checkpoint (default: none)
      evaluate: False  # evaluate on validation set, extra gpu memory needed and small batch_size_val is recommend
    Distributed:
      distributed: True
      dist_url: tcp://127.0.0.1:6789
      dist_backend: 'nccl'
      multiprocessing_distributed: True
      world_size: 1
      rank: 0
      use_apex: True
      opt_level: 'O0'
      keep_batchnorm_fp32:
      loss_scale:
    
    TEST:
      test_list: dataset/cityscapes/list/fine_val.txt
      split: val  # split in [train, val and test]
      base_size: 2048  # based size for scaling
      test_h: 713
      test_w: 713
      scales: [1.0]  # evaluation scales, ms as [0.5, 0.75, 1.0, 1.25, 1.5, 1.75]
      has_prediction: False  # has prediction already or not
      index_start: 0  # evaluation start index in list
      index_step: 0  # evaluation step index in list, 0 means to end
      test_gpu: [0]
      model_path: exp/cityscapes/pspnet101/model/train_epoch_400.pth  # evaluation model path
      save_folder: exp/cityscapes/pspnet101/result/epoch_400/val/ss  # results save folder
      colors_path: dataset/cityscapes/cityscapes_colors.txt  # path of dataset colors
      names_path: dataset/cityscapes/cityscapes_names.txt  # path of dataset category names
    
    

    My environment:

    • 2080ti, 12G
    • CUDA 10.0
    • python 3.6

    Hoping for your reply! Thank you again!

    opened by zhixuanli 6
  • some question about test.py ?

    some question about test.py ?

    I cant' understand the mean about follow code:

        def scale_process(self, image, crop_h, crop_w, h, w, mean, std=None, stride_rate=2 / 3):
            ori_h, ori_w, _ = image.shape
            # 填充周边
            pad_h = max(crop_h - ori_h, 0)
            pad_w = max(crop_w - ori_w, 0)
            pad_h_half = int(pad_h / 2)
            pad_w_half = int(pad_w / 2)
            if pad_h > 0 or pad_w > 0:
                image = cv2.copyMakeBorder(image, pad_h_half, pad_h - pad_h_half, pad_w_half, pad_w - pad_w_half,
                                           cv2.BORDER_CONSTANT, value=mean)
            new_h, new_w, _ = image.shape
            # FAQ:
            stride_h = int(np.ceil(crop_h * stride_rate))
            stride_w = int(np.ceil(crop_w * stride_rate))
            grid_h = int(np.ceil(float(new_h - crop_h) / stride_h) + 1)
            grid_w = int(np.ceil(float(new_w - crop_w) / stride_w) + 1)
            prediction_crop = np.zeros((new_h, new_w, self.numclass), dtype=float)
            count_crop = np.zeros((new_h, new_w), float)
            for index_h in range(0, grid_h):
                for index_w in range(0, grid_w):
                    s_h = index_h * stride_h
                    e_h = min(s_h + crop_h, new_h)
                    s_h = e_h - crop_h
                    s_w = index_w * stride_w
                    e_w = min(s_w + crop_w, new_w)
                    s_w = e_w - crop_w
                    image_crop = image[s_h:e_h, s_w:e_w].copy()
                    count_crop[s_h:e_h, s_w:e_w] += 1
                    prediction_crop[s_h:e_h, s_w:e_w, :] += self.net_process(image_crop, mean, std)
            prediction_crop /= np.expand_dims(count_crop, 2)
            ..........
    

    i know that it need to process with the train height、width,But I dont't understand! Appreciate with any suggest!

    opened by HiIcy 5
  • PSANet is stuck in modeling

    PSANet is stuck in modeling

    I have tried to train PSPNet50 and PSANet50. PSPNet has been successfully trained, but PSANet is stuck in building up model. Has anyone encountered similar problem?

    opened by eugenelawrence 5
  • cuDNN error: CUDNN_STATUS_INTERNAL_ERROR

    cuDNN error: CUDNN_STATUS_INTERNAL_ERROR

    The GPU I used is RTX 8000 with 48G. However, I cannot run the it successfully and the error is "cuDNN error: CUDNN_STATUS_INTERNAL_ERROR". I notice that this appears because of the pspnet needs a more powerful GPU. I tried to decrease the batch size and resolution, and I find out that the occupation of GPU rise to a relative large valve and then decrease to about 11G. I speculate that the reason I fail to run the pspnet is the rapid rise of the occupation of GPU. The occupation is rather large (about 40G) even I set the batch size as 1. How can I address this?

    opened by qysun291 4
  • Pascal VOC 2012 - training time

    Pascal VOC 2012 - training time

    Hi,

    we are training Pascal VOC 2012 trainaug with PSPnet50. We have only 4 gpus, but the training time is 10x more, which is strange (we could even fit more into a batch).

    our setup:

    • 4 x P100 with 16GB
    • batch size:20
    • lr: 0.005

    Is DDP enabled by default? What else could cause the slowing down? Only having 2x less GPUs is not proportionate with the speed drop.

    @zhixuanli you got close with cityscapes in https://github.com/hszhao/semseg/issues/7#issuecomment-536251008 but still not the same. Did you only change the GPUs? Is that training time with distributed data parallel model?

    @hszhao

    opened by atiszabo 4
  • I want to train pspnet50,but not succeed.

    I want to train pspnet50,but not succeed.

    thx you code.when i input ‘sh tool/train.sh ade20k pspnet50’,i want to train pspnet50,but display the results of test .i don't know how change?Can you help me? /semseg/config/ade20k/ade20k_pspnet101.yaml DATA: data_root: /DATA/maran/anaconda3/Project/semseg/data/ADEChallengeData2016/images/data/ train_list: /DATA/maran/anaconda3/Project/semseg/data/ADEChallengeData2016/training.txt val_list: /DATA/maran/anaconda3/Project/semseg/data/ADEChallengeData2016/validation.txt classes: 150

    TRAIN: arch: psp layers: 50 sync_bn: True # adopt sync_bn or not train_h: 473 train_w: 473 scale_min: 0.5 # minimum random scale scale_max: 2.0 # maximum random scale rotate_min: -10 # minimum random rotate rotate_max: 10 # maximum random rotate zoom_factor: 8 # zoom factor for final prediction during training, be in [1, 2, 4, 8] ignore_label: 255 aux_weight: 0.4 train_gpu: [0, 1, 2, 3, 4, 5, 6, 7] workers: 16 # data loader workers batch_size: 16 # batch size for training batch_size_val: 8 # batch size for validation during training, memory and speed tradeoff base_lr: 0.01 epochs: 200 start_epoch: 101 power: 0.9 momentum: 0.9 weight_decay: 0.0001 manual_seed: print_freq: 10 save_freq: 1 save_path: exp/ade20k/pspnet50/model weight: # path to initial weight (default: none) resume: exp/ade20k/pspnet50/model/train_epoch_100.pth # path to latest checkpoint (default: none) evaluate: False # evaluate on validation set, extra gpu memory needed and small batch_size_val is recommend Distributed: dist_url: tcp://127.0.0.1:6789 dist_backend: 'nccl' multiprocessing_distributed: True world_size: 1 rank: 0 use_apex: True opt_level: 'O0' keep_batchnorm_fp32: loss_scale:

    TEST: test_list: /DATA/maran/anaconda3/Project/semseg/data/ADEChallengeData2016/validation.txt split: val # split in [train, val and test] base_size: 512 # based size for scaling test_h: 473 test_w: 473 scales: [1.0] # evaluation scales, ms as [0.5, 0.75, 1.0, 1.25, 1.5, 1.75] has_prediction: False # has prediction already or not index_start: 0 # evaluation start index in list index_step: 0 # evaluation step index in list, 0 means to end test_gpu: [0] model_path: exp/ade20k/pspnet50/model/train_epoch_100.pth # evaluation model path save_folder: exp/ade20k/pspnet50/result/epoch_100/val/ss # results save folder colors_path: dataset/ade20k/ade20k_colors.txt # path of dataset colors names_path: dataset/ade20k/ade20k_names.txt # path of dataset category names

    opened by E18301194 4
  • About the args.batch_size_val

    About the args.batch_size_val

    Hi, hs. In your code,

    if args.distributed: torch.cuda.set_device(gpu) args.batch_size = int(args.batch_size / ngpus_per_node) args.batch_size_val = int(args.batch_size_val / ngpus_per_node) args.workers = int(args.workers / ngpus_per_node)

    I think the default batch_size_val should be as the same as the ngpus_per_node, or get an error: ValueError: batch_size should be a positive integeral value, but got batch_size=0

    opened by sunpeng1996 3
  • cityscapes_colors.txt and cityscapes_names.txt missed

    cityscapes_colors.txt and cityscapes_names.txt missed

    Thank you for your codes. I did not find cityscapes_colors.txt and cityscapes_names.txt described in .yaml file in the google drive. What are their format?

    THX and have a nice day!

    opened by shanjiuvspikaqiu 2
  • Cannot handle cases with zero intersection

    Cannot handle cases with zero intersection

    https://github.com/hszhao/semseg/blob/4f274c3f276778228bc14a4565822d46359f0cc8/util/util.py#L63 This line of code works if there are non-zero instances of intersection between the output and target. There should be a check for this.

    opened by Abhimanyu8713 0
  • Opencv not being able to get images

    Opencv not being able to get images

    File "/content/gdrive/My Drive/Project/semseg/util/dataset.py", line 64, in getitem image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) # convert cv2 read image from BGR order to RGB order cv2.error: OpenCV(4.5.4-dev) /tmp/pip-req-build-v2fnlv3a/opencv/modules/imgproc/src/color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'

    aparently the code can't open the ADE dataset, i've placed on ade20k_pspnet50.yaml data_root the path to ADE Dataset, inside the folder with the following items "ADE (containing training models and validation), index_ade20k.mat, index_ade20k.pkl, objects.txt" what could I be doing wrong?

    opened by Henrique-Liesenfeld-Krever 1
  • About the model structure

    About the model structure

    Dr. Zhao, in your PSA paper, the model adopts ResNet-FCN-backbone. But I find no code about confusion about feature maps of different scales. Is my understanding right? Thank you very much.

    opened by L0-zhang 0
  • How to crop images into the individual segments

    How to crop images into the individual segments

    I am using test.py and it perfectly renders this color coded image. After playing with the code I couldn't figure out how to output the individual segments as separate images. Any advice would be appreciated

    opened by stevenohohohoh 0
Owner
Hengshuang Zhao
Hengshuang Zhao
Learning Pixel-level Semantic Affinity with Image-level Supervision for Weakly Supervised Semantic Segmentation, CVPR 2018

Learning Pixel-level Semantic Affinity with Image-level Supervision This code is deprecated. Please see https://github.com/jiwoon-ahn/irn instead. Int

Jiwoon Ahn 337 Dec 15, 2022
Segmentation in Style: Unsupervised Semantic Image Segmentation with Stylegan and CLIP

Segmentation in Style: Unsupervised Semantic Image Segmentation with Stylegan and CLIP Abstract: We introduce a method that allows to automatically se

Daniil Pakhomov 134 Dec 19, 2022
Mae segmentation - Reproduction of semantic segmentation using masked autoencoder (mae)

ADE20k Semantic segmentation with MAE Getting started Install the mmsegmentation

null 97 Dec 17, 2022
PyTorch for Semantic Segmentation

PyTorch for Semantic Segmentation This repository contains some models for semantic segmentation and the pipeline of training and testing models, impl

Zijun Deng 1.7k Jan 6, 2023
A semantic segmentation toolbox based on PyTorch

Introduction vedaseg is an open source semantic segmentation toolbox based on PyTorch. Features Modular Design We decompose the semantic segmentation

null 407 Dec 15, 2022
HyperSeg: Patch-wise Hypernetwork for Real-time Semantic Segmentation Official PyTorch Implementation

: We present a novel, real-time, semantic segmentation network in which the encoder both encodes and generates the parameters (weights) of the decoder. Furthermore, to allow maximal adaptivity, the weights at each decoder block vary spatially. For this purpose, we design a new type of hypernetwork, composed of a nested U-Net for drawing higher level context features

Yuval Nirkin 182 Dec 14, 2022
PyTorch implementation of: Michieli U. and Zanuttigh P., "Continual Semantic Segmentation via Repulsion-Attraction of Sparse and Disentangled Latent Representations", CVPR 2021.

Continual Semantic Segmentation via Repulsion-Attraction of Sparse and Disentangled Latent Representations This is the official PyTorch implementation

Multimedia Technology and Telecommunication Lab 42 Nov 9, 2022
Official PyTorch implementation of Segmenter: Transformer for Semantic Segmentation

Segmenter: Transformer for Semantic Segmentation Segmenter: Transformer for Semantic Segmentation by Robin Strudel*, Ricardo Garcia*, Ivan Laptev and

null 594 Jan 6, 2023
PyTorch implementation of ShapeConv: Shape-aware Convolutional Layer for RGB-D Indoor Semantic Segmentation.

Shape-aware Convolutional Layer (ShapeConv) PyTorch implementation of ShapeConv: Shape-aware Convolutional Layer for RGB-D Indoor Semantic Segmentatio

Hanchao Leng 82 Dec 29, 2022
Pytorch implementation for Semantic Segmentation/Scene Parsing on MIT ADE20K dataset

Semantic Segmentation on MIT ADE20K dataset in PyTorch This is a PyTorch implementation of semantic segmentation models on MIT ADE20K scene parsing da

MIT CSAIL Computer Vision 4.5k Jan 8, 2023
Pytorch Implementation for NeurIPS (oral) paper: Pixel Level Cycle Association: A New Perspective for Domain Adaptive Semantic Segmentation

Pixel-Level Cycle Association This is the Pytorch implementation of our NeurIPS 2020 Oral paper Pixel-Level Cycle Association: A New Perspective for D

null 87 Oct 19, 2022
An official implementation of "Exploiting a Joint Embedding Space for Generalized Zero-Shot Semantic Segmentation" (ICCV 2021) in PyTorch.

Exploiting a Joint Embedding Space for Generalized Zero-Shot Semantic Segmentation This is an official implementation of the paper "Exploiting a Joint

CV Lab @ Yonsei University 35 Oct 26, 2022
Semantic Segmentation with Pytorch-Lightning

This is a simple demo for performing semantic segmentation on the Kitti dataset using Pytorch-Lightning and optimizing the neural network by monitoring and comparing runs with Weights & Biases.

Boris Dayma 58 Nov 18, 2022
The PyTorch implementation of DiscoBox: Weakly Supervised Instance Segmentation and Semantic Correspondence from Box Supervision.

DiscoBox: Weakly Supervised Instance Segmentation and Semantic Correspondence from Box Supervision The PyTorch implementation of DiscoBox: Weakly Supe

Shiyi Lan 1 Oct 23, 2021
Pytorch implementation for Semantic Segmentation/Scene Parsing on MIT ADE20K dataset

Semantic Segmentation on MIT ADE20K dataset in PyTorch This is a PyTorch implementation of semantic segmentation models on MIT ADE20K scene parsing da

MIT CSAIL Computer Vision 4.5k Jan 8, 2023
PyTorch implementation of Memory-based semantic segmentation for off-road unstructured natural environments.

MemSeg: Memory-based semantic segmentation for off-road unstructured natural environments Introduction This repository is a PyTorch implementation of

null 11 Nov 28, 2022
A simple pytorch pipeline for semantic segmentation.

SegmentationPipeline -- Pytorch A simple pytorch pipeline for semantic segmentation. Requirements : torch>=1.9.0 tqdm albumentations>=1.0.3 opencv-pyt

petite7 4 Feb 22, 2022
Semantic Segmentation in Pytorch

PyTorch Semantic Segmentation Introduction This repository is a PyTorch implementation for semantic segmentation / scene parsing. The code is easy to

Hengshuang Zhao 1.2k Jan 1, 2023