Hello, I want to define a new loss function. Specifically, with the L1 norm applied on the weight of FC layer, my aim is to learn sparse feature. The code is following:
params = model.state_dict()
p = params['module.fc.weight']
loss = nn.CrossEntropyLoss()(output, target_var) + lambda*L1Loss(p)
here is my loss function
loss = torch,norm(weight, p=1)
Obviously, it does work. The L1 loss dosen’t decrease, but the CrossEntropyLoss seems well.
So, How to combine them? or my definition on L1 loss is wrong?