Download dinov3/eval/dense/depth/utils.py from Addax-Data-Science/AFR-DFV-v2: direct link, hf CLI and curl.
- Browser
- Download file 661 Bytes
-
https://huggingface.co/Addax-Data-Science/AFR-DFV-v2/resolve/main/dinov3/eval/dense/depth/utils.py
- Command line
-
hf download hf://Addax-Data-Science/AFR-DFV-v2/dinov3/eval/dense/depth/utils.py
-
curl -L -o utils.py https://huggingface.co/Addax-Data-Science/AFR-DFV-v2/resolve/main/dinov3/eval/dense/depth/utils.py
661 Bytes
| # Copyright (c) Meta Platforms, Inc. and affiliates. | |
| # | |
| # This software may be used and distributed in accordance with | |
| # the terms of the DINOv3 License Agreement. | |
| import torch | |
| def cast_to(o, dtype: torch.dtype): | |
| if isinstance(o, torch.Tensor): | |
| return o.to(dtype) | |
| if isinstance(o, tuple): | |
| return tuple(cast_to(u, dtype) for u in o) | |
| if isinstance(o, list): | |
| return list(cast_to(u, dtype) for u in o) | |
| if isinstance(o, dict): | |
| return {k: cast_to(u, dtype) for k, u in o.items()} | |
| if isinstance(o, (bool, int, float, str, type(None))): | |
| return o | |
| raise NotImplementedError(f"Unsupported type: {type(o)}") | |