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

hi!
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

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 = model.net.SquaredL2Distance([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 = model.net.SquaredL2Distance([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

you can see this: https://github.com/facebookresearch/Detectron/issues/353
use StopGradient

Thanks for the suggestion!