Skip to content

How to change to another loss function? #2

@duancaohui

Description

@duancaohui

Hi, your code is so nice.
I want to change MSE loss to another one, such as SSIM or add another term. In cnn_train_fbpconvent, there are many loss function definitions,such as

error_multiclass
error_binary
error_euclideanloss
......

error_euclideanloss is the definition of MSE, which is the most used function.
If I want to replace it with SSIM, I use next code:

function err = error_euclideanloss(opts, labels, res)
predictions = gather(res(end-1).x) ;
err_ssim = 0;
for i = size(predictions,4)
    err_ssim = err_ssim + ssim(predictions(:,:,1,i),labels(:,:,1,i));
end
err = err_ssim;

However I have two problems:
1.In network evaluation function vl_simplenn_fbpconvnet, network Forward and Backward computation, the layer.type have 'euclideanloss'

case 'euclideanloss'
            if testMode
                res(i+1).x = res(i).x;
            else
                res(i+1).x = vl_euclideanloss(res(i).x, l.class) ;
            end

The loss function is vl_euclideanloss, which is matconvnet default function. Should I change this definition? However, It seems to work even I don't change vl_euclideanloss. What is the right thing to do?

2.If I change MSE to SSIM, do I need to compute the derivatives of SSIM respect to rec image by myself? just as Hang Zhao in

Loss Functions for Image Restoration With Neural Networks, IEEE TRANSACTIONS ON COMPUTATIONAL IMAGING, VOL. 3, NO. 1, JANUARY 2017
qq 20180705202450

Or matconvnet can compute automatic?

thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions