pymic.loss.cls package

Submodules

pymic.loss.cls.basic module

class pymic.loss.cls.basic.AbstractClassificationLoss(params=None)

Bases: Module

Abstract Classification Loss.

forward(loss_input_dict)

The arguments should be written in the loss_input_dict dictionary, and it has the following fields.

Parameters:
  • prediction – A prediction with shape of [N, C] where C is the class number.

  • ground_truth – The corresponding ground truth, with shape of [N, 1].

Note that prediction is the digit output of a network, before using softmax.

training: bool
class pymic.loss.cls.basic.CrossEntropyLoss(params=None)

Bases: AbstractClassificationLoss

Standard Softmax-based CE loss.

forward(loss_input_dict)

The arguments should be written in the loss_input_dict dictionary, and it has the following fields.

Parameters:
  • prediction – A prediction with shape of [N, C] where C is the class number.

  • ground_truth – The corresponding ground truth, with shape of [N, 1].

Note that prediction is the digit output of a network, before using softmax.

training: bool
class pymic.loss.cls.basic.L1Loss(params=None)

Bases: AbstractClassificationLoss

L1 (MAE) loss for classification

forward(loss_input_dict)

The arguments should be written in the loss_input_dict dictionary, and it has the following fields.

Parameters:
  • prediction – A prediction with shape of [N, C] where C is the class number.

  • ground_truth – The corresponding ground truth, with shape of [N, 1].

Note that prediction is the digit output of a network, before using softmax.

training: bool
class pymic.loss.cls.basic.MSELoss(params=None)

Bases: AbstractClassificationLoss

Mean Square Error loss for classification.

forward(loss_input_dict)

The arguments should be written in the loss_input_dict dictionary, and it has the following fields.

Parameters:
  • prediction – A prediction with shape of [N, C] where C is the class number.

  • ground_truth – The corresponding ground truth, with shape of [N, 1].

Note that prediction is the digit output of a network, before using softmax.

training: bool
class pymic.loss.cls.basic.NLLLoss(params=None)

Bases: AbstractClassificationLoss

The negative log likelihood loss for classification.

forward(loss_input_dict)

The arguments should be written in the loss_input_dict dictionary, and it has the following fields.

Parameters:
  • prediction – A prediction with shape of [N, C] where C is the class number.

  • ground_truth – The corresponding ground truth, with shape of [N, 1].

Note that prediction is the digit output of a network, before using softmax.

training: bool
class pymic.loss.cls.basic.SigmoidCELoss(params=None)

Bases: AbstractClassificationLoss

Sigmoid-based CE loss.

forward(loss_input_dict)

The arguments should be written in the loss_input_dict dictionary, and it has the following fields.

Parameters:
  • prediction – A prediction with shape of [N, C] where C is the class number.

  • ground_truth – The corresponding ground truth, with shape of [N, 1].

Note that prediction is the digit output of a network, before using softmax.

training: bool

pymic.loss.cls.util module

pymic.loss.cls.util.get_soft_label(input_tensor, num_class, data_type='float')

Convert a label tensor to one-hot soft label.

Parameters:
  • input_tensor – Tensor with shape of [B, 1].

  • output_tensor – Tensor with shape of [B, num_class].

  • num_class – (int) Class number.

  • data_type – (str) float or double.

Module contents