27 lines
799 B
Python
27 lines
799 B
Python
#
|
|
# extract from original zero123 code : https://github.com/cvlab-columbia/zero123/
|
|
#
|
|
|
|
import torch
|
|
import numpy as np
|
|
import os
|
|
import math
|
|
import torch.nn as nn
|
|
from einops import repeat
|
|
|
|
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)
|