Pytorch implementation of U-Net, R2U-Net, Attention U-Net, and Attention R2U-Net.

Overview

pytorch Implementation of U-Net, R2U-Net, Attention U-Net, Attention R2U-Net

U-Net: Convolutional Networks for Biomedical Image Segmentation

https://arxiv.org/abs/1505.04597

Recurrent Residual Convolutional Neural Network based on U-Net (R2U-Net) for Medical Image Segmentation

https://arxiv.org/abs/1802.06955

Attention U-Net: Learning Where to Look for the Pancreas

https://arxiv.org/abs/1804.03999

Attention R2U-Net : Just integration of two recent advanced works (R2U-Net + Attention U-Net)

U-Net

U-Net

R2U-Net

R2U-Net

Attention U-Net

AttU-Net

Attention R2U-Net

AttR2U-Net

Evaluation

we just test the models with ISIC 2018 dataset. The dataset was split into three subsets, training set, validation set, and test set, which the proportion is 70%, 10% and 20% of the whole dataset, respectively. The entire dataset contains 2594 images where 1815 images were used for training, 259 for validation and 520 for testing models.

evaluation

Comments
  • FileNotFoundError: [Errno 2] No such file or directory: '.

    FileNotFoundError: [Errno 2] No such file or directory: '.

    hello i have some problems about this code Traceback (most recent call last): File "/home/panpan/wenjian/pytorchImage_Segmentation-master/dataset.py", line 115, in main(config) File "/home/panpan/wenjian/pytorchImage_Segmentation-master/dataset.py", line 55, in main copyfile(src, dst) File "/home/panpan/anaconda3/lib/python3.6/shutil.py", line 120, in copyfile with open(src, 'rb') as fsrc: FileNotFoundError: [Errno 2] No such file or directory: '../ISIC/dataset/train_data/ISIC_33.png'

    i dont know how to deal with ,can you help me ?thanks a lot

    opened by YangBai1109 21
  • about the test

    about the test

    hello ,thank you very much for your contribution

    could you tell me how to test the code ,because

    Epoch [15/15], Loss: 11.5097, [Training] Acc: 0.9289, SE: 0.8480, SP: 0.9742, PC: 0.8885, F1: 0.8537, JS: 0.7518, DC: 0.8537 Decay learning rate to lr: 0.0. [Validation] Acc: 0.8809, SE: 0.9680, SP: 0.8651, PC: 0.6196, F1: 0.7209, JS: 0.5988, DC: 0.7209

    Process finished with exit code 0

    the test function ,doesn't work , and i only can see the test result

    opened by YangBai1109 9
  • Dataset training

    Dataset training

    Hello, @LeeJunHyun I followed your instruction by changing the path to my data in dataset.py L99,100 .. but after running main.py i got errors in L152(solver.py) about the unequal size of SR_Flat, GT_Flat !!

    ValueError: Target and input must have the same number of elements. target nelement (196608) != input nelement (65536)

    opened by loaysh2010 7
  • The result is not good in ISIC 2018

    The result is not good in ISIC 2018

    Jaccard and F1 only 0.5-0.7,are you sure? On the official competition website, the result common is 0.80+ in term of jaccard. In addition, the result of Unet in my experiment is 0.78+ in term of jaccard, Yes! ISIC 2018. 2594 images.I resize it to 256*192

    opened by FENGShuanglang 7
  • Attention-Unet : IndexError: tuple index out of range

    Attention-Unet : IndexError: tuple index out of range

    Hey Lee, So I am wanted to implement Attention Unet. But there is some issue coming up while using it. I am using my own dataset and also doing a lot of preprocessing with data. When I am using your model I get this error.

    error

    Any idea about it? Its for medical binary segmentation

    opened by bigmb 7
  • About the input file and the evaluation

    About the input file and the evaluation

    I have 2 questions. 1.What kind of images can I use? My input includes single channel '.png' images which should be segmented and '.png' GT images which is composed of 0 and 255. Can I use them directly, or what is your image format?

    1. What does it mean that SR = SR > treshhold in get_accuracy in evaluation? For example, my SR.max() is 8 , SR.min() is -10 for a instance. Are you supposed SR is ranged in (0:1)? Why did I get this wried results?

    Thank you so much

    opened by ghost 7
  • SE: 0.0000, SP: 0.0000, PC: 0.0000, F1: 0.0000, JS: 0.0000, DC: 0.0000

    SE: 0.0000, SP: 0.0000, PC: 0.0000, F1: 0.0000, JS: 0.0000, DC: 0.0000

    [Training] Acc: 0.6241, SE: 0.0000, SP: 0.0000, PC: 0.0000, F1: 0.0000, JS: 0.0000, DC: 0.0000 [Validation] Acc: 0.7816, SE: 0.0000, SP: 0.0000, PC: 0.0000, F1: 0.0000, JS: 0.0000, DC: 0.0000 Epoch [42/250], Loss: 0.0649, [Training] Acc: 0.6238, SE: 0.0000, SP: 0.0000, PC: 0.0000, F1: 0.0000, JS: 0.0000, DC: 0.0000 [Validation] Acc: 0.7816, SE: 0.0000, SP: 0.0000, PC: 0.0000, F1: 0.0000, JS: 0.0000, DC: 0.0000 Epoch [43/250], Loss: 0.0613, [Training] Acc: 0.6243, SE: 0.0000, SP: 0.0000, PC: 0.0000, F1: 0.0000, JS: 0.0000, DC: 0.0000 [Validation] Acc: 0.7814, SE: 0.0000, SP: 0.0000, PC: 0.0000, F1: 0.0000, JS: 0.0000, DC: 0.0000 Epoch [44/250], Loss: 0.0590, [Training] Acc: 0.6240, SE: 0.0000, SP: 0.0000, PC: 0.0000, F1: 0.0000, JS: 0.0000, DC: 0.0000 [Validation] Acc: 0.7815, SE: 0.0000, SP: 0.0000, PC: 0.0000, F1: 0.0000, JS: 0.0000, DC: 0.0000 Epoch [45/250], Loss: 0.0560, [Training] Acc: 0.6242, SE: 0.0000, SP: 0.0000, PC: 0.0000, F1: 0.0000, JS: 0.0000, DC: 0.0000 [Validation] Acc: 0.7815, SE: 0.0000, SP: 0.0000, PC: 0.0000, F1: 0.0000, JS: 0.0000, DC: 0.0000 Epoch [46/250], Loss: 0.0539, [Training] Acc: 0.6240, SE: 0.0000, SP: 0.0000, PC: 0.0000, F1: 0.0000, JS: 0.0000, DC: 0.0000 [Validation] Acc: 0.7815, SE: 0.0000, SP: 0.0000, PC: 0.0000, F1: 0.0000, JS: 0.0000, DC: 0.0000 Epoch [47/250], Loss: 0.0517, [Training] Acc: 0.6239, SE: 0.0000, SP: 0.0000, PC: 0.0000, F1: 0.0000, JS: 0.0000, DC: 0.0000 [Validation] Acc: 0.7816, SE: 0.0000, SP: 0.0000, PC: 0.0000, F1: 0.0000, JS: 0.0000, DC: 0.0000 Epoch [48/250], Loss: 0.0492, [Training] Acc: 0.6242, SE: 0.0000, SP: 0.0000, PC: 0.0000, F1: 0.0000, JS: 0.0000, DC: 0.0000 PS C:\Users\Egp\Desktop\Image_Segmentation-master>

    i train on my own data. i don'know why. can u help me ?

    opened by gdut3118007086 6
  • poor result on isbi challenge

    poor result on isbi challenge

    Hi: thank you for the code, i have trained the unet with the isbi dataset 100 epoch,batch size is 8(30 gray picture),but the result is very bad, about 11 percent(accuracy). And i wonder is there something wrong that i have done, could you give me some advise? data_loader .txt main .txt I just modify the data_loader.py and change the input channel to 1(the picture is gray)

    opened by Lijiatu321 6
  • error when set batch to 4

    error when set batch to 4

    Namespace(augmentation_prob=0.16924156139739033, batch_size=4, beta1=0.5, beta2=0.999, cuda_idx=3, image_size=224, img_ch=1, log_step=2, lr=0.00017304986946574825, mode='train', model_path='./models', model_type='R2U_Net', num_epochs=250, num_epochs_decay=186, num_workers=8, output_ch=1, result_path='./result/R2U_Net', t=3, test_path='/home/Data/DC_disk2/tsachi_dataset/dataset/test/', train_path='/home/Data/DC_disk2/tsachi_dataset/dataset/train/', val_step=2, valid_path='/home/Data/DC_disk2/tsachi_dataset/dataset/valid/') image count in train path :2400 image count in valid path :211 image count in test path :200 Traceback (most recent call last): File "main.py", line 101, in main(config) File "main.py", line 61, in main solver.train() File "/home/imagry/tsachi/solver.py", line 140, in train for i, (images, GT) in enumerate(self.train_loader): File "/usr/local/lib/python3.5/dist-packages/torch/utils/data/dataloader.py", line 336, in next return self._process_next_batch(batch) File "/usr/local/lib/python3.5/dist-packages/torch/utils/data/dataloader.py", line 357, in _process_next_batch raise batch.exc_type(batch.exc_msg) RuntimeError: Traceback (most recent call last): File "/usr/local/lib/python3.5/dist-packages/torch/utils/data/dataloader.py", line 106, in _worker_loop samples = collate_fn([dataset[i] for i in batch_indices]) File "/usr/local/lib/python3.5/dist-packages/torch/utils/data/dataloader.py", line 187, in default_collate return [default_collate(samples) for samples in transposed] File "/usr/local/lib/python3.5/dist-packages/torch/utils/data/dataloader.py", line 187, in return [default_collate(samples) for samples in transposed] File "/usr/local/lib/python3.5/dist-packages/torch/utils/data/dataloader.py", line 164, in default_collate return torch.stack(batch, 0, out=out) RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 0. Got 192 and 320 in dimension 2 at /pytorch/aten/src/TH/generic/THTensorMath.cpp:3616

    Exception ignored in: <bound method _DataLoaderIter.del of <torch.utils.data.dataloader._DataLoaderIter object at 0x7fca6e95b7b8>> Traceback (most recent call last): File "/usr/local/lib/python3.5/dist-packages/torch/utils/data/dataloader.py", line 399, in del self._shutdown_workers() File "/usr/local/lib/python3.5/dist-packages/torch/utils/data/dataloader.py", line 378, in _shutdown_workers self.worker_result_queue.get() File "/usr/lib/python3.5/multiprocessing/queues.py", line 345, in get return ForkingPickler.loads(res) File "/usr/local/lib/python3.5/dist-packages/torch/multiprocessing/reductions.py", line 151, in rebuild_storage_fd fd = df.detach() File "/usr/lib/python3.5/multiprocessing/resource_sharer.py", line 57, in detach with _resource_sharer.get_connection(self._id) as conn: File "/usr/lib/python3.5/multiprocessing/resource_sharer.py", line 87, in get_connection c = Client(address, authkey=process.current_process().authkey) File "/usr/lib/python3.5/multiprocessing/connection.py", line 487, in Client c = SocketClient(address) File "/usr/lib/python3.5/multiprocessing/connection.py", line 614, in SocketClient s.connect(address) ConnectionRefusedError: [Errno 111] Connection refused

    opened by Tsachi321 6
  • about label issue

    about label issue

    I change the background to 0 and others to 1 in my labels.But when I save the GT that is loaded from dataloader as a image, I get a image full of 0. Do you know why it happened?

    opened by kangyang94 6
  • Problems about JS=1 & DC>1

    Problems about JS=1 & DC>1

    First of all, thank you for your code where I do learned a lot from. I work on a dataset looks like isic2018 where only got one category and around 900 images for training.

    But I occur to a problem that when training, JS would keep equal to 1 and DC would even keeps greater than 1. I can't find reason since normalization in data_loader has already make sure DC could not larger than 1. Do you have any ideas?

    I noticed things would happens when I use R2Unet and when SR output is totally black(nothing is divided out), maybe that would be helpful to find out where got something wrong.

    Another problem is it seems the model cannot learn things during epoches processing, the best model would come out in first 5 epoches when training for like 200 epoches. Is that because model would get better result on small set and when it generalized to more images the score would drop? By the way, implementing only U-net would not get DC>1 and get some result.

    Thank you in advance for your help~


    Edit: Just found out JS would also stuck on 1.0 and DC greater than 1 when training Attention U-net but this time it get some result. So it maybe just JS and DC calculation problem No way this time same situation happens to U-net and I changed nothing...

    opened by Yiyiyimu 5
  • the length variable in the solver.py,

    the length variable in the solver.py,

    Thank you for sharing your amazing code;

    the "length" variable in the solver is the total data size, how in the evaluation.py ,the acc and othor metrics is calculated base on the batch, so the lengeth variable should be the iterations (base on batch), not the total number of the train data

    opened by ponykid 0
  • > hey guys. use pytorch<=1.2.0 (not confirmed) or change the funtion in

    > hey guys. use pytorch<=1.2.0 (not confirmed) or change the funtion in "evaluation" to fit the calculation of **bool tensor** will sovle the problem

    hey guys. use pytorch<=1.2.0 (not confirmed) or change the funtion in "evaluation" to fit the calculation of bool tensor will sovle the problem e.g. change "TP = ((SR==1)+(GT==1))==2" to "TP = SR & GT"

    thanks, i try it now, and do you have some recommend with pytorch > 1.2?

    Originally posted by @CodeXiaoLingYun in https://github.com/LeeJunHyun/Image_Segmentation/issues/58#issuecomment-741368638

    opened by Lenleooo 1
  • RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 0. Got 160 and 384 in dimension 2 at /pytorch/aten/src/TH/generic/THTensor.cpp:689

    RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 0. Got 160 and 384 in dimension 2 at /pytorch/aten/src/TH/generic/THTensor.cpp:689

    Traceback (most recent call last): File "/home/pxg/alex/U-Net/main.py", line 101, in main(config) File "/home/pxg/alex/U-Net/main.py", line 61, in main solver.train() File "/home/pxg/alex/U-Net/solver.py", line 140, in train for i, (images, GT) in enumerate(self.train_loader): File "/home/pxg/DANet-master/venv/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 819, in next return self._process_data(data) File "/home/pxg/DANet-master/venv/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 846, in _process_data data.reraise() File "/home/pxg/DANet-master/venv/lib/python3.6/site-packages/torch/_utils.py", line 369, in reraise raise self.exc_type(msg) RuntimeError: Caught RuntimeError in DataLoader worker process 0. Original Traceback (most recent call last): File "/home/pxg/DANet-master/venv/lib/python3.6/site-packages/torch/utils/data/_utils/worker.py", line 178, in _worker_loop data = fetcher.fetch(index) File "/home/pxg/DANet-master/venv/lib/python3.6/site-packages/torch/utils/data/_utils/fetch.py", line 47, in fetch return self.collate_fn(data) File "/home/pxg/DANet-master/venv/lib/python3.6/site-packages/torch/utils/data/_utils/collate.py", line 80, in default_collate return [default_collate(samples) for samples in transposed] File "/home/pxg/DANet-master/venv/lib/python3.6/site-packages/torch/utils/data/_utils/collate.py", line 80, in return [default_collate(samples) for samples in transposed] File "/home/pxg/DANet-master/venv/lib/python3.6/site-packages/torch/utils/data/_utils/collate.py", line 56, in default_collate return torch.stack(batch, 0, out=out) RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 0. Got 160 and 384 in dimension 2 at /pytorch/aten/src/TH/generic/THTensor.cpp:689

    Hello, can you help me see what the problem is? This is the result of batch_size = 8. When batch_size = 1, the computer gets stuck, can't move at all, and can only be restarted. Do you know what's going on? I hope you're free to help. Thank you.

    opened by wlj567 8
  • JS=1,DS>1and loss>1000

    JS=1,DS>1and loss>1000

    Hello, SORRY to bother you, when I refocused m attention Unet on my custom dataset, I also encountered JS which was always 1 and DICE >1, I saw previous comments, I changed Torch. Max to Max without any improvement, and my loss was always over 1000, what is the reason?

    223

    opened by kimjisoo12 1
