crowdcount.utils¶
Save the models¶
-
class
crowdcount.utils.
Saver
(mode='remain', path=None)[source]¶ Saves the best models
- Parameters
mode (string, optional) – Specifies the mode to confirm how to save the models. ‘replace’ | ‘remain’. ‘replace’: only the best model will be saved ‘remain’: the old best model won’t be replaced by the new best model. Default: “replace”
path (string, optional) – The directory you want to save to. The default is None, and the sys will create a directory called “./exp” automatically.
Init functions¶
-
crowdcount.utils.
weights_normal_init
(model, dev=0.01)[source]¶ For modules in model, if module is Convolutional layer: init with torch.nn.init.normal_(mean, std), elif module is Linear layer: init with torch.nn.init.fill_(val), elif module is Batch Normalization layer: init with torch.nn.init.constant_(tensor, val)
- Parameters
model (torch.nn.module) – the model to be init
dev (float) – the standard deviation used in norm init
- Returns
model (torch.nn.module)
Loss functions¶
-
class
crowdcount.utils.
AVGLoss
[source]¶ The loss function used in train part, torch.nn.MSELoss with reduction=’mean’, which means the sum of the density map will be divided by the number of pixels in the density map. It can be described as:
\[\ell(\theta) = \frac{1}{2N*B}\sum_{i=1}^N\parallel{Z(X_i;\theta) - Z_i^GT}\parallel_2^2\]
-
class
crowdcount.utils.
SUMLoss
[source]¶ The loss function used in train part, torch.nn.MSELoss with reduction=’sum’, which means the density map will be summed. It can be described as:
\[\ell(\theta) = \frac{1}{2*B}\sum_{i=1}^N\parallel{Z(X_i;\theta) - Z_i^GT}\parallel_2^2\]
-
class
crowdcount.utils.
TestLoss
[source]¶ The loss function used in test part, this loss just get mae and mse with (output-ground_truth) and mae ** 2