Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
P

Pytorch-UNet

> 编程语言
Open source

PyTorch implementation of the U-Net for image semantic segmentation with high quality images

11.6K stars0 likes3 views
WebsiteGitHub

About

PyTorch implementation of the U-Net for image semantic segmentation with high quality images

U-Net: Semantic segmentation with PyTorch

Customized implementation of the U-Net in PyTorch for Kaggle's Carvana Image Masking Challenge from high definition images.

  • Quick start
    • Without Docker
    • With Docker
  • Description
  • Usage
    • Docker
    • Training
    • Prediction
  • Weights & Biases
  • Pretrained model
  • Data

Quick start

Without Docker

  1. Install CUDA

  2. Install PyTorch 1.13 or later

  3. Install dependencies

bash
pip install -r requirements.txt
  1. Download the data and run training:
bash
bash scripts/download_data.sh
python train.py --amp

With Docker

  1. Install Docker 19.03 or later:
bash
curl https://get.docker.com | sh && sudo systemctl --now enable docker
  1. Install the NVIDIA container toolkit:
bash
distribution=$(. /etc/os-release;echo $ID$VERSION_ID) \
   && curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add - \
   && curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list
sudo apt-get update
sudo apt-get install -y nvidia-docker2
sudo systemctl restart docker
  1. Download and run the image:
bash
sudo docker run --rm --shm-size=8g --ulimit memlock=-1 --gpus all -it milesial/unet
  1. Download the data and run training:
bash
bash scripts/download_data.sh
python train.py --amp

Description

This model was trained from scratch with 5k images and scored a Dice coefficient of 0.988423 on over 100k test images.

It can be easily used for multiclass segmentation, portrait segmentation, medical segmentation, ...

Usage

Note : Use Python 3.6 or newer

Docker

A docker image containing the code and the dependencies is available on DockerHub. You can download and jump in the container with (docker >=19.03):

bash
docker run -it --rm --shm-size=8g --ulimit memlock=-1 --gpus all milesial/unet

Training

…

By default, the scale is 0.5, so if you wish to obtain better results (but use more memory), set it to 1.

Automatic mixed precision is also available with the --amp flag. Mixed precision allows the model to use less memory and to be faster on recent GPUs by using FP16 arithmetic. Enabling AMP is recommended.

Prediction

After training your model and saving it to MODEL.pth, you can easily test the output masks on your images via the CLI.

To predict a single image and save it:

python predict.py -i image.jpg -o output.jpg

To predict a multiple images and show them without saving them:

python predict.py -i image1.jpg image2.jpg --viz --no-save

…

You can specify which model file to use with --model MODEL.pth.

Weights & Biases

The training progress can be visualized in real-time using Weights & Biases. Loss curves, validation curves, weights and gradient histograms, as well as predicted masks are logged to the platform.

When launching a training, a link will be printed in the console. Click on it to go to your dashboard. If you have an existing W&B account, you can link it by setting the WANDB_API_KEY environment variable. If not, it will create an anonymous run which is automatically deleted after 7 days.

Pretrained model

A pretrained model is available for the Carvana dataset. It can also be loaded from torch.hub:

python
net = torch.hub.load('milesial/Pytorch-UNet', 'unet_carvana', pretrained=True, scale=0.5)

Available scales are 0.5 and 1.0.

Data

The Carvana data is available on the Kaggle website.

You can also download it using the helper script:

bash scripts/download_data.sh

The input images and target masks should be in the data/imgs and data/masks folders respectively (note that the imgs and masks folder should not contain any sub-folder or any other files, due to the greedy data-loader). For Carvana, images are RGB and masks are black and white.

You can use your own dataset as long as you make sure it is loaded properly in utils/data_loading.py.


Original paper by Olaf Ronneberger, Philipp Fischer, Thomas Brox:

U-Net: Convolutional Networks for Biomedical Image Segmentation

Issues· 126 open

View all issuesOpen on GitHub
  • #536

    สล็อตออนไลน์ สล็อตเว็บตรง เชื่อถือได้100% แตกหนัก ระบบ AUTO

    Updated Apr 29, 2026
  • #529

    kaggle数据下载失败

    Updated Mar 25, 2026
  • #518

    The model's loss value turns into NaN

    Updated Mar 23, 2026
  • #436

    No Improvement in Accuracy with higher batch size like 8 (Multi GPU)

    Updated Mar 20, 2026
  • #472

    Refer the datasets to download from Kaggle

    Updated Mar 6, 2026
  • #533

    manhwa-maker

    Updated Dec 1, 2025
  • #532

    why

    Updated Nov 16, 2025
  • #314

    训练结果不好,怎么调参数

    Updated Nov 7, 2025
  • #500

    why my result is a white picture

    Updated Nov 1, 2025
  • #531

    all the input arrays must have same number of dimensions, but the array at index 0 has 2 dimension(s) and the array at index 1 has 1 dimension(s)

    Updated Oct 27, 2025

> Tags

Pythonconvolutional-networksconvolutional-neural-networksdeep-learningkaggle

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 28, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言