• 大小: 2.84MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-11-18
  • 语言: Python
  • 标签:

资源简介

This repository contains the reference implementation for our proposed Convolutional CRFs in PyTorch (Tensorflow planned)

资源截图

代码片段和文件信息

“““
The MIT License (MIT)

Copyright (c) 2017 Marvin Teichmann
“““

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import os
import sys

import numpy as np
import imageio
# import scipy as scp
# import scipy.misc

import argparse

import logging

from convcrf import convcrf
from fullcrf import fullcrf

import torch
from torch.autograd import Variable

from utils import pascal_visualizer as vis
from utils import synthetic

import time

try:
    import matplotlib.pyplot as plt
    matplotlib = True
    figure = plt.figure()
    plt.close(figure)
except:
    matplotlib = False
    pass

logging.basicConfig(format=‘%(asctime)s %(levelname)s %(message)s‘
                    level=logging.INFO
                    stream=sys.stdout)


def do_crf_inference(image unary args):

    if args.pyinn or not hasattr(torch.nn.functional ‘unfold‘):
        # pytorch 0.3 or older requires pyinn.
        args.pyinn = True
        # Cheap and easy trick to make sure that pyinn is loadable.
        import pyinn

    # get basic hyperparameters
    num_classes = unary.shape[2]
    shape = image.shape[0:2]
    config = convcrf.default_conf
    config[‘filter_size‘] = 7
    config[‘pyinn‘] = args.pyinn

    if args.normalize:
        # Warning applying image normalization affects CRF computation.
        # The parameter ‘col_feats::schan‘ needs to be adapted.

        # Normalize image range
        #     This changes the image features and influences CRF output
        image = image / 255
        # mean substraction
        #    CRF is invariant to mean subtraction output is NOT affected
        image = image - 0.5
        # std normalization
        #       Affect CRF computation
        image = image / 0.3

        # schan = 0.1 is a good starting value for normalized images.
        # The relation is f_i = image / schan
        config[‘col_feats‘][‘schan‘] = 0.1

    # make input pytorch compatible
    img = image.transpose(2 0 1)  # shape: [3 hight width]
    # Add batch dimension to image: [1 3 height width]
    img = img.reshape([1 3 shape[0] shape[1]])
    img_var = Variable(torch.Tensor(img)).cuda()

    un = unary.transpose(2 0 1)  # shape: [3 hight width]
    # Add batch dimension to unary: [1 21 height width]
    un = un.reshape([1 num_classes shape[0] shape[1]])
    unary_var = Variable(torch.Tensor(un)).cuda()

    logging.debug(“Build ConvCRF.“)
    ##
    # Create CRF module
    gausscrf = convcrf.GaussCRF(conf=config shape=shape nclasses=num_classes)
    # Cuda computation is required.
    # A CPU implementation of our message passing is not provided.
    gausscrf.cuda()

    # Perform ConvCRF inference
    “““
    ‘Warm up‘: Our implementation compiles cuda kernels during runtime.
    The first inference call thus comes with some overhead.
    “““
    logging.info(“Start Computation.“)
    prediction = gausscrf.forward(unary=unary_var img=img_var)

    if args.n

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-05-15 16:56  ConvCRF-master\
     文件        1166  2018-05-15 16:56  ConvCRF-master\.gitignore
     文件        1073  2018-05-15 16:56  ConvCRF-master\LICENSE
     文件        2551  2018-05-15 16:56  ConvCRF-master\README.md
     文件        8780  2018-05-15 16:56  ConvCRF-master\benchmark.py
     目录           0  2018-05-15 16:56  ConvCRF-master\convcrf\
     文件           0  2018-05-15 16:56  ConvCRF-master\convcrf\__init__.py
     文件       19822  2018-05-15 16:56  ConvCRF-master\convcrf\convcrf.py
     目录           0  2018-05-15 16:56  ConvCRF-master\data\
     文件          68  2018-05-15 16:56  ConvCRF-master\data\.directory
     文件      236150  2018-05-15 16:56  ConvCRF-master\data\2007_000033_0img.png
     文件        1710  2018-05-15 16:56  ConvCRF-master\data\2007_000033_5labels.png
     文件      343420  2018-05-15 16:56  ConvCRF-master\data\2007_000129_0img.png
     文件        4835  2018-05-15 16:56  ConvCRF-master\data\2007_000129_5labels.png
     文件      420470  2018-05-15 16:56  ConvCRF-master\data\2007_000332_0img.png
     文件        2174  2018-05-15 16:56  ConvCRF-master\data\2007_000332_5labels.png
     文件      326961  2018-05-15 16:56  ConvCRF-master\data\2007_000346_0img.png
     文件        2433  2018-05-15 16:56  ConvCRF-master\data\2007_000346_5labels.png
     文件      370339  2018-05-15 16:56  ConvCRF-master\data\2007_000847_0img.png
     文件        2530  2018-05-15 16:56  ConvCRF-master\data\2007_000847_5labels.png
     文件      411275  2018-05-15 16:56  ConvCRF-master\data\2007_001284_0img.png
     文件        3839  2018-05-15 16:56  ConvCRF-master\data\2007_001284_5labels.png
     文件      228540  2018-05-15 16:56  ConvCRF-master\data\2007_001288_0img.png
     文件        1801  2018-05-15 16:56  ConvCRF-master\data\2007_001288_5labels.png
     目录           0  2018-05-15 16:56  ConvCRF-master\data\output\
     文件      163137  2018-05-15 16:56  ConvCRF-master\data\output\Res1.png
     文件      131469  2018-05-15 16:56  ConvCRF-master\data\output\Res2.pdf
     文件      161758  2018-05-15 16:56  ConvCRF-master\data\output\Res2.png
     文件      163137  2018-05-15 16:56  ConvCRF-master\data\output\Res_1.png
     文件        7037  2018-05-15 16:56  ConvCRF-master\demo.py
     目录           0  2018-05-15 16:56  ConvCRF-master\fullcrf\
............此处省略9个文件信息

评论

共有 条评论