File size: 1,646 Bytes
98e2c81 |
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 |
import json
import time
from dataset.tracks_motion import TracksMotion
from GPS import GPS
import gradio as gr
def _synthesis(synthesis_setting, motion_data):
model = GPS(
init_mode = f"random_synthesis/{synthesis_setting['frames']}",
noise_sigma = synthesis_setting['noise_sigma'],
coarse_ratio = 0.2,
pyr_factor = synthesis_setting['pyr_factor'],
num_stages_limit = -1,
silent=True,
device='cpu'
)
synthesized_motion = model.run(
motion_data,
mode="match_and_blend",
ext={
'criteria': {
'type': 'PatchCoherentLoss',
'patch_size': synthesis_setting['patch_size'],
'stride': synthesis_setting['stride'] if 'stride' in synthesis_setting.keys() else 1,
'loop': synthesis_setting['loop'],
'coherent_alpha': synthesis_setting['alpha'] if synthesis_setting['completeness'] else None,
},
'optimizer': "match_and_blend",
'num_itrs': synthesis_setting['num_steps'],
}
)
return synthesized_motion
def synthesis(data):
data = json.loads(data)
# create track object
data['setting']['coarse_ratio'] = -1
motion_data = TracksMotion(data['tracks'], scale=data['scale'])
start = time.time()
synthesized_motion = _synthesis(
data['setting'],
[motion_data]
)
end = time.time()
data['time'] = end - start
data['tracks'] = motion_data.parse(synthesized_motion)
return data
demo = gr.Interface(fn=synthesis, inputs="json", outputs="json")
demo.launch()
|