Download scripts/early_stop_score_function.py from MONAI/VISTA3D-HF: direct link, hf CLI and curl.
- Browser
- Download file 454 Bytes
-
https://huggingface.co/MONAI/VISTA3D-HF/resolve/main/scripts/early_stop_score_function.py
- Command line
-
hf download hf://MONAI/VISTA3D-HF/scripts/early_stop_score_function.py
-
curl -L -o early_stop_score_function.py https://huggingface.co/MONAI/VISTA3D-HF/resolve/main/scripts/early_stop_score_function.py
454 Bytes
| import os | |
| import torch | |
| import torch.distributed as dist | |
| def score_function(engine): | |
| val_metric = engine.state.metrics["val_mean_dice"] | |
| if dist.is_initialized(): | |
| device = torch.device("cuda:" + os.environ["LOCAL_RANK"]) | |
| val_metric = torch.tensor([val_metric]).to(device) | |
| dist.all_reduce(val_metric, op=dist.ReduceOp.SUM) | |
| val_metric /= dist.get_world_size() | |
| return val_metric.item() | |
| return val_metric | |