MCPcopy Create free account
hub / github.com/VCIP-RGBD/DFormer / get_class_weight

Function get_class_weight

models/losses/utils.py:10–25  ·  view source on GitHub ↗

Get class weight for loss function. Args: class_weight (list[float] | str | None): If class_weight is a str, take it as a file name and read from it.

(class_weight)

Source from the content-addressed store, hash-verified

8
9
10def get_class_weight(class_weight):
11 """Get class weight for loss function.
12
13 Args:
14 class_weight (list[float] | str | None): If class_weight is a str,
15 take it as a file name and read from it.
16 """
17 if isinstance(class_weight, str):
18 # take it as a file path
19 if class_weight.endswith(".npy"):
20 class_weight = np.load(class_weight)
21 else:
22 # pkl, json or yaml
23 class_weight = mmcv.load(class_weight)
24
25 return class_weight
26
27
28def reduce_loss(loss, reduction):

Callers 4

__init__Method · 0.70
__init__Method · 0.70
__init__Method · 0.70
__init__Method · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected