GithubHelp home page GithubHelp logo

deeachain / segmentation-pytorch Goto Github PK

View Code? Open in Web Editor NEW
457.0 6.0 69.0 10.94 MB

Semantic Segmentation in Pytorch. Network include: FCN、FCN_ResNet、SegNet、UNet、BiSeNet、BiSeNetV2、PSPNet、DeepLabv3_plus、 HRNet、DDRNet

Python 99.38% Shell 0.62%

segmentation-pytorch's Introduction

🚀 If it helps you, click a star! ⭐

Update log

  • 2020.12.10 Project structure adjustment, the previous code has been deleted, the adjustment will be re-uploaded code
  • 2021.04.09 Re-upload the code, "V1 Commit"
  • 2021.04.22 update torch distributed training
  • Ongoing update .....

1. Display (Cityscapes)

  • Using model DDRNet 1525 test sets, official MIOU =78.4069%
Average results
Class results1
Class results2
Class results3
  • Comparison of the original and predicted images
origin
label
predict

2. Install

pip install -r requirements.txt
Experimental environment:

  • Ubuntu 16.04 Nvidia-Cards >= 1
  • python==3.6.5
  • See Dependency Installation Package for details in requirement.txt

3. Model

All the modeling is done in builders/model_builder.py

  • FCN
  • FCN_ResNet
  • SegNet
  • UNet
  • BiSeNet
  • BiSeNetV2
  • PSPNet
  • DeepLabv3_plus
  • HRNet
  • DDRNet
Model Backbone Val mIoU Test mIoU Imagenet Pretrain Pretrained Model
PSPNet ResNet 50 76.54% - PSPNet
DeeplabV3+ ResNet 50 77.78% - DeeplabV3+
DDRNet23_slim - DDRNet23_slim_imagenet
DDRNet23 - DDRNet23_imagenet
DDRNet39 - 79.63% - DDRNet39_imagenet DDRNet39
Updating more model.......

4. Data preprocessing

This project enables you to expose data sets: CityscapesISPRS
The data set is uploaded later .....
Cityscapes data set preparation is shown here:

4.1 Download the dataset

Download the dataset from the link on the website, You can get *leftImg8bit.png suffix of original image under folder leftImg8bit, a) *color.pngb) *labelIds.pngc) *instanceIds.png suffix of fine labeled image under folder gtFine.

*leftImg8bit.png          : the origin picture
a) *color.png             : the class is encoded by its color
b) *labelIds.png          : the class is encoded by its ID
c) *instanceIds.png       : the class and the instance are encoded by an instance ID

4.2 Onehot encoding of label image

