pengsun / tvnorm-nn

Total Variation Norm as Torch 7 nn module

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

tvnorm-nn

Total Variation Norm as Torch 7 nn module. Expose several modules to calculate Total Variation Norm (TODO: ref?) as nn layer or loss function regularizer. Only support CUDA tensor, cudnn required.

Requirement

  • Torch
  • nn
  • cunn
  • cudnn

Install

git clone this repo, cd to the directory, then type command

luarocks make

Usage

We'll use the following data size notations hereafter:

B: batch size
C: #channels/#feature maps
H: image height
W: image width

nn.SpatialTVNormCriterion()

TV Norm as criterion. Convenient when used as regularizer. See also nn.MultiCriterion. Expect tensor size:

input: B, C, H, W
output: 1 (lua number)

Calculate TV norm for each H, W sized image with C channels by calling nn.SpatialTVNorm, then average the results by size B to get the loss in lua number. Forward() and Backward() routines are implemented. No parameters.

Examples: see temp/timing_tvnormCri.lua.

nn.SpatialTVNorm()

Expect tensor size:

input: B, C, H, W
output: B

Calculate TV norm for each H, W sized image with C channels. Each result has been averaged by size C*H*W. Forward() and Backward() routines are implemented. No parameters.

Examples: see temp/timing_tvnorm.lua.

nn.SpatialSimpleGradFilter()

Calculate x- and y- directional gradients (consecutive pixels subtraction) for each of the H, W sized image. Expect tensor size:

input: B, 1, H, W
output: B, 2, H-1, W-1

Examples: see temp/timing_simplegrad.luat

About

Total Variation Norm as Torch 7 nn module


Languages

Language:Lua 97.0%Language:CMake 3.0%