Skip to content

Legacy

init_params(net)

Init layer parameters.

Source code in V3_3/src/super_gradients/training/legacy/utils.py
62
63
64
65
66
67
68
69
70
71
72
73
74
75
def init_params(net):
    """Init layer parameters."""
    for m in net.modules():
        if isinstance(m, nn.Conv2d):
            init.kaiming_normal(m.weight, mode="fan_out")
            # if m.bias:
            #    init.constant(m.bias, -5)
        elif isinstance(m, nn.BatchNorm2d):
            init.constant(m.weight, 1)
            init.constant(m.bias, 0)
        elif isinstance(m, nn.Linear):
            init.normal(m.weight, std=1e-3)
            if m.bias:
                init.constant(m.bias, 0)

is_better(new_metric, current_best_metric, metric_to_watch='acc')

Determines which of the two metrics is better, the higher if watching acc or lower when watching loss

Parameters:

Name Type Description Default
new_metric

the new metric

required
current_best_metric

the compared to metric

required
metric_to_watch

acc or loss

'acc'

Returns:

Type Description

bool, True if new metric is better than current

Source code in V3_3/src/super_gradients/training/legacy/utils.py
111
112
113
114
115
116
117
118
119
def is_better(new_metric, current_best_metric, metric_to_watch="acc"):
    """
    Determines which of the two metrics is better, the higher if watching acc or lower when watching loss
    :param new_metric:                 the new metric
    :param current_best_metric:        the compared to metric
    :param metric_to_watch:             acc or loss
    :return: bool, True if new metric is better than current
    """
    return metric_to_watch == "acc" and new_metric > current_best_metric or (metric_to_watch == "loss" and current_best_metric > new_metric)

makedirs_if_not_exists(dir_path)

make new directory in dir_path if it doesn't exists :param dir_path - full path of directory

Source code in V3_3/src/super_gradients/training/legacy/utils.py
122
123
124
125
126
127
128
def makedirs_if_not_exists(dir_path: str):
    """
    make new directory in dir_path if it doesn't exists
        :param dir_path - full path of directory
    """
    if not os.path.exists(dir_path):
        os.makedirs(dir_path)