Spaces:
Paused
Paused
Download src/utils/train_util.py from florendrian/InstantMesh: direct link, hf CLI and curl.
- Browser
- Download file 857 Bytes
-
https://huggingface.co/spaces/florendrian/InstantMesh/resolve/main/src/utils/train_util.py
- Command line
-
hf download hf://spaces/florendrian/InstantMesh/src/utils/train_util.py
-
curl -L -o train_util.py https://huggingface.co/spaces/florendrian/InstantMesh/resolve/main/src/utils/train_util.py
857 Bytes
| import importlib | |
| def count_params(model, verbose=False): | |
| total_params = sum(p.numel() for p in model.parameters()) | |
| if verbose: | |
| print(f"{model.__class__.__name__} has {total_params*1.e-6:.2f} M params.") | |
| return total_params | |
| def instantiate_from_config(config): | |
| if not "target" in config: | |
| if config == '__is_first_stage__': | |
| return None | |
| elif config == "__is_unconditional__": | |
| return None | |
| raise KeyError("Expected key `target` to instantiate.") | |
| return get_obj_from_str(config["target"])(**config.get("params", dict())) | |
| def get_obj_from_str(string, reload=False): | |
| module, cls = string.rsplit(".", 1) | |
| if reload: | |
| module_imp = importlib.import_module(module) | |
| importlib.reload(module_imp) | |
| return getattr(importlib.import_module(module, package=None), cls) | |