Caffe2-- how to modify SquaredL2Distance(L2 loss)to contain weight?

(chuli) #1

I want to use L2 loss(SquaredL2Distance) in caffe2. But it doesn’t contain weight. for example, SoftmaxWithLoss contains weight

My aim is to set weight to be 0 to not train it

(Carlos Yeverino) #2

Hello chuli,

I am also trying to use the SquaredL2Distance as the output layer of my CNN network. I tried the following attempts, however I got the mentioned errors:

       # FIRST ATTEMPT. Error got:  Tensor type mismatch, caller expects elements to be float while tensor contains double Error from operator
        dist =[label, fc9_], 'dist')
		predictions = dist.AveragedLoss([], ['predictions'])

        # SECOND ATTEMPT: Error got: Exception: Exception when creating gradient for [Cast] ...  Argument 'from_type' of type int or string is required to get the gradient of CastOp .
		label_float = model.Cast(label, None, to=core.DataType.FLOAT)
		dist =[label_float, fc9_], 'dist')
		predictions = dist.AveragedLoss([], ['predictions'])

Any suggestions on how to use it properly?

I created also a ticket [Caffe2] SquaredL2Distance as output layer of CNN network. Error: Exception when creating gradient for [Cast] related to the L2 loss

(chuli) #3

you can see this:
use StopGradient

(Carlos Yeverino) #4

Thanks for the suggestion!