The real label gray scale image Onehot encoding used by the semantic segmentation task is 0-18, so the label needs to be encoded. Using scripts dataset/cityscapes/cityscapes_scripts/process_cityscapes.py to process the image and get the result *labelTrainIds.png. process_cityscapes.py usage: Modify 486 lines `Cityscapes_path'is the path to store your own data.

  • Comparison of original image, color label image and gray label image (0-18)
***_leftImg8bit
***_gtFine_color
***_gtFine_labelTrainIds
  • Local storage path display /data/open_data/cityscapes/:
data
  |--open_data
        |--cityscapes
               |--leftImg8bit
                    |--train
                        |--cologne
                        |--*******
                    |--val
                        |--*******
                    |--test
                        |--*******
               |--gtFine
                    |--train
                        |--cologne
                        |--*******
                    |--val
                        |--*******
                    |--test
                        |--*******

4.3 Generate image path

  • Generate a txt containing the image path
    Use script dataset/generate_txt.py to generate the path txt file containing the original image and labels. A total of 3 txt files will be generated: cityscapes_train_list.txtcityscapes_val_list.txtcityscapes_test_list.txt, and copy the three files to the dataset root directory.
data
  |--open_data
        |--cityscapes
               |--cityscapes_train_list.txt
               |--cityscapes_val_list.txt
               |--cityscapes_test_list.txt
               |--leftImg8bit
                    |--train
                        |--cologne
                        |--*******
                    |--val
                        |--*******
                    |--test
                        |--*******
               |--gtFine
                    |--train
                        |--cologne
                        |--*******
                    |--val
                        |--*******
                    |--test
                        |--*******
  • The contents of the txt are shown as follows:
leftImg8bit/train/cologne/cologne_000000_000019_leftImg8bit.png gtFine/train/cologne/cologne_000000_000019_gtFine_labelTrainIds.png
leftImg8bit/train/cologne/cologne_000001_000019_leftImg8bit.png gtFine/train/cologne/cologne_000001_000019_gtFine_labelTrainIds.png
..............
  • The format of the txt are shown as follows:
origin image path + the separator '\t' + label path +  the separator '\n'

TODO.....

5. How to train

sh train.sh

5.1 Parameters

python -m torch.distributed.launch --nproc_per_node=2 \
                train.py --model PSPNet_res50 --out_stride 8 \
                --max_epochs 200 --val_epochs 20 --batch_size 4 --lr 0.01 --optim sgd --loss ProbOhemCrossEntropy2d \
                --base_size 768 --crop_size 768  --tile_hw_size 768,768 \
                --root '/data/open_data' --dataset cityscapes --gpus_id 1,2

6. How to validate

sh predict.sh

segmentation-pytorch's People

Contributors

deeachain avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

segmentation-pytorch's Issues

AttributeError in HRNet

When I run ./model/HRNet.py on Ubuntu 18.04, torch 1.8.0+cu111, the error raise as follows,

/home/vgc/users/lwz/code/rice_seg/template/Segmentation-Pytorch/model/HRNet.py:329: DeprecationWarning: np.int is a deprecated alias for the builtin int. To silence this warning, use int by itself. Doing this will not modify any behavior and is safe. When replacing np.int, you may wish to use e.g. np.int64 or np.int32 to specify the precision. If you wish to review your current use, check the release note link for additional information.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
last_inp_channels = np.int(np.sum(pre_stage_channels))
Traceback (most recent call last):
File "/home/vgc/users/lwz/code/rice_seg/template/Segmentation-Pytorch/model/HRNet.py", line 520, in
summary(model, (3, 512, 512), device="cpu")
File "/home/vgc/anaconda3/envs/lwz37/lib/python3.7/site-packages/torchsummary/torchsummary.py", line 72, in summary
model(*x)
File "/home/vgc/anaconda3/envs/lwz37/lib/python3.7/site-packages/torch/nn/modules/module.py", line 889, in _call_impl
result = self.forward(*input, **kwargs)
File "/home/vgc/users/lwz/code/rice_seg/template/Segmentation-Pytorch/model/HRNet.py", line 447, in forward
y_list = self.stage2(x_list)
File "/home/vgc/anaconda3/envs/lwz37/lib/python3.7/site-packages/torch/nn/modules/module.py", line 889, in _call_impl
result = self.forward(*input, **kwargs)
File "/home/vgc/anaconda3/envs/lwz37/lib/python3.7/site-packages/torch/nn/modules/container.py", line 119, in forward
input = module(input)
File "/home/vgc/anaconda3/envs/lwz37/lib/python3.7/site-packages/torch/nn/modules/module.py", line 893, in _call_impl
hook_result = hook(self, input, result)
File "/home/vgc/anaconda3/envs/lwz37/lib/python3.7/site-packages/torchsummary/torchsummary.py", line 19, in hook
summary[m_key]["input_shape"] = list(input[0].size())
AttributeError: 'list' object has no attribute 'size'

模型

请问训练的权重文件提供吗

DDRNet相关问题

你好,你这代码写的很好鲁棒性很强!但是我在本地单卡3060训练DDRNet23_slim,训练参数如下的情况下,跑出来结果只有70%

python -m torch.distributed.launch --nproc_per_node=1 \
                train.py --model DDRNet --out_stride 8 \
                --max_epochs 200 --val_epochs 20 --batch_size 6 --lr 0.01 --optim sgd --loss ProbOhemCrossEntropy2d \
                --base_size 768 --crop_size 768  --tile_hw_size 768,768 \
                --root 'data' --dataset cityscapes --gpus_id 0

这是什么原因呢,可以分享下复现DDRNet的参数吗,或者帮忙分析下是啥原因呀,感谢!

路徑問題

我依照你的數據階層放我cityscapes,還是出現Screenshot from 2023-11-27 22-20-30,能幫我看下哪裡有問題嗎?謝謝+
Traceback (most recent call last):
File "/datashare3/charis/code/recaps/segNet/Segmentation-Pytorch-master/train.py", line 367, in
main(args)
File "/datashare3/charis/code/recaps/segNet/Segmentation-Pytorch-master/train.py", line 117, in main
datas, traindataset = build_dataset_train(args.root, args.dataset, args.base_size, args.crop_size)
File "/datashare3/charis/code/recaps/segNet/Segmentation-Pytorch-master/builders/dataset_builder.py", line 39, in build_dataset_train
mean=datas['mean'], std=datas['std'], ignore_label=255)
File "/datashare3/charis/code/recaps/segNet/Segmentation-Pytorch-master/dataset/cityscapes/cityscapes.py", line 40, in init
self.img_ids = [i_id.strip() for i_id in open(list_path)]
FileNotFoundError: [Errno 2] No such file or directory: "'/datashare3/charis/code/recaps/segNet/Segmentation-Pytorch-master/data/open_data/cityscapes'/cityscapes/cityscapes_train_list.txt"

bug about generate_txt.py

in line 26
filename_gt = filename.replace('leftImg8bit', 'gtFine')
should change to
filename_gt = filename.replace('leftImg8bit', 'gtFine').replace('.png','_labelTrainIds.png')
to produce the format of
leftImg8bit/train/cologne/cologne_000001_000019_leftImg8bit.png gtFine/train/cologne/cologne_000001_000019_gtFine_labelTrainIds.png

the result will be
leftImg8bit/train/cologne/cologne_000001_000019_leftImg8bit.png gtFine/train/cologne/cologne_000001_000019_gtFine.png
before. And the program wont find the file.

if I am wrong, plz tell me. Best wishes.

DDRNet在预测推理的时候遇到了维度不匹配的问题

在用DDRNet训练自己的数据后(两类,背景和前景),对图片进行预测时,偶尔会出现
File "/0work/LMK/Segment_task/Segmentation-Pytorch/model/DDRNet.py", line 330, in forward
x_ = x_ + F.interpolate(
RuntimeError: The size of tensor a (63) must match the size of tensor b (62) at non-singleton dimension 3
这个维度的bug。
请问该如何解决?

使用ENet模型,在train时正常,在pridict时会出现超出内存。

在train时正常,在pridict时会出现:
RuntimeError.CUDA out of memory. Tried to allocate 188.00 MiB (GPU 0; 6.00 GiB total capacity; 4.21 GiB already allocated; 63.85 MiB free; 81.86 MiB cached)
使用predict_sliding时会出现:
发生异常: TypeError
init() got an unexpected keyword argument 'std'
请问怎么解决?

Can you offer me the trainning log?

I am trying to reproduce the scores, could you offer the log if it`s possible. So that I can check if the program is running correctly. Thank you.

