https://github.com/ai-forever/segm-model

An easy-to-run semantic segmentation model based on Unet

https://github.com/ai-forever/segm-model

Science Score: 36.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
    Links to: arxiv.org
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (12.8%) to scientific vocabulary

Keywords

pytorch segmentation semantic-segmentation unet
Last synced: 5 months ago · JSON representation

Repository

An easy-to-run semantic segmentation model based on Unet

Basic Info
  • Host: GitHub
  • Owner: ai-forever
  • License: mit
  • Language: Python
  • Default Branch: master
  • Homepage:
  • Size: 123 KB
Statistics
  • Stars: 13
  • Watchers: 2
  • Forks: 7
  • Open Issues: 0
  • Releases: 0
Topics
pytorch segmentation semantic-segmentation unet
Created about 4 years ago · Last pushed about 3 years ago
Metadata Files
Readme License

README.md

Segmentation model

This is a model for semantic segmentation based on LinkNet (Unet-like architecture).

SEGM-model is a part of ReadingPipeline repo.

Demo

In the demo you can find an example of using the SEGM-model (you can run it in your Google Colab).

Quick setup and start

The provided Dockerfile is supplied to build an image with CUDA support and cuDNN.

Preparations

  • Clone the repo.
  • Download and extract dataset to the data/ folder.
  • sudo make all to build a docker image and create a container. Or sudo make all GPUS=device=0 CPUS=10 if you want to specify gpu devices and limit CPU-resources.

If you don't want to use Docker, you can install dependencies via requirements.txt

Configuring the model

You can change the segm_config.json and set some of the the base training and evaluating parameters: num epochs, image size, saving dir, etc.

Class specific parameters

Parameters in the classes are set individually for each class of the model. The order of the subdicts in the classes corresponds to the order of the mask layers in the predicted tensor. Each dictionary contains parameters for model classes to pre- and post-process stages, for example:

"classes": { "class_name": { "annotation_classes": ["class1", "class2"], "polygon2mask": { "ShrinkMaskMaker": {"shrink_ratio": 0.5} }, "postprocess": { "threshold": 0.8, "min_area": 10 } }, ... }

  • annotation_classes - a list with class names from annotation["categories"]. If multiple are passed, classes will be merged.
  • polygon2mask - a list of functions that will be applied one by one to convert polygons to mask and prepare target for this class. There are several functions available - to create regular, border or shrinked masks. To add a new function to the processing, you need to add it to the PREPROCESS_FUNC dictionary in prepare_dataset.py and also specify it in the polygon2mask-dict in the config.

Postprocessing settings:

  • threshold is the threshold of the model's confidence. Above this value the mask becomes Ture, below - False. It helps to remove some false predictions of the model with low confidence.
  • min_area - the minimum area of a polygon (polygons with less area will be removed).

Dataset folders

Individual for train / val / test:

"train": { "datasets": [ { "json_path": "path/to/annotaion.json", "image_root": "path/to/folder/with/images", "processed_data_path": "path/to/save/processed_dataset.csv", "prob": 0.5 }, ... ], "epoch_size": 2000, "batch_size": 8 } In datasets-dict, you can specify paths to multiple datasets for train / test / val processes.

  • json_path (to the annotation.json) and image_root (to the folder with images) are paths to the dataset with markup in COCO format.
  • processed_data_path - the saving path of the final csv file, which is produced by the prepare_dataset.py script. This csv-file will be used in the train stage. This file stores paths to the processed target masks.
  • epoch_size - the size of an epoch. If you set it to null, then the epoch size will be equal to the amount of samples in the all datasets.
  • It is also possible to specify several datasets for the train/validation/test, setting the probabilities for each dataset separately (the sum of prob can be greater than 1, since normalization occurs inside the processing).

Input dataset description

The input dataset should be in COCO format. The annotation.json should have the following dictionaries:

  • annotation["categories"] - a list of dicts with a categories info (categotiy names and indexes).
  • annotation["images"] - a list of dictionaries with a description of images, each dictionary must contain fields:
    • file_name - name of the image file.
    • id for image id.
  • annotation["annotations"] - a list of dictioraties with a murkup information. Each dictionary stores a description for one polygon from the dataset, and must contain the following fields:
    • image_id - the index of the image on which the polygon is located.
    • category_id - the polygon’s category index.
    • segmentation - the coordinates of the polygon, a list of numbers - which are coordinate pairs x and y.

Prepare target masks

To preprocess dataset and create target masks for training:

bash python scripts/prepare_dataset.py --config_path path/to/the/segm_config.json

The script creates a target masks for train/val/test stages. The path to the input dataset is set in the config file in json_path and image_root. The output csv file is saved to processed_data_path from the config.

Training

To train the model:

bash python scripts/train.py --config_path path/to/the/segm_config.json

Evaluating

To test the model:

bash python scripts/evaluate.py \ --config_path path/to/the/segm_config.json \ --model_path path/to/the/model-weights.ckpt

ONNX

You can convert Torch model to ONNX to speed up inference on cpu.

bash python scripts/torch2onnx.py \ --config_path path/to/the/ocr_config.json \ --model_path path/to/the/model-weights.ckpt

Owner

  • Name: AI Forever
  • Login: ai-forever
  • Kind: organization
  • Location: Armenia

Creating ML for the future. AI projects you already know. We are non-profit organization with members from all over the world.

GitHub Events

Total
Last Year

Issues and Pull Requests

Last synced: 10 months ago

All Time
  • Total issues: 0
  • Total pull requests: 1
  • Average time to close issues: N/A
  • Average time to close pull requests: 15 minutes
  • Total issue authors: 0
  • Total pull request authors: 1
  • Average comments per issue: 0
  • Average comments per pull request: 0.0
  • Merged pull requests: 1
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
  • Julia132 (1)
Top Labels
Issue Labels
Pull Request Labels

Dependencies

requirements.txt pypi
  • Pillow ==8.4.0
  • albumentations ==1.1.0
  • matplotlib ==3.5.0
  • numpy ==1.21.4
  • opencv-python ==4.6.0.66
  • pandas ==1.3.4
  • pudb ==2021.1
  • pyclipper ==1.3.0
  • scikit-learn ==1.0.1
  • scipy ==1.4.1
  • shapely ==1.8.0
  • torch >=1.6.0
  • tqdm ==4.62.3
Dockerfile docker
  • nvidia/cuda 11.4.0-devel-ubuntu20.04 build