densecrf.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:material-seg 作者: paulu 项目源码 文件源码
def __init__(self, image, pred, params):
        """ pred: [C x H x W] """

        #assert pred.shape[1:3] == prediction_shape
        prediction_shape = pred.shape[1:3]

        self.prediction_shape = prediction_shape
        self.npixels = np.prod(prediction_shape[0:2])
        self.nlabels = pred.shape[0]
        self.params = params

        # Convert from [C x H x W] to [(H*W) x C], remove 'other' class
        unary_probs = pred.reshape(self.nlabels, self.npixels).transpose()
        unary_probs[:, config.NAME_TO_LABEL['other']] = 0.0

        self.unary_costs = -np.log(np.clip(unary_probs + params['unary_prob_padding'], 1e-20, 1e20))
        self.unary_costs = np.copy(self.unary_costs, order='C').astype(np.float32)

        if image.shape[0:2] == prediction_shape:
            self.im_lab = rgb2lab(image)
        else:
            self.im_lab = rgb2lab(transform.resize(image, prediction_shape[0:2]))

        # scale features to have have dynamic range ~10-20ish
        self.scaled_positions = (
            np.indices(prediction_shape[0:2]).astype(np.float32) *
            10.0 / float(np.min(prediction_shape[0:2]))
        )
        self.bilateral_features = np.zeros((self.npixels, 5), dtype=np.float32)
        self.bilateral_features[:, 0] = self.scaled_positions[0].ravel()
        self.bilateral_features[:, 1] = self.scaled_positions[1].ravel()
        self.bilateral_features[:, 2] = self.im_lab[:, :, 0].ravel() / 10.0
        self.bilateral_features[:, 3] = self.im_lab[:, :, 1].ravel() / 10.0
        self.bilateral_features[:, 4] = self.im_lab[:, :, 2].ravel() / 10.0

        #position_features = np.zeros((npixels, 2), dtype=np.float32)
        #position_features[:, 0] = scaled_positions[0].ravel() * (params['position_theta_xy'] / mindim)
        #position_features[:, 1] = scaled_positions[1].ravel() * (params['position_theta_xy'] / mindim)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号