Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

retargeting on win #225

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions retargeting/demo-win.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import os
from datasets.bvh_parser import BVH_file
from datasets.bvh_writer import BVH_writer
from models.IK import fix_foot_contact
from os.path import join as pjoin


# downsampling and remove redundant joints
def copy_ref_file(src, dst):
file = BVH_file(src)
writer = BVH_writer(file.edges, file.names)
writer.write_raw(file.to_tensor(quater=True)[..., ::2], 'quaternion', dst)


def get_height(file):
file = BVH_file(file)
return file.get_height()


def example(src_name, dest_name, bvh_name, test_type, output_path):
if not os.path.exists(output_path):
os.makedirs(output_path)

input_file = os.getcwd()+'\\datasets\\Mixamo\\{}\\{}'.format(src_name, bvh_name)
ref_file = os.getcwd()+'\\datasets\\Mixamo\\{}\\{}'.format(dest_name, bvh_name)
copy_ref_file(input_file, pjoin(output_path, 'input.bvh'))
copy_ref_file(ref_file, pjoin(output_path, 'gt.bvh'))
height = get_height(input_file)

bvh_name = bvh_name.replace(' ', '_')
input_file = os.getcwd()+'\\datasets\\Mixamo\\{}\\{}'.format(src_name, bvh_name)
ref_file = os.getcwd()+'\\datasets\\Mixamo\\{}\\{}'.format(dest_name, bvh_name)

cmd = 'python eval_single_pair.py --input_bvh={} --target_bvh={} --output_filename={} --test_type={}'.format(
input_file, ref_file, pjoin(output_path, 'result.bvh'), test_type
)
os.system(cmd)

fix_foot_contact(pjoin(output_path, 'result.bvh'),
pjoin(output_path, 'input.bvh'),
pjoin(output_path, 'result.bvh'),
height)


if __name__ == '__main__':
example('Aj', 'BigVegas', 'Dancing Running Man.bvh', 'intra', os.getcwd()+'\\examples\\intra_structure')
example('BigVegas', 'Mousey_m', 'Dual Weapon Combo.bvh', 'cross', os.getcwd()+'\\examples\\cross_structure')
print('Finished!')
2 changes: 1 addition & 1 deletion retargeting/demo.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
python demo.py
python demo-win.py
28 changes: 21 additions & 7 deletions retargeting/eval_single_pair.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import os
import platform
import torch
from models import create_model
from datasets import create_dataset
import option_parser

separator = '/'
if platform.system() == 'Windows':
separator = '\\'

def eval_prepare(args):
character = []
file_id = []
character_names = []
character_names.append(args.input_bvh.split('/')[-2])
character_names.append(args.target_bvh.split('/')[-2])
character_names.append(args.input_bvh.split(separator)[-2])
character_names.append(args.target_bvh.split(separator)[-2])
if args.test_type == 'intra':
if character_names[0].endswith('_m'):
character = [['BigVegas', 'BigVegas'], character_names]
Expand All @@ -35,9 +39,9 @@ def eval_prepare(args):


def recover_space(file):
l = file.split('/')
l = file.split(separator)
l[-1] = l[-1].replace('_', ' ')
return '/'.join(l)
return separator.join(l)


def main():
Expand All @@ -54,9 +58,16 @@ def main():
args.target_bvh = recover_space(args.target_bvh)
args.output_filename = recover_space(args.output_filename)

# print(input_bvh)
# print(input_bvh)
# print(input_bvh)
# print(target_bvh)
# print(target_bvh)
# print(target_bvh)

character_names, file_id, src_id = eval_prepare(args)
input_character_name = args.input_bvh.split('/')[-2]
output_character_name = args.target_bvh.split('/')[-2]
input_character_name = args.input_bvh.split(separator)[-2]
output_character_name = args.target_bvh.split(separator)[-2]
output_filename = args.output_filename

test_device = args.cuda_device
Expand Down Expand Up @@ -91,7 +102,10 @@ def main():
model.set_input(input_motion)
model.test()

os.system('cp "{}/{}/0_{}.bvh" "./{}"'.format(model.bvh_path, output_character_name, src_id, output_filename))
if platform.system() == 'Windows':
os.system('cp "{}\\{}\\0_{}.bvh" "{}"'.format(model.bvh_path, output_character_name, src_id, output_filename))
else:
os.system('cp "{}/{}/0_{}.bvh" "./{}"'.format(model.bvh_path, output_character_name, src_id, output_filename))


if __name__ == '__main__':
Expand Down
6 changes: 5 additions & 1 deletion retargeting/models/architecture.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
from option_parser import try_mkdir

import os
import platform

separator = '/'
if platform.system() == 'Windows':
separator = '\\'

class GAN_model(BaseModel):
def __init__(self, args, character_names, dataset):
Expand Down Expand Up @@ -42,7 +46,7 @@ def __init__(self, args, character_names, dataset):
for i in range(self.n_topology):
self.err_crit.append(Eval_Criterion(dataset.joint_topologies[i]))
self.id_test = 0
self.bvh_path = os.path.join(args.save_dir, 'results/bvh')
self.bvh_path = os.path.join(args.save_dir, 'results'+separator+'bvh')
option_parser.try_mkdir(self.bvh_path)

