Spaces:
Sleeping
Sleeping
File size: 6,222 Bytes
cb900d8 6f7cc86 cb900d8 |
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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
import numpy as np
import gradio as gr
import os
import tempfile
import shutil
# from gradio_inter.predict_from_file import predict_from_file
# from gradio_inter.create_bash_file import create_bash_file
def create_bash_file(single_path_seq):
ori_bash_file = "./scripts_demo/train_grab_pointset_points_dyn_s1.sh"
with open(ori_bash_file) as rf:
bash_string = rf.read()
bash_string = bash_string.replace("./data/102_grab_all_data.npy", single_path_seq)
dst_bash_file = "./scripts_demo/train_grab_pointset_points_dyn_s1.sh"
with open(dst_bash_file, "w") as wf:
wf.write(bash_string)
return dst_bash_file
# from sample.reconstruct_data_taco import reconstruct_from_file
def create_temp_file(path: str) -> str:
temp_dir = tempfile.gettempdir()
temp_folder = os.path.join(temp_dir, "denoising")
os.makedirs(temp_folder, exist_ok=True)
# Clean up directory
# for i in os.listdir(temp_folder):
# print("Removing", i)
# os.remove(os.path.join(temp_folder, i))
temp_path = os.path.join(temp_folder, path.split("/")[-1])
shutil.copy2(path, temp_path)
return temp_path
# from gradio_inter.predict import predict_from_data
# from gradio_inter.predi
def transpose(matrix):
return matrix.T
def predict(file_path: str):
temp_file_path = create_temp_file(file_path)
# predict_from_file
temp_bash_file = create_bash_file(temp_file_path)
os.system(f"bash {temp_bash_file}")
temp_dir = tempfile.gettempdir()
base_exp_dir = os.path.join(temp_dir, "quasi_sim")
os.makedirs(base_exp_dir, exist_ok=True)
base_exp_dir = os.path.join(base_exp_dir, "exp")
os.makedirs(base_exp_dir, exist_ok=True)
base_exp_dir = f"{base_exp_dir}/wmask"
print(f"self.base_exp_dir:", base_exp_dir)
base_exp_dir = base_exp_dir + f"_reverse_value_totviews_"
os.makedirs(base_exp_dir, exist_ok=True)
# self.dataset = Dataset(self.conf['dataset'])
mano_pts_retar_sv_info_fn = os.path.join(base_exp_dir, f"ts_to_hand_obj_verts.npy")
return mano_pts_retar_sv_info_fn
# res_file_path = "/tmp/denoising/save/predicted_infos_seed_0_tag_20231104_017_jts_spatial_t_100__st_0.npy"
# saved_path = reconstruct_from_file(temp_file_path)
# return saved_path
def create_demo():
USAGE = """## Input data format
Currently, the demo accepts a `.pkl` file containing an hand-object sequence organized as the following format:
```python
{
"hand_pose": numpy.ndarray(seq_length, 48), # MANO pose at each frame
"hand_trans": numpy.ndarray(seq_length, 3), # hand global translation at each frmae
"hand_shape": numpy.ndarray(10), # MANO shape coefficients
"hand_verts": numpy.ndarray(seq_length, 778, 3), # MANO hand vertices
"hand_faces": numpy.ndarray(1538, 3), # MANO hand faces
"obj_verts": numpy.ndarray(seq_length, num_obj_verts, 3), # object vertices at each frame
"obj_faces": numpy.ndarray(num_obj_faces, 3), # object faces
"obj_pose": numpy.ndarray(seq_length, 4, 4), # object pose at each frame
}
```
We provide an example [here](https://drive.google.com/file/d/17oqKMhQNpRqSdApyuuCmTrPkrFl0Cqp6/view?usp=sharing). **The demo is under developing and will support more data formats in the future.**
## To run the demo,
1. Upload a `pickle` file to the left box by draging your file or clicking the box to open the file explorer.
2. Clik the `Submit` button to run the demo.
3. The denoised sequence will be output as a `.npy` file and can be downloaded from the right box.
Since the model runs on CPU currently, the speed is not very fast. For instance, it takes abount 1200s to process the [example](https://drive.google.com/file/d/17oqKMhQNpRqSdApyuuCmTrPkrFl0Cqp6/view?usp=sharing) mentioned above which contains 288 frames. Please be patient and wait for the result.
To run the model faster, please visit our [github repo](https://github.com/Meowuu7/GeneOH-Diffusion), follow the instructions and run the model on your own server or local machine.
## Output data format
The output is a `.npy` file containing the denoised sequence organized as the following format:
```python
{
"predicted_info": xxx
"bf_ct_verts": numpy.ndarray(seq_length, 778, 3), # denoised MANO vertices
"bf_ct_rot_var": numpy.ndarray(seq_length, 3), # denoised MANO global rotation coefficients
"bf_ct_theta_var": numpy.ndarray(seq_length, 45), # denoised MANO global pose coefficients
"bf_ct_beta_var": numpy.ndarray(1, 10), # denoised MANO shape coefficients
"bf_ct_transl_var": numpy.ndarray(seq_length, 3), # denoised hand global translation
}
```
The corresponding output file of the [example](https://drive.google.com/file/d/17oqKMhQNpRqSdApyuuCmTrPkrFl0Cqp6/view?usp=sharing) mentioned above can be downloaded [here](https://drive.google.com/file/d/1Ah-qwV6LXlOyaBBe0qQRu1lN-BpKt2Y3/view?usp=sharing).
"""
with gr.Blocks() as demo:
gr.Markdown(USAGE)
# demo =
# gr.Interface(
# predict,
# # gr.Dataframe(type="numpy", datatype="number", row_count=5, col_count=3),
# gr.File(type="filepath"),
# gr.File(type="filepath"),
# cache_examples=False
# )
input_file = gr.File(type="filepath")
output_file = gr.File(type="filepath")
gr.Interface(
predict,
# gr.Dataframe(type="numpy", datatype="number", row_count=5, col_count=3),
input_file,
output_file,
cache_examples=False
)
inputs = input_file
outputs = output_file
gr.Examples(
examples=[os.path.join(os.path.dirname(__file__), "./data/102_grab_all_data.npy")],
inputs=inputs,
fn=predict,
outputs=outputs,
)
return demo
if __name__ == "__main__":
demo = create_demo()
demo.launch() |