change_loading_options
Browse files- app.py +41 -7
- mogen/models/utils/imagebind_wrapper.py +4 -4
app.py
CHANGED
|
@@ -35,7 +35,19 @@ from mogen.datasets.paramUtil import (
|
|
| 35 |
from mogen.datasets.utils import recover_from_ric
|
| 36 |
from mogen.datasets.pipelines import RetargetSkeleton
|
| 37 |
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
def motion_temporal_filter(motion, sigma=1):
|
| 40 |
motion = motion.reshape(motion.shape[0], -1)
|
| 41 |
for i in range(motion.shape[1]):
|
|
@@ -57,7 +69,7 @@ def plot_tomato(data, kinematic_chain, result_path, npy_path, fps, sigma=None):
|
|
| 57 |
|
| 58 |
def create_lmm():
|
| 59 |
config_path = "configs/lmm/lmm_small_demo.py"
|
| 60 |
-
ckpt_path = "
|
| 61 |
cfg = mmcv.Config.fromfile(config_path)
|
| 62 |
model = build_architecture(cfg.model)
|
| 63 |
load_checkpoint(model, ckpt_path, map_location='cpu')
|
|
@@ -70,15 +82,37 @@ def create_lmm():
|
|
| 70 |
|
| 71 |
# device = 'cpu'
|
| 72 |
device = 'cuda'
|
| 73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
model_lmm = create_lmm()
|
| 75 |
-
model_imagebind = imagebind_huge(pretrained=True)
|
| 76 |
model_imagebind.eval()
|
| 77 |
model_imagebind.to(device)
|
| 78 |
-
rtg_skl = RetargetSkeleton(tgt_skel_file=
|
| 79 |
|
| 80 |
-
mean_path = "
|
| 81 |
-
std_path = "
|
| 82 |
mean = np.load(mean_path)
|
| 83 |
std = np.load(std_path)
|
| 84 |
|
|
|
|
| 35 |
from mogen.datasets.utils import recover_from_ric
|
| 36 |
from mogen.datasets.pipelines import RetargetSkeleton
|
| 37 |
|
| 38 |
+
import requests
|
| 39 |
+
|
| 40 |
+
def load_large_files(relative_path):
|
| 41 |
+
# URL to file in the Hugging Face Hub
|
| 42 |
+
url = "https://huggingface.co/mingyuan/data_hf/" + relative_path
|
| 43 |
+
# Temporary download in Space
|
| 44 |
+
file_path = "/tmp/" + relative_path.split('/')[-1]
|
| 45 |
+
|
| 46 |
+
response = requests.get(url)
|
| 47 |
+
with open(file_path, "wb") as f:
|
| 48 |
+
f.write(response.content)
|
| 49 |
+
return file_path
|
| 50 |
+
|
| 51 |
def motion_temporal_filter(motion, sigma=1):
|
| 52 |
motion = motion.reshape(motion.shape[0], -1)
|
| 53 |
for i in range(motion.shape[1]):
|
|
|
|
| 69 |
|
| 70 |
def create_lmm():
|
| 71 |
config_path = "configs/lmm/lmm_small_demo.py"
|
| 72 |
+
ckpt_path = load_file_list["lmm"]
|
| 73 |
cfg = mmcv.Config.fromfile(config_path)
|
| 74 |
model = build_architecture(cfg.model)
|
| 75 |
load_checkpoint(model, ckpt_path, map_location='cpu')
|
|
|
|
| 82 |
|
| 83 |
# device = 'cpu'
|
| 84 |
device = 'cuda'
|
| 85 |
+
type = "hf"
|
| 86 |
+
|
| 87 |
+
if type == "local":
|
| 88 |
+
load_file_list = {
|
| 89 |
+
"mean": "../data_hf/data/motionverse/statistics/mean.npy",
|
| 90 |
+
"std": "../data_hf/data/motionverse/statistics/std.npy",
|
| 91 |
+
"skeleton": "../data_hf/data/motionverse/statistics/skeleton.npy",
|
| 92 |
+
"lmm": "../data_hf/data/motionverse/pretrained/lmm_small_demo.pth",
|
| 93 |
+
"imagebind": "../data_hf/data/motionverse/pretrained/imagebind_huge.pth"
|
| 94 |
+
}
|
| 95 |
+
os.environ["NO_PROXY"] = os.environ["no_proxy"] = "localhost, 127.0.0.1:7860"
|
| 96 |
+
else:
|
| 97 |
+
src_file_list = {
|
| 98 |
+
"mean": "data/motionverse/statistics/mean.npy",
|
| 99 |
+
"std": "data/motionverse/statistics/std.npy",
|
| 100 |
+
"skeleton": "data/motionverse/statistics/skeleton.npy",
|
| 101 |
+
"lmm": "data/motionverse/pretrained/lmm_small_demo.pth",
|
| 102 |
+
"imagebind": "data/motionverse/pretrained/imagebind_huge.pth"
|
| 103 |
+
}
|
| 104 |
+
load_file_list = {}
|
| 105 |
+
for key in src_file_list.keys():
|
| 106 |
+
load_file_list[key] = load_large_files(src_file_list[key])
|
| 107 |
+
|
| 108 |
model_lmm = create_lmm()
|
| 109 |
+
model_imagebind = imagebind_huge(pretrained=True, ckpt_path=load_file_list["imagebind"])
|
| 110 |
model_imagebind.eval()
|
| 111 |
model_imagebind.to(device)
|
| 112 |
+
rtg_skl = RetargetSkeleton(tgt_skel_file=load_file_list["skeleton"])
|
| 113 |
|
| 114 |
+
mean_path = load_file_list["mean"]
|
| 115 |
+
std_path = load_file_list["std"]
|
| 116 |
mean = np.load(mean_path)
|
| 117 |
std = np.load(std_path)
|
| 118 |
|
mogen/models/utils/imagebind_wrapper.py
CHANGED
|
@@ -42,7 +42,7 @@ class FeatureExtractor(imagebind_model.ImageBindModel):
|
|
| 42 |
return word_feat, seq_feat
|
| 43 |
|
| 44 |
|
| 45 |
-
def imagebind_huge(pretrained=False):
|
| 46 |
model = FeatureExtractor(
|
| 47 |
vision_embed_dim=1280,
|
| 48 |
vision_num_blocks=32,
|
|
@@ -56,9 +56,9 @@ def imagebind_huge(pretrained=False):
|
|
| 56 |
)
|
| 57 |
|
| 58 |
if pretrained:
|
| 59 |
-
file_path = os.path.abspath(os.path.dirname(__file__))
|
| 60 |
-
ckpt_dir = os.path.join(file_path, '../../../data/motionverse/pretrained')
|
| 61 |
-
ckpt_path = os.path.join(ckpt_dir, 'imagebind_huge.pth')
|
| 62 |
if not os.path.exists(ckpt_path):
|
| 63 |
print(
|
| 64 |
"Downloading imagebind weights to motionverse/pretrained/imagebind_huge.pth ..."
|
|
|
|
| 42 |
return word_feat, seq_feat
|
| 43 |
|
| 44 |
|
| 45 |
+
def imagebind_huge(pretrained=False, ckpt_path=None):
|
| 46 |
model = FeatureExtractor(
|
| 47 |
vision_embed_dim=1280,
|
| 48 |
vision_num_blocks=32,
|
|
|
|
| 56 |
)
|
| 57 |
|
| 58 |
if pretrained:
|
| 59 |
+
# file_path = os.path.abspath(os.path.dirname(__file__))
|
| 60 |
+
# ckpt_dir = os.path.join(file_path, '../../../data/motionverse/pretrained')
|
| 61 |
+
# ckpt_path = os.path.join(ckpt_dir, 'imagebind_huge.pth')
|
| 62 |
if not os.path.exists(ckpt_path):
|
| 63 |
print(
|
| 64 |
"Downloading imagebind weights to motionverse/pretrained/imagebind_huge.pth ..."
|