# pytorch-nested-unet **Repository Path**: liu-qi/pytorch-nested-unet ## Basic Information - **Project Name**: pytorch-nested-unet - **Description**: PyTorch implementation of UNet++ (Nested U-Net). - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-10-22 - **Last Updated**: 2021-10-22 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # PyTorch implementation of UNet++ (Nested U-Net) [![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](LICENSE) This repository contains code for a image segmentation model based on [UNet++: A Nested U-Net Architecture for Medical Image Segmentation](https://arxiv.org/abs/1807.10165) implemented in PyTorch. [**NEW**] Add support for multi-class segmentation dataset. [**NEW**] Add support for PyTorch 1.x. ## Requirements - PyTorch 1.x or 0.41 ## Installation 1. Create an anaconda environment. ```sh conda create -n= python=3.6 anaconda conda activate ``` 2. Install PyTorch. ```sh conda install pytorch torchvision cudatoolkit=10.1 -c pytorch ``` 3. Install pip packages. ```sh pip install -r requirements.txt ``` ## Training on [2018 Data Science Bowl](https://www.kaggle.com/c/data-science-bowl-2018) dataset 1. Download dataset from [here](https://www.kaggle.com/c/data-science-bowl-2018/data) to inputs/ and unzip. The file structure is the following: ``` inputs └── data-science-bowl-2018 ├── stage1_train | ├── 00ae65... │ │ ├── images │ │ │ └── 00ae65... │ │ └── masks │ │ └── 00ae65... │ ├── ... | ... ``` 2. Preprocess. ```sh python preprocess_dsb2018.py ``` 3. Train the model. ```sh python train.py --dataset dsb2018_96 --arch NestedUNet ``` 4. Evaluate. ```sh python val.py --name dsb2018_96_NestedUNet_woDS ``` ### (Optional) Using LovaszHingeLoss 1. Clone LovaszSoftmax from [bermanmaxim/LovaszSoftmax](https://github.com/bermanmaxim/LovaszSoftmax). ``` git clone https://github.com/bermanmaxim/LovaszSoftmax.git ``` 2. Train the model with LovaszHingeLoss. ``` python train.py --dataset dsb2018_96 --arch NestedUNet --loss LovaszHingeLoss ``` ## Training on original dataset Make sure to put the files as the following structure (e.g. the number of classes is 2): ``` inputs └── ├── images | ├── 0a7e06.jpg │ ├── 0aab0a.jpg │ ├── 0b1761.jpg │ ├── ... | └── masks ├── 0 | ├── 0a7e06.png | ├── 0aab0a.png | ├── 0b1761.png | ├── ... | └── 1 ├── 0a7e06.png ├── 0aab0a.png ├── 0b1761.png ├── ... ``` 1. Train the model. ``` python train.py --dataset --arch NestedUNet --img_ext .jpg --mask_ext .png ``` 2. Evaluate. ``` python val.py --name _NestedUNet_woDS ``` ## Results ### DSB2018 (96x96) Here is the results on DSB2018 dataset (96x96) with LovaszHingeLoss. | Model | IoU | Loss | |:------------------------------- |:-------:|:-------:| | U-Net | 0.839 | 0.365 | | Nested U-Net | 0.842 |**0.354**| | Nested U-Net w/ Deepsupervision |**0.843**| 0.362 |