Owner
leejunhyun
Graduate student, Korea University / Visiting student, Carnegie Mellon University
leejunhyun
Implementation of 🦩 Flamingo, state-of-the-art few-shot visual question answering attention net out of Deepmind, in Pytorch

?? Flamingo - Pytorch Implementation of Flamingo, state-of-the-art few-shot visual question answering attention net, in Pytorch. It will include the p

Phil Wang 630 Dec 28, 2022
Implementation of Transformer in Transformer, pixel level attention paired with patch level attention for image classification, in Pytorch

Transformer in Transformer Implementation of Transformer in Transformer, pixel level attention paired with patch level attention for image c

Phil Wang 272 Dec 23, 2022
Official Pytorch Implementation of Relational Self-Attention: What's Missing in Attention for Video Understanding

Relational Self-Attention: What's Missing in Attention for Video Understanding This repository is the official implementation of "Relational Self-Atte

mandos 43 Dec 7, 2022
Implementation of Deformable Attention in Pytorch from the paper "Vision Transformer with Deformable Attention"

Deformable Attention Implementation of Deformable Attention from this paper in Pytorch, which appears to be an improvement to what was proposed in DET

Phil Wang 128 Dec 24, 2022
Implementation of Uniformer, a simple attention and 3d convolutional net that achieved SOTA in a number of video classification tasks

