-
Notifications
You must be signed in to change notification settings - Fork 119
/
vllab_nn_L1_loss.m
38 lines (35 loc) · 1.07 KB
/
vllab_nn_L1_loss.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
function Y = vllab_nn_L1_loss(X, Z, dzdy)
% -------------------------------------------------------------------------
% Description:
% L1 (Charbonnier) loss function
% forward : Y = vllab_nn_L1_loss(X, Z)
% backward: Y = vllab_nn_L1_loss(X, Z, dzdy)
%
% Input:
% - X : predicted data
% - Z : ground truth data
% - dzdy : the derivative of the output
%
% Output:
% - Y : loss when forward, derivative of loss when backward
%
% Citation:
% Deep Laplacian Pyramid Networks for Fast and Accurate Super-Resolution
% Wei-Sheng Lai, Jia-Bin Huang, Narendra Ahuja, and Ming-Hsuan Yang
% IEEE Conference on Computer Vision and Pattern Recognition (CVPR), 2017
%
% Contact:
% Wei-Sheng Lai
% University of California, Merced
% -------------------------------------------------------------------------
eps = 1e-6;
d = X - Z;
e = sqrt( d.^2 + eps );
if nargin <= 2
Y = sum(e(:));
else
Y = d ./ e;
Y = Y .* dzdy;
end
end