PyTorch for Semantic Segmentation

Overview

PyTorch for Semantic Segmentation

This repository contains some models for semantic segmentation and the pipeline of training and testing models, implemented in PyTorch

Models

  1. Vanilla FCN: FCN32, FCN16, FCN8, in the versions of VGG, ResNet and DenseNet respectively (Fully convolutional networks for semantic segmentation)
  2. U-Net (U-net: Convolutional networks for biomedical image segmentation)
  3. SegNet (Segnet: A deep convolutional encoder-decoder architecture for image segmentation)
  4. PSPNet (Pyramid scene parsing network)
  5. GCN (Large Kernel Matters)
  6. DUC, HDC (understanding convolution for semantic segmentation)

Requirement

  1. PyTorch 0.2.0
  2. TensorBoard for PyTorch. Here to install
  3. Some other libraries (find what you miss when running the code :-P)

Preparation

  1. Go to models directory and set the path of pretrained models in config.py
  2. Go to datasets directory and do following the README

TODO

  1. DeepLab v3
  2. RefineNet
  3. More dataset (e.g. ADE)
Comments
  • A Simple Question About FCN

    A Simple Question About FCN

    Thanks for your code, a small question,In file fcn8s.py upscore_pool4 = self.upscore_pool4(score_pool4[:, :, 5: (5 + upscore2.size()[2]), 5: (5 + upscore2.size()[3])] + upscore2) upscore8 = self.upscore8(score_pool3[:, :, 9: (9 + upscore_pool4.size()[2]), 9: (9 + upscore_pool4.size()[3])] + upscore_pool4) how can we know the number 5,9 , i can't find it in the FCN paper ,i am new to the image segmentation

    opened by lxtGH 5
  • About the performance

    About the performance

    Hi @ZijunDeng , thanks for sharing. Elegant code. I have a question about the performance on VOC or cityscape of the models, such as pspnet, gcn, etc. I find your data augmentation is simple and different from that proposed in the corresponding paper. And I think it has a big impact on the segmentation result. So, how about the mean IOU of your implementations?

    opened by speedinghzl 3
  • unexpected key

    unexpected key "module.enc1.0.weight" in state_dict'

    Hi there, I'm aware that you are updating your repo :) but I tried to use your repo as an initial point for my own implementation! I just trained a segNet model and tried to use the learned model to predict on a query image, but I came across the following error: KeyError: 'unexpected key "module.enc1.0.weight" in state_dict'

    Do you know what causes this error?

    opened by saeedizadi 3
  • ResNetDUC model can not converge in the dataset CamVid?

    ResNetDUC model can not converge in the dataset CamVid?

    image

    First thanks for your implementing for ResNetDUC, I try to train on the dataset CamVid, but it is trained slow and seem not converge. What should I do to get a better model?

    opened by guanfuchen 2
  • TypeError: 'torch.FloatTensor' object does not support indexing

    TypeError: 'torch.FloatTensor' object does not support indexing

    When I train the FCN8S model it shows error at the end of epoch 1 [epoch 1], [iter 8440 / 8498], [train loss 545605.78962] [epoch 1], [iter 8460 / 8498], [train loss 545628.17753] [epoch 1], [iter 8480 / 8498], [train loss 545635.63007] Traceback (most recent call last): File "train.py", line 214, in main(args) File "train.py", line 98, in main val_loss = validate(val_loader, net, criterion, optimizer, epoch, train_args, restore_transform, visualize) File "train.py", line 190, in validate writer.add_image(snapshot_name, val_visual) File "/home/lxt/anaconda3/lib/python3.6/site-packages/tensorboard/writer.py", line 221, in add_image self.file_writer.add_summary(image(tag, img_tensor)) File "/home/lxt/anaconda3/lib/python3.6/site-packages/tensorboard/summary.py", line 174, in image tensor = np.ndarray(tensor, dtype=np.float32) TypeError: 'torch.FloatTensor' object does not support indexing

    opened by lxtGH 2
  • Loading from a pretrained PSPNet model

    Loading from a pretrained PSPNet model

    This may not be relevant and I'm new to pytorch but I'm interested to load just the pyramid pooling module features from the weights provided in numpy format here. How can it be possible? Thanks

    opened by iliadsouti 2
  • Error  while train

    Error while train

    error happened while training, hope you can help me Traceback (most recent call last): File "train/cityscapes-psp_net/train2.py", line 252, in main() File "train/cityscapes-psp_net/train2.py", line 110, in main train(train_loader, net, criterion, optimizer, curr_epoch, args, val_loader, restore_transform, visualize) File "train/cityscapes-psp_net/train2.py", line 159, in train validate(val_loader, net, criterion, optimizer, curr_epoch, train_args, restore, visualize) File "train/cityscapes-psp_net/train2.py", line 182, in validate outputs,aa = net(inputs) File "/usr/local/lib/python2.7/dist-packages/torch/nn/modules/module.py", line 224, in call result = self.forward(*input, **kwargs) File "/home/htjiang/Desktop/pytorch-semantic-segmentation/models/psp_net.py", line 79, in forward x = self.final(x) File "/usr/local/lib/python2.7/dist-packages/torch/nn/modules/module.py", line 224, in call result = self.forward(*input, **kwargs) File "/usr/local/lib/python2.7/dist-packages/torch/nn/modules/container.py", line 67, in forward input = module(input) File "/usr/local/lib/python2.7/dist-packages/torch/nn/modules/module.py", line 224, in call result = self.forward(*input, **kwargs) File "/usr/local/lib/python2.7/dist-packages/torch/nn/modules/conv.py", line 254, in forward self.padding, self.dilation, self.groups) File "/usr/local/lib/python2.7/dist-packages/torch/nn/functional.py", line 52, in conv2d return f(input, weight, bias) RuntimeError: CUDNN_STATUS_INTERNAL_ERROR

    opened by jhtao1860 2
  • upsample_bilinear and conv_transposed2d

    upsample_bilinear and conv_transposed2d

    Hi, Zijun

    Thanks for your code. I notice you use upsample_bilinear instead of conv_transposed2d to interpolate in FCN implementation. What is your consideration?

    Thanks,

    opened by donproc 2
  • Adjustments for Python 3

    Adjustments for Python 3

    Thank you very much for providing your implementation. I recently used your FCN but needed to make adjustments to make it work on my environment (miniconda, python 3). I share those adjustments in case someone finds them useful.

    opened by adynathos 1
  • Error while eval_cityscapes

    Error while eval_cityscapes

    I change some code in eval_cs to fit CityScapes,the error happened as following

    File "eval/eval_cs.py", line 58, in main() File "eval/eval_cs.py", line 42, in main for vi, data in enumerate(test_loader): File "/usr/local/lib/python2.7/dist-packages/torch/utils/data/dataloader.py", line 201, in next return self._process_next_batch(batch) File "/usr/local/lib/python2.7/dist-packages/torch/utils/data/dataloader.py", line 221, in _process_next_batch raise batch.exc_type(batch.exc_msg) TypeError: Traceback (most recent call last): File "/usr/local/lib/python2.7/dist-packages/torch/utils/data/dataloader.py", line 40, in _worker_loop samples = collate_fn([dataset[i] for i in batch_indices]) File "/usr/local/lib/python2.7/dist-packages/torch/utils/data/dataloader.py", line 109, in default_collate return [default_collate(samples) for samples in transposed] File "/usr/local/lib/python2.7/dist-packages/torch/utils/data/dataloader.py", line 112, in default_collate .format(type(batch[0])))) TypeError: batch must contain tensors, numbers, dicts or lists; found <class 'PIL.Image.Image'>

    opened by jhtao1860 1
  • Downloaded Dataset PASCAL VOC 2012 missing folders

    Downloaded Dataset PASCAL VOC 2012 missing folders

    After downloading PASCAL VOC 2012 from http://host.robots.ox.ac.uk/pascal/VOC/voc2012/VOCdevkit_18-May-2011.tar and unzipping there is no folder/path like VOCdefkit/VOC2012/ImageSets/Segmentation to put the file seg11valid.txt into.

    opened by dan1elR 0
  • Segnet unsampling way

    Segnet unsampling way

    Hello, author!About the SEGNET's upper sampling method has a little confusion, why use the transposition convolution, which does not record the index of the pooling? Hope receive your reply!

    opened by Tensor-king 0
  • Segnet unsampling way

    Segnet unsampling way

    Hello, author!About the SEGNET's upper sampling method has a little confusion, why use the transposition convolution, which does not record the index of the pooling? Hope receive your reply!

    opened by Tensor-king 0
  • tensorboard

    tensorboard

    hello author,

    i installed tensorboardX, but your code imports summary writer from tensorboard, gives error. how can i solve this.

    if i use from tensorboard import SummaryWriter ImportError: cannot import name SummaryWriter

    if i use, from tensorboardX import SummaryWriter

    Traceback (most recent call last): File "/home/rahul/rahul/pytorch-semantic-segmentation-master/train/voc-fcn/train.py", line 7, in from tensorboardX import SummaryWriter File "/home/rahul/anaconda3/envs/semseg/lib/python2.7/site-packages/tensorboardX/init.py", line 5, in from .torchvis import TorchVis File "/home/rahul/anaconda3/envs/semseg/lib/python2.7/site-packages/tensorboardX/torchvis.py", line 11, in from .writer import SummaryWriter File "/home/rahul/anaconda3/envs/semseg/lib/python2.7/site-packages/tensorboardX/writer.py", line 223 logdir: Optional[str] = None, ^ SyntaxError: invalid syntax

    opened by soans1994 0
  • Can't pickle local object 'main.<locals>.<lambda>'

    Can't pickle local object 'main..'

    When I try to run the train.py, it reports an error like this:

    • Can't pickle local object 'main..'

    is there anyone know why? And how can I reslove it?

    opened by Relu-cloud 2
  • cuDNN error: CUDNN_STATUS_NOT_INITIALIZED

    cuDNN error: CUDNN_STATUS_NOT_INITIALIZED

    I training FCN32 with the my onw datatset. However, i realized that the loss is empty and lead to the error above. The detailed error: C:/cb/pytorch_1000000000000/work/aten/src/THCUNN/SpatialClassNLLCriterion.cu:106: block: [3,0,0], thread: [293,0,0] Assertion t >= 0 && t < n_classes failed. C:/cb/pytorch_1000000000000/work/aten/src/THCUNN/SpatialClassNLLCriterion.cu:106: block: [3,0,0], thread: [294,0,0] Assertion t >= 0 && t < n_classes failed. C:/cb/pytorch_1000000000000/work/aten/src/THCUNN/SpatialClassNLLCriterion.cu:106: block: [3,0,0], thread: [32,0,0] Assertion t >= 0 && t < n_classes failed. C:/cb/pytorch_1000000000000/work/aten/src/THCUNN/SpatialClassNLLCriterion.cu:106: block: [3,0,0], thread: [33,0,0] Assertion t >= 0 && t < n_classes failed. C:/cb/pytorch_1000000000000/work/aten/src/THCUNN/SpatialClassNLLCriterion.cu:106: block: [3,0,0], thread: [34,0,0] Assertion t >= 0 && t < n_classes failed. C:/cb/pytorch_1000000000000/work/aten/src/THCUNN/SpatialClassNLLCriterion.cu:106: block: [3,0,0], thread: [35,0,0] Assertion t >= 0 && t < n_classes failed. C:/cb/pytorch_1000000000000/work/aten/src/THCUNN/SpatialClassNLLCriterion.cu:106: block: [3,0,0], thread: [514,0,0] Assertion t >= 0 && t < n_classes failed. C:/cb/pytorch_1000000000000/work/aten/src/THCUNN/SpatialClassNLLCriterion.cu:106: block: [3,0,0], thread: [515,0,0] Assertion t >= 0 && t < n_classes failed. C:/cb/pytorch_1000000000000/work/aten/src/THCUNN/SpatialClassNLLCriterion.cu:106: block: [3,0,0], thread: [516,0,0] Assertion t >= 0 && t < n_classes failed. C:/cb/pytorch_1000000000000/work/aten/src/THCUNN/SpatialClassNLLCriterion.cu:106: block: [3,0,0], thread: [517,0,0] Assertion t >= 0 && t < n_classes failed. C:/cb/pytorch_1000000000000/work/aten/src/THCUNN/SpatialClassNLLCriterion.cu:106: block: [3,0,0], thread: [518,0,0] Assertion t >= 0 && t < n_classes failed. C:/cb/pytorch_1000000000000/work/aten/src/THCUNN/SpatialClassNLLCriterion.cu:106: block: [3,0,0], thread: [160,0,0] Assertion t >= 0 && t < n_classes failed. C:/cb/pytorch_1000000000000/work/aten/src/THCUNN/SpatialClassNLLCriterion.cu:106: block: [3,0,0], thread: [161,0,0] Assertion t >= 0 && t < n_classes failed. C:/cb/pytorch_1000000000000/work/aten/src/THCUNN/SpatialClassNLLCriterion.cu:106: block: [3,0,0], thread: [162,0,0] Assertion t >= 0 && t < n_classes failed. C:/cb/pytorch_1000000000000/work/aten/src/THCUNN/SpatialClassNLLCriterion.cu:106: block: [3,0,0], thread: [163,0,0] Assertion t >= 0 && t < n_classes failed. C:/cb/pytorch_1000000000000/work/aten/src/THCUNN/SpatialClassNLLCriterion.cu:106: block: [3,0,0], thread: [164,0,0] Assertion t >= 0 && t < n_classes failed. C:/cb/pytorch_1000000000000/work/aten/src/THCUNN/SpatialClassNLLCriterion.cu:106: block: [3,0,0], thread: [165,0,0] Assertion t >= 0 && t < n_classes failed. C:/cb/pytorch_1000000000000/work/aten/src/THCUNN/SpatialClassNLLCriterion.cu:106: block: [3,0,0], thread: [166,0,0] Assertion t >= 0 && t < n_classes failed. C:/cb/pytorch_1000000000000/work/aten/src/THCUNN/SpatialClassNLLCriterion.cu:106: block: [3,0,0], thread: [167,0,0] Assertion t >= 0 && t < n_classes failed. C:/cb/pytorch_1000000000000/work/aten/src/THCUNN/SpatialClassNLLCriterion.cu:106: block: [3,0,0], thread: [168,0,0] Assertion t >= 0 && t < n_classes failed. C:/cb/pytorch_1000000000000/work/aten/src/THCUNN/SpatialClassNLLCriterion.cu:106: block: [3,0,0], thread: [256,0,0] Assertion t >= 0 && t < n_classes failed. C:/cb/pytorch_1000000000000/work/aten/src/THCUNN/SpatialClassNLLCriterion.cu:106: block: [3,0,0], thread: [257,0,0] Assertion t >= 0 && t < n_classes failed. C:/cb/pytorch_1000000000000/work/aten/src/THCUNN/SpatialClassNLLCriterion.cu:106: block: [3,0,0], thread: [258,0,0] Assertion t >= 0 && t < n_classes failed. C:/cb/pytorch_1000000000000/work/aten/src/THCUNN/SpatialClassNLLCriterion.cu:106: block: [3,0,0], thread: [259,0,0] Assertion t >= 0 && t < n_classes failed. C:/cb/pytorch_1000000000000/work/aten/src/THCUNN/SpatialClassNLLCriterion.cu:106: block: [3,0,0], thread: [260,0,0] Assertion t >= 0 && t < n_classes failed. C:/cb/pytorch_1000000000000/work/aten/src/THCUNN/SpatialClassNLLCriterion.cu:106: block: [3,0,0], thread: [261,0,0] Assertion t >= 0 && t < n_classes failed. C:/cb/pytorch_1000000000000/work/aten/src/THCUNN/SpatialClassNLLCriterion.cu:106: block: [3,0,0], thread: [262,0,0] Assertion t >= 0 && t < n_classes failed. C:/cb/pytorch_1000000000000/work/aten/src/THCUNN/SpatialClassNLLCriterion.cu:106: block: [3,0,0], thread: [384,0,0] Assertion t >= 0 && t < n_classes failed. C:/cb/pytorch_1000000000000/work/aten/src/THCUNN/SpatialClassNLLCriterion.cu:106: block: [3,0,0], thread: [385,0,0] Assertion t >= 0 && t < n_classes failed. C:/cb/pytorch_1000000000000/work/aten/src/THCUNN/SpatialClassNLLCriterion.cu:106: block: [3,0,0], thread: [386,0,0] Assertion t >= 0 && t < n_classes failed. C:/cb/pytorch_1000000000000/work/aten/src/THCUNN/SpatialClassNLLCriterion.cu:106: block: [3,0,0], thread: [387,0,0] Assertion t >= 0 && t < n_classes failed. C:/cb/pytorch_1000000000000/work/aten/src/THCUNN/SpatialClassNLLCriterion.cu:106: block: [3,0,0], thread: [388,0,0] Assertion t >= 0 && t < n_classes failed. C:/cb/pytorch_1000000000000/work/aten/src/THCUNN/SpatialClassNLLCriterion.cu:106: block: [3,0,0], thread: [389,0,0] Assertion t >= 0 && t < n_classes failed. C:/cb/pytorch_1000000000000/work/aten/src/THCUNN/SpatialClassNLLCriterion.cu:106: block: [3,0,0], thread: [390,0,0] Assertion t >= 0 && t < n_classes failed. C:/cb/pytorch_1000000000000/work/aten/src/THCUNN/SpatialClassNLLCriterion.cu:106: block: [3,0,0], thread: [391,0,0] Assertion t >= 0 && t < n_classes failed. C:/cb/pytorch_1000000000000/work/aten/src/THCUNN/SpatialClassNLLCriterion.cu:106: block: [3,0,0], thread: [392,0,0] Assertion t >= 0 && t < n_classes failed. C:/cb/pytorch_1000000000000/work/aten/src/THCUNN/SpatialClassNLLCriterion.cu:106: block: [3,0,0], thread: [393,0,0] Assertion t >= 0 && t < n_classes failed. Traceback (most recent call last): File "train.py", line 245, in main(args) File "train.py", line 126, in main train(train_loader, net, criterion, optimizer, epoch, train_args) File "train.py", line 149, in train loss.backward() File "C:\Users\ADMIN\anaconda3\envs\Pytorch\lib\site-packages\torch\tensor.py", line 198, in backward torch.autograd.backward(self, gradient, retain_graph, create_graph) File "C:\Users\ADMIN\anaconda3\envs\Pytorch\lib\site-packages\torch\autograd_init_.py", line 100, in backward allow_unreachable=True) # allow_unreachable flag RuntimeError: cuDNN error: CUDNN_STATUS_NOT_INITIALIZED (createCuDNNHandle at ..\aten\src\ATen\cudnn\Handle.cpp:9) (no backtrace available).

    opened by AnhNguyenUK 0
Owner
Zijun Deng
Interested in deep learning.
Zijun Deng
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