mirror of
https://github.com/Stability-AI/generative-models.git
synced 2025-12-19 14:24:21 +01:00
Stable Video Diffusion
This commit is contained in:
27
sgm/util.py
27
sgm/util.py
@@ -246,3 +246,30 @@ def get_configs_path() -> str:
|
||||
if os.path.isdir(candidate):
|
||||
return candidate
|
||||
raise FileNotFoundError(f"Could not find SGM configs in {candidates}")
|
||||
|
||||
|
||||
def get_nested_attribute(obj, attribute_path, depth=None, return_key=False):
|
||||
"""
|
||||
Will return the result of a recursive get attribute call.
|
||||
E.g.:
|
||||
a.b.c
|
||||
= getattr(getattr(a, "b"), "c")
|
||||
= get_nested_attribute(a, "b.c")
|
||||
If any part of the attribute call is an integer x with current obj a, will
|
||||
try to call a[x] instead of a.x first.
|
||||
"""
|
||||
attributes = attribute_path.split(".")
|
||||
if depth is not None and depth > 0:
|
||||
attributes = attributes[:depth]
|
||||
assert len(attributes) > 0, "At least one attribute should be selected"
|
||||
current_attribute = obj
|
||||
current_key = None
|
||||
for level, attribute in enumerate(attributes):
|
||||
current_key = ".".join(attributes[: level + 1])
|
||||
try:
|
||||
id_ = int(attribute)
|
||||
current_attribute = current_attribute[id_]
|
||||
except ValueError:
|
||||
current_attribute = getattr(current_attribute, attribute)
|
||||
|
||||
return (current_attribute, current_key) if return_key else current_attribute
|
||||
|
||||
Reference in New Issue
Block a user