Skip to main content

Conditional Random Field Implementation for segmentation models as used in Deeplab-v2

Project description

License: MIT PyPI

Fully Connected CRF

This repo implements CRF as described in Deeplab paper it takes about 0.2 seconds per image. Following image is taken form DeepLab paper

alt text

Requirements

Python <= 3.6
pydensecrf
cv2
matplotlib
gray2color

It takes following arguments. For details visit project page.

        ⚠ Zero pixels are consdered background
        img_path : path to an image, 
                        Format [H, W, 3]; values ranging from [0, 255]
        model_op_path : path model output of the same input image.
                        Format [H, W]; values ranging from [0, num_of_classes]
        num_of_classes : number of classes in a dataset e.g. in cityscape has 30 classes
        clr_op : color the output or not a bool
        pallet2use : see https://pypi.org/project/gray2color/ for details
        img_w : for resizing image and mask to same size default is 1024
        img_h : for resizing image and mask to same size default is 512
        apperance_kernel : The PairwiseBilateral term in CRF a list of values in order [sxy, srgb, compat]  
                            default values are [8, 164, 100]
        spatial_kernel : The PairwiseGaussian term in CRF a list of values in order [sxy, compat]  
                            default values are [3, 10]
from seg_crf import Seg_CRF

img_path='D:/Anaconda/Image_analysis/cat.png'
model_op_path='D:/Anaconda/Image_analysis/mask.png'

crf = Seg_CRF(img_path, model_op_path, 2, img_w=1024, img_h=512, clr_op=True, pallet2use ='cityscape')

gray, rgb = crf.start()
plt.imshow(rgb)

Appearance and Spatial Kernel

# Default Values are
apperance_kernel = [8, 164, 100] # PairwiseBilateral [sxy, srgb, compat]  
spatial_kernel = [3, 10]         # PairwiseGaussian  [sxy, compat] 

# or if you want to to specify seprately for each XY direction and RGB color channel then

apperance_kernel = [(1.5, 1.5), (64, 64, 64), 100] # PairwiseBilateral [sxy, srgb, compat]  
spatial_kernel = [(0.5, 0.5), 10]                  # PairwiseGaussian  [sxy, compat] 
# Use like
crf = Seg_CRF(img_path, model_op_path, 2, img_w=1024, img_h=512,
                 apperance_kernel=apperance_kernel, spatial_kernel=spatial_kernel,
                 clr_op=True, pallet2use ='cityscape')

gray, rgb = crf.start()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

seg_crf-1.0.0.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

seg_crf-1.0.0-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file seg_crf-1.0.0.tar.gz.

File metadata

  • Download URL: seg_crf-1.0.0.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.7.6

File hashes

Hashes for seg_crf-1.0.0.tar.gz
Algorithm Hash digest
SHA256 de71eae55aab234cac3264dce7eda9f6ee7f2660f067e464d1c8e32e1eb56170
MD5 2c6270c05cd38a479a2e11bb499d4b58
BLAKE2b-256 ea600f3bb956e31dcdc95d02ea948ae5311e004b3f83073f4c18e5c39448a6b1

See more details on using hashes here.

File details

Details for the file seg_crf-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: seg_crf-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.7.6

File hashes

Hashes for seg_crf-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c8cf243bb22855f42f2d6fb897197e2c3c683f925a9f3d2e01d360587502106d
MD5 dbf66ae1e37493a8c115578b8d0314cf
BLAKE2b-256 2aba64cebadd27c92907a7b8cb33fd4320253f87eaeba1c8f8bebe285b41ab70

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page