Skip to content

Latest commit

 

History

History
29 lines (23 loc) · 914 Bytes

README.md

File metadata and controls

29 lines (23 loc) · 914 Bytes

crfseg: CRF layer for segmentation in PyTorch

Conditional random field (CRF) is a classical graphical model which allows to make structured predictions in such tasks as image semantic segmentation or sequence labeling.

You can learn about it in papers:

Installation

pip install crfseg

Usage

Can be easily used as differentiable (and moreover learnable) postprocessing layer of your NN for segmentation.

import torch
import torch.nn as nn
from crfseg import CRF

model = nn.Sequential(
    nn.Identity(),  # your NN
    CRF(n_spatial_dims=2)
)

batch_size, n_channels, spatial = 10, 1, (100, 100)
x = torch.zeros(batch_size, n_channels, *spatial)
log_proba = model(x)