torch/nn — pull request #82 by yossibiton (2014-10-08 08:11:47+00:00)
Title: ClassNLLCriterion - adding classes weights input

Adding class weights is relevant when you have unbalanced training set, adding custom weights can help in these cases.

Example for input weights -

--- compute frequency for each class
class_freqs = torch.Tensor(nLabels):fill(0)
for iImage = 1,trainData:size() do
label = trainData.labels[iImage]
class_freqs[label] = class_freqs[label] + 1
end

print('classes frequencies :')
print(class_freqs)
class_weights = torch.Tensor(nLabels):fill(0)
for iLabel = 1,nLabels do
class_weights[iLabel] = 1 / class_freqs[iLabel]
end
class_weights = class_weights / class_weights:sum()
print('classes weights :')
print(class_weights)