Uniformer - Pytorch Implementation of Uniformer, a simple attention and 3d convolutional net that achieved SOTA in a number of video classification ta

Phil Wang 90 Nov 24, 2022
Implementation of STAM (Space Time Attention Model), a pure and simple attention model that reaches SOTA for video classification

STAM - Pytorch Implementation of STAM (Space Time Attention Model), yet another pure and simple SOTA attention model that bests all previous models in

Phil Wang 109 Dec 28, 2022
PyTorch code for our paper "Attention in Attention Network for Image Super-Resolution"

Under construction... Attention in Attention Network for Image Super-Resolution (A2N) This repository is an PyTorch implementation of the paper "Atten

Haoyu Chen 71 Dec 30, 2022
The Medical Detection Toolkit contains 2D + 3D implementations of prevalent object detectors such as Mask R-CNN, Retina Net, Retina U-Net, as well as a training and inference framework focused on dealing with medical images.

The Medical Detection Toolkit contains 2D + 3D implementations of prevalent object detectors such as Mask R-CNN, Retina Net, Retina U-Net, as well as a training and inference framework focused on dealing with medical images.

MIC-DKFZ 1.2k Jan 4, 2023
Neural networks applied in recognizing guitar chords using python, AutoML.NET with C# and .NET Core

Chord Recognition Demo application The demo application is written in C# with .NETCore. As of July 9, 2020, the only version available is for windows

