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)
| 8 | |
| 9 | |
| 10 | def 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 | |
| 28 | def reduce_loss(loss, reduction): |