• 大小: 11KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-05-12
  • 语言: 其他
  • 标签: CRF  

资源简介

条件随机场代码(图像分割),可以直接对图像进行分割,也可以用于深度学习网络的后端优化

资源截图

代码片段和文件信息

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
“““
Created on Sat Mar 10 16:04:33 2018

@author: sy
“““



import numpy as np
import pydensecrf.densecrf as dense_crf
#from . import potentials
from densecrf2 import potentials

class DenseCRF:
    def __init__(self num_classes zero_unsure unary_potential pairwise_potentials use_2d = ‘rgb-1d‘):
        “““A wrapper for the PyDenseCRF functions. 
        
        Currently only 2D images are supported.
        
        Arguments
        ---------
        num_classes : int
        unary_potential : UnaryPotential
        pairwise_potentials : PairwisePotential or array like
            A collection of PairwisePotential instances.
        “““
        if isinstance(pairwise_potentials potentials.PairwisePotential):
            pairwise_potentials = [pairwise_potentials]

        for pairwise_potential in pairwise_potentials:
            self.check_potential(pairwise_potential potentials.PairwisePotential)
        self.check_potential(unary_potential potentials.UnaryPotential)

        self.zero_unsure = zero_unsure
        self.pairwise_potentials = pairwise_potentials
        self.unary_potential = unary_potential
        
        self.use_2d = use_2d
        self.num_classes = num_classes
        self.crf_model = None
        self._image = None
        self._colour_axis = None

        # Variables needed for the CRF model to run
        self._Q = None
        self._tmp1 = None
        self._tmp2 = None

    def set_image(self image probabilities colour_axis=None class_axis=None label_source=‘label‘):
        “““Set the image for the CRF model to perform inference on.

        Arguments
        ---------
        image : numpy.ndarray
            The image to segment.
        probabilities : numpy.ndarray
            Class probabilities for each pixel.
        colour_axis : int
            Which axis of the image array the colour information lies in.
            Usually the last axis (-1) but can also be the first axis (0).
            If ‘image‘ is a grayscale image this should be set to None.
        class_axis : int
            Which axis of the probabilities array the class information lies.
            If the probabilites are on the form
                ‘‘[image_height image_width class]‘‘
            then class axis should be set to either ‘3‘ or ‘-1‘.
        “““
        if colour_axis is None:
            colour_axis = -1
            image = image.reshape(*image.shape 1)

        self._image = image
        self._colour_axis = self.fix_negative_index(colour_axis)
        self._class_axis = class_axis
        self._probabilities = probabilities
        self._image_shape = \
            image.shape[:self._colour_axis] + image.shape[self._colour_axis+1:]
        self.label_source = label_source

##        ‘rgb-1d‘ or ‘rgb-2d‘ or ‘non-rgb‘
        if self.use_2d == ‘rgb-1d‘:
            self.process_rgb_label()
            self._create_model()
            self._set_potentials_1d()

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-03-12 09:38  CRF-semantic-segmentation-master\
     文件        1491  2018-03-12 09:38  CRF-semantic-segmentation-master\README.md
     目录           0  2018-03-12 09:38  CRF-semantic-segmentation-master\densecrf2\
     文件          50  2018-03-12 09:38  CRF-semantic-segmentation-master\densecrf2\__init__.py
     文件       10298  2018-03-12 09:38  CRF-semantic-segmentation-master\densecrf2\crf_model.py
     文件        9681  2018-03-12 09:38  CRF-semantic-segmentation-master\densecrf2\potentials.py
     目录           0  2018-03-12 09:38  CRF-semantic-segmentation-master\examples\
     文件        3742  2018-03-12 09:38  CRF-semantic-segmentation-master\examples\non_rgb_image_test_1.py
     文件        3800  2018-03-12 09:38  CRF-semantic-segmentation-master\examples\non_rgb_image_test_2.py
     文件        3350  2018-03-12 09:38  CRF-semantic-segmentation-master\examples\rgb_image_test.py

评论

共有 条评论