Andres Mauricio Rondon Patiño 24 Oct 22, 2022
Implementation of the 😇 Attention layer from the paper, Scaling Local Self-Attention For Parameter Efficient Visual Backbones

HaloNet - Pytorch Implementation of the Attention layer from the paper, Scaling Local Self-Attention For Parameter Efficient Visual Backbones. This re

Phil Wang 189 Nov 22, 2022
Implementation of a memory efficient multi-head attention as proposed in the paper, "Self-attention Does Not Need O(n²) Memory"

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

Phil Wang 180 Jan 5, 2023
Official implementation of cosformer-attention in cosFormer: Rethinking Softmax in Attention

cosFormer Official implementation of cosformer-attention in cosFormer: Rethinking Softmax in Attention Update log 2022/2/28 Add core code License This

null 120 Dec 15, 2022
U^2-Net - Portrait matting This repository explores possibilities of using the original u^2-net model for portrait matting.

U^2-Net - Portrait matting This repository explores possibilities of using the original u^2-net model for portrait matting.

Dennis Bappert 104 Nov 25, 2022
U-2-Net: U Square Net - Modified for paired image training of style transfer

U2-Net: U Square Net Modified for paired image training of style transfer This is an unofficial repo making use of the code which was made available b

Doron Adler 43 Oct 3, 2022
Code for paper "ASAP-Net: Attention and Structure Aware Point Cloud Sequence Segmentation"