self.writer = []
Expand Down
13 changes: 11 additions & 2 deletions retargeting/option_parser.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import argparse

import os
import platform

separator = '/'
if platform.system() == 'Windows':
separator = '\\'

def get_parser():
parser = argparse.ArgumentParser()
parser.add_argument('--save_dir', type=str, default='./pretrained', help='directory for all savings')
parser.add_argument('--save_dir', type=str, default=os.getcwd()+separator+'pretrained', help='directory for all savings')
parser.add_argument('--cuda_device', type=str, default='cuda:0', help='cuda device number, eg:[cuda:0]')
parser.add_argument('--num_layers', type=int, default=2, help='number of layers')
parser.add_argument('--learning_rate', type=float, default=2e-4, help='learning rate')
Expand Down Expand Up @@ -69,4 +75,7 @@ def get_std_bvh(args=None, dataset=None):
def try_mkdir(path):
import os
if not os.path.exists(path):
os.system('mkdir -p {}'.format(path))
if platform.system() == 'Windows':
os.system('mkdir {}'.format(path))
else:
os.system('mkdir -p {}'.format(path))
2 changes: 1 addition & 1 deletion retargeting/pretrained/para.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
train_new.py --save_dir=./pretrained/ --num_layers=2 --rotation=quaterneion --downsampling=stride2 --batch_normalization=0 --upsampling=linear --activation=LeakyReLU --kernel_size=15 --base_channel_num=-1 --normalization=1 --skeleton_dist=2 --verbose=1 --learning_rate=2e-4 --skeleton_pool=mean --data_augment=1 --padding_mode=reflection --cuda_device=cuda:0 --batch_size=256 --debug=0 --skeleton_info=concat --patch_gan=1 --fk_world=0 --eval=0 --ee_loss=vec --ee_loss_fact=learn --pos_repr=3d --model=mul_top_mul_ske --ee_velo=1 --rec_loss_mode=extra_global_pos --simple_operator=0 --epoch_num=30000 --gan_mode=lsgan --lambda_ee=100
train_new.py --save_dir=D:\deeplearning\research_work\eb7\deep-motion-editing\retargeting\pretrained\ --num_layers=2 --rotation=quaterneion --downsampling=stride2 --batch_normalization=0 --upsampling=linear --activation=LeakyReLU --kernel_size=15 --base_channel_num=-1 --normalization=1 --skeleton_dist=2 --verbose=1 --learning_rate=2e-4 --skeleton_pool=mean --data_augment=1 --padding_mode=reflection --cuda_device=cuda:0 --batch_size=256 --debug=0 --skeleton_info=concat --patch_gan=1 --fk_world=0 --eval=0 --ee_loss=vec --ee_loss_fact=learn --pos_repr=3d --model=mul_top_mul_ske --ee_velo=1 --rec_loss_mode=extra_global_pos --simple_operator=0 --epoch_num=30000 --gan_mode=lsgan --lambda_ee=100
14 changes: 9 additions & 5 deletions retargeting/test.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import os
import platform
from os.path import join as pjoin
from get_error import full_batch
import numpy as np
from option_parser import try_mkdir
from eval import eval
import argparse

separator = '/'
if platform.system() == 'Windows':
separator = '\\'

def batch_copy(source_path, suffix, dest_path, dest_suffix=None):
try_mkdir(dest_path)
Expand All @@ -24,13 +28,13 @@ def batch_copy(source_path, suffix, dest_path, dest_suffix=None):
test_characters = ['Mousey_m', 'Goblin_m', 'Mremireh_m', 'Vampire_m']

parser = argparse.ArgumentParser()
parser.add_argument('--save_dir', type=str, default='./pretrained/')
parser.add_argument('--save_dir', type=str, default='.'+separator+'pretrained'+separator)
args = parser.parse_args()
prefix = args.save_dir

cross_dest_path = pjoin(prefix, 'results/cross_structure/')
intra_dest_path = pjoin(prefix, 'results/intra_structure/')
source_path = pjoin(prefix, 'results/bvh/')
cross_dest_path = pjoin(prefix, 'results'+separator+'cross_structure'+separator+'')
intra_dest_path = pjoin(prefix, 'results'+separator+'intra_structure'+separator+'')
source_path = pjoin(prefix, 'results'+separator+'bvh'+separator+'')

cross_error = []
intra_error = []
Expand Down Expand Up @@ -59,7 +63,7 @@ def batch_copy(source_path, suffix, dest_path, dest_suffix=None):
cross_error_mean = cross_error.mean()
intra_error_mean = intra_error.mean()

os.system('rm -r %s' % pjoin(prefix, 'results/bvh'))
os.system('rm -r %s' % pjoin(prefix, 'results'+separator+'bvh'))

print('Intra-retargeting error:', intra_error_mean)
print('Cross-retargeting error:', cross_error_mean)
Expand Down