forked from kaleido-lab/dolphin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
58 lines (43 loc) · 1.55 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import os, sys, uuid
import importlib
import numpy as np
import torch
import random
def instantiate_from_config(config, **kwargs):
if not "target" in config:
raise KeyError("Expected key `target` to instantiate.")
return get_obj_from_str(config["target"])(**config.get("params", dict()), **kwargs)
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)
def seed_everything(seed):
random.seed(seed)
np.random.seed(seed)
torch.manual_seed(seed)
torch.cuda.manual_seed_all(seed)
return seed
def get_new_video_name(org_vid_name, func_name="update"):
head_tail = os.path.split(org_vid_name)
head = head_tail[0]
tail = head_tail[1]
name_split = tail.split(".")[0].split("_")
this_new_uuid = str(uuid.uuid4())[:4]
if len(name_split) == 1:
most_org_file_name = name_split[0]
else:
assert len(name_split) == 4
most_org_file_name = name_split[3]
recent_prev_file_name = name_split[0]
new_file_name = (
f"{this_new_uuid}_{func_name}_{recent_prev_file_name}_{most_org_file_name}.mp4"
)
return os.path.join(head, new_file_name)
def generate_video_name_mp4():
return os.path.join("video", str(uuid.uuid4())[:8] + ".mp4")
def generate_audio_name():
return os.path.join("video", str(uuid.uuid4())[:8] + ".wav")
def get_new_uuid():
return str(uuid.uuid4())[:8]