Unet pretrained

Hi, thank you so much for sharing. Do you have the unet pretrained on cityscapes? THanks

Making inference from a pretrained HRNet?

Great Work. I was wondering How can I make inference from a pretrained HRNet. Please do provide a pretrained HRNet model or provide the link as the dimensions are mismatching when i downloaded hrnet pretrained from HRNet official.
What parameters do you set for pretrained HRNet ? Waiting for a positive response.

size doesn't match error when run the train.py

sorry to disturb you, when i run train.py, it goes wrong, and i print the size of the two tensor, there are same, i can't find the resolution, how to solve it?
`******* Begining traing *******


Epoch 0/300: 0%| | 0/909 [00:00<?, ?it/s]/usr/local/anaconda3/lib/python3.6/site-packages/torch/nn/functional.py:1350: UserWarning: nn.functional.sigmoid is deprecated. Use torch.sigmoid instead.
warnings.warn("nn.functional.sigmoid is deprecated. Use torch.sigmoid instead.")
Traceback (most recent call last):
File "/home/yeluyue/dl/bottle_Segmentation/train.py", line 415, in
train_model(args)
File "/home/yeluyue/dl/bottle_Segmentation/train.py", line 293, in train_model
lossTr, lr = train(args, trainLoader, model, criteria, optimizer, epoch)
File "/home/yeluyue/dl/bottle_Segmentation/train.py", line 117, in train
loss = criterion(output, labels)
File "/usr/local/anaconda3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 547, in call
result = self.forward(*input, **kwargs)
File "/home/yeluyue/dl/bottle_Segmentation/tools/loss.py", line 27, in forward
return self.loss(outputs, targets)
File "/usr/local/anaconda3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 547, in call
result = self.forward(*input, **kwargs)
File "/usr/local/anaconda3/lib/python3.6/site-packages/torch/nn/modules/loss.py", line 498, in forward
return F.binary_cross_entropy(input, target, weight=self.weight, reduction=self.reduction)
File "/usr/local/anaconda3/lib/python3.6/site-packages/torch/nn/functional.py", line 2047, in binary_cross_entropy
new_size = _infer_size(target.size(), weight.size())
RuntimeError: The size of tensor a (512) must match the size of tensor b (2) at non-singleton dimension 2`

dataset

hello ,when will you update ISPRS Dataset,thank you

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.