commit all
This commit is contained in:
+25
-8
@@ -1,5 +1,6 @@
|
||||
import os
|
||||
from configs.config_abl_pyr_64_128_256_cape_f import config
|
||||
from configs.config_abl_2_pyr_64_128_256_512_cape_m import config
|
||||
|
||||
os.environ["CUDA_VISIBLE_DEVICES"] = config['gpu']
|
||||
import tensorflow as tf
|
||||
|
||||
@@ -323,29 +324,42 @@ def plot_everything(batch: dict, type: str):
|
||||
|
||||
|
||||
def test():
|
||||
load_model(model, 'checkpoints/' + config['name'])
|
||||
load_model(model, 'checkpoints/' + config['name']) # , iteration='60000'
|
||||
clothing_verts_idx = np.load(os.path.join('CAPE', 'data', 'clothing_verts_idx.npy'))
|
||||
cape_mask = np.zeros((6890), bool)
|
||||
cape_mask[clothing_verts_idx] = True
|
||||
|
||||
dataset_test = factory.get_dataset(folder=config['test_dir'], batch_size=config['batch_size'], signature=config['signature_dynamic'], resolutions=dataset_resolutions, in_memory=False, do_repeat=False, is_cape=config['is_cape'])
|
||||
|
||||
dataset_test = factory.get_dataset(folder=config['test_dir'], batch_size=config['batch_size'], signature=config['signature_dynamic'], resolutions=dataset_resolutions, in_memory=False, do_repeat=False, is_cape=config['is_cape'], shuffle=False)
|
||||
static_dataset_test = StaticDataset(folder=config['test_dir'], signature=config['signature_static'], resolutions=dataset_resolutions, in_memory=True, is_cape=config['is_cape'])
|
||||
|
||||
step = 0
|
||||
losses = []
|
||||
lines = []
|
||||
|
||||
|
||||
all_errors = []
|
||||
|
||||
for batch in tqdm.tqdm(dataset_test):
|
||||
batch = static_dataset_test.expand_batch(batch_to_dict(batch, config['signature_dynamic']))
|
||||
|
||||
_, out_levels = test_step(batch)
|
||||
all_errors = []
|
||||
if step == 0:
|
||||
_, out_levels = test_step(batch)
|
||||
# load_model(model, 'checkpoints/' + config['name']) # , iteration='60000'
|
||||
# _, out_levels = test_step(batch)
|
||||
else:
|
||||
_, out_levels = test_step(batch)
|
||||
|
||||
|
||||
errors = []
|
||||
for i, id in enumerate(batch['id']):
|
||||
id_str = id.numpy().decode("utf-8")
|
||||
frame_nr_str = batch['frame_nr'][i].numpy().decode("utf-8")
|
||||
pred = uv2mesh(out_levels[-1][0])
|
||||
min_body = np.load(os.path.join('/home/workspace/data/dataset/cape/cape_release', 'minimal_body_shape', id_str.split('_')[0], id_str.split('_')[0] + '_minimal.npy'))[np.newaxis, :, :].astype(np.float32)
|
||||
offsets_pred = pred[i] - min_body[0,smpl.to_keep,:]
|
||||
offsets_orig = batch['mesh_unposed'][i] - min_body[0,smpl.to_keep,:]
|
||||
offsets_pred = pred[i].numpy()[cape_mask[smpl.to_keep],:] - min_body[0,clothing_verts_idx,:]
|
||||
offsets_orig = batch['mesh_unposed'][i].numpy()[cape_mask[smpl.to_keep],:] - min_body[0,clothing_verts_idx,:]
|
||||
error = tf.reduce_mean(tf.math.sqrt(tf.reduce_sum((offsets_orig - offsets_pred) ** 2, axis=-1)))
|
||||
lines.append(id_str + '_' + frame_nr_str + ' ' + str(error.numpy()))
|
||||
errors.append(error)
|
||||
|
||||
# test_loss = { **{ 'test/error': tf.reduce_mean(errors) }, **test_loss }
|
||||
@@ -364,6 +378,9 @@ def test():
|
||||
# averages = dict()
|
||||
path_to_plotly_html = "temp/plotly_figure.html"
|
||||
|
||||
with open('temp/error_' + config['name'] + '.txt', 'w') as f:
|
||||
f.writelines('\n'.join(lines))
|
||||
|
||||
errors = np.asarray(all_errors)
|
||||
print('mean: ' + str(errors.mean()))
|
||||
print('min: ' + str(errors.min()))
|
||||
|
||||
Reference in New Issue
Block a user