ASAP-Net This project implements ASAP-Net of paper ASAP-Net: Attention and Structure Aware Point Cloud Sequence Segmentation (BMVC2020). Overview We i

Hanwen Cao 26 Aug 25, 2022
Code for our ICASSP 2021 paper: SA-Net: Shuffle Attention for Deep Convolutional Neural Networks

SA-Net: Shuffle Attention for Deep Convolutional Neural Networks (paper) By Qing-Long Zhang and Yu-Bin Yang [State Key Laboratory for Novel Software T

Qing-Long Zhang 199 Jan 8, 2023
The open source code of SA-UNet: Spatial Attention U-Net for Retinal Vessel Segmentation.

SA-UNet: Spatial Attention U-Net for Retinal Vessel Segmentation(ICPR 2020) Overview This code is for the paper: Spatial Attention U-Net for Retinal V

Changlu Guo 151 Dec 28, 2022
Locally Enhanced Self-Attention: Rethinking Self-Attention as Local and Context Terms

LESA Introduction This repository contains the official implementation of Locally Enhanced Self-Attention: Rethinking Self-Attention as Local and Cont

Chenglin Yang 20 Dec 31, 2021
PyTorch implementation of ARM-Net: Adaptive Relation Modeling Network for Structured Data.

A ready-to-use framework of latest models for structured (tabular) data learning with PyTorch. Applications include recommendation, CRT prediction, healthcare analytics, and etc.

null 48 Nov 30, 2022