forked from AIHGF/matconvnet-deepReg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RegLoss.m
60 lines (49 loc) · 1.55 KB
/
RegLoss.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
classdef RegLoss < dagnn.ElementWise
properties
loss = 'tukeyloss' %default loss
end
properties (Transient)
average = 0
numAveraged = 0
iter = 0
scbox= 0
end
methods
function outputs = forward(obj, inputs, params)
obj.iter = obj.net.iter;
obj.scbox = obj.net.scbox;
outputs{1} = vl_nntukeyloss(inputs{1}, inputs{2}, obj.iter, obj.scbox, [], 'loss', obj.loss);
n = obj.numAveraged ;
m = n + size(inputs{1},4) ;
obj.average = (n * obj.average + gather(outputs{1})) / m ;
obj.numAveraged = m ;
end
function [derInputs, derParams] = backward(obj, inputs, params, derOutputs)
obj.iter = obj.net.iter;
obj.scbox = obj.net.scbox;
derInputs{1} = vl_nntukeyloss(inputs{1}, inputs{2}, obj.iter, obj.scbox, derOutputs{1}, 'loss', obj.loss);
derInputs{2} = [] ;
derParams = {} ;
end
function reset(obj)
obj.average = 0 ;
obj.numAveraged = 0 ;
obj.iter = 0 ;
obj.scbox = 0 ;
end
function outputSizes = getOutputSizes(obj, inputSizes, paramSizes)
outputSizes{1} = [1 1 1 inputSizes{1}(1)] ;
end
function rfs = getReceptiveFields(obj)
% the receptive field depends on the dimension of the variables
% which is not known until the network is run
rfs(1,1).size = [NaN NaN] ;
rfs(1,1).stride = [NaN NaN] ;
rfs(1,1).offset = [NaN NaN] ;
rfs(2,1) = rfs(1,1) ;
end
function obj = RegLoss(varargin)
obj.load(varargin) ;
end
end
end