backup
This commit is contained in:
@@ -144,9 +144,25 @@ def maskFacesBatch(V, F, mask):
|
||||
return Vs, Fs
|
||||
|
||||
|
||||
def plot_3d(mesh_gt, mesh_pred_unposed, faces, collision, collision_faces, collision_color):
|
||||
def flip_axis(x, ind=None):
|
||||
y = x.copy()
|
||||
if ind is not None:
|
||||
y[ind:,1] = x[ind:,2]
|
||||
y[ind:,2] = x[ind:,1]
|
||||
else:
|
||||
y[:,1] = x[:,2]
|
||||
y[:,2] = x[:,1]
|
||||
return y
|
||||
|
||||
|
||||
def plot_3d(mesh_gt, mesh_pred_unposed, faces, collision, collision_faces, collision_color, flip_xy=False):
|
||||
fig = make_subplots(rows=1, cols=3, start_cell="top-left", specs = [ [{ 'type': 'scene' } for _ in range(3)] ])
|
||||
|
||||
if flip_xy:
|
||||
mesh_gt = flip_axis(mesh_gt)
|
||||
mesh_pred_unposed = flip_axis(mesh_pred_unposed)
|
||||
collision = flip_axis(collision, ind=14475)
|
||||
|
||||
fig.add_trace(go.Mesh3d(
|
||||
# 8 vertices of a cube
|
||||
x=mesh_gt[:,0],
|
||||
@@ -200,8 +216,24 @@ def plot_3d(mesh_gt, mesh_pred_unposed, faces, collision, collision_faces, colli
|
||||
return fig
|
||||
|
||||
|
||||
def plot_3d_collision(collision_1, collision_2, collision_faces, collision_color):
|
||||
fig = make_subplots(rows=1, cols=2, start_cell="top-left", specs = [ [{ 'type': 'scene' } for _ in range(2)] ])
|
||||
def plot_3d_collision(gt, collision_1, collision_2, collision_faces, collision_color, flip_xy=False):
|
||||
fig = make_subplots(rows=1, cols=3, start_cell="top-left", specs = [ [{ 'type': 'scene' } for _ in range(3)] ])
|
||||
|
||||
if flip_xy:
|
||||
collision_1 = flip_axis(collision_1, ind=14475)
|
||||
collision_2 = flip_axis(collision_2, ind=14475)
|
||||
gt = flip_axis(gt, ind=14475)
|
||||
|
||||
fig.add_trace(go.Mesh3d(
|
||||
x=gt[:,0],
|
||||
y=gt[:,2],
|
||||
z=gt[:,1],
|
||||
i = collision_faces[:,0],
|
||||
j = collision_faces[:,1],
|
||||
k = collision_faces[:,2],
|
||||
vertexcolor=collision_color
|
||||
),
|
||||
row=1, col=1)
|
||||
|
||||
fig.add_trace(go.Mesh3d(
|
||||
x=collision_1[:,0],
|
||||
@@ -212,7 +244,7 @@ def plot_3d_collision(collision_1, collision_2, collision_faces, collision_color
|
||||
k = collision_faces[:,2],
|
||||
vertexcolor=collision_color
|
||||
),
|
||||
row=1, col=1)
|
||||
row=1, col=2)
|
||||
|
||||
fig.add_trace(go.Mesh3d(
|
||||
x=collision_2[:,0],
|
||||
@@ -223,17 +255,19 @@ def plot_3d_collision(collision_1, collision_2, collision_faces, collision_color
|
||||
k = collision_faces[:,2],
|
||||
vertexcolor=collision_color
|
||||
),
|
||||
row=1, col=2)
|
||||
row=1, col=3)
|
||||
|
||||
|
||||
fig.update_layout(scene_aspectmode='manual', scene_aspectratio=dict(x=1, y=1, z=1),
|
||||
scene2_aspectmode='manual', scene2_aspectratio=dict(x=1, y=1, z=1),
|
||||
scene3_aspectmode='manual', scene3_aspectratio=dict(x=1, y=1, z=1),
|
||||
)
|
||||
helper = dict(xaxis = dict(nticks=4, range=[-1,1],),
|
||||
yaxis = dict(nticks=4, range=[-1,1],),
|
||||
zaxis = dict(nticks=4, range=[-1,1],),)
|
||||
fig.update_layout(scene = helper,
|
||||
scene2 = helper,
|
||||
scene3 = helper,
|
||||
)
|
||||
|
||||
return fig
|
||||
@@ -258,7 +292,7 @@ def sparse_to_tensor(L):
|
||||
return tf.SparseTensor(idx, data, shape)
|
||||
|
||||
|
||||
def load_model(model, checkpoint, disable_assert=False, assert_consumed_on=False):
|
||||
def load_model(model, checkpoint, disable_assert=False, assert_consumed_on=False, iteration=''):
|
||||
ckpt = tf.train.Checkpoint(model=model)
|
||||
manager = tf.train.CheckpointManager(ckpt, checkpoint, max_to_keep=1)
|
||||
if not disable_assert:
|
||||
@@ -267,7 +301,12 @@ def load_model(model, checkpoint, disable_assert=False, assert_consumed_on=False
|
||||
if assert_consumed_on:
|
||||
ckpt.restore(manager.latest_checkpoint).assert_consumed()
|
||||
else:
|
||||
ckpt.restore(manager.latest_checkpoint).assert_existing_objects_matched()#.assert_consumed()
|
||||
if iteration != '':
|
||||
name_base = manager.latest_checkpoint.split('-')[0]
|
||||
ckpt_ind = [i for i in range(len(manager.checkpoints)) if manager.checkpoints[i].endswith(name_base + '-' + iteration)][0]
|
||||
ckpt.restore(manager.checkpoints[ckpt_ind]).assert_existing_objects_matched()#.assert_consumed()
|
||||
else:
|
||||
ckpt.restore(manager.latest_checkpoint).assert_existing_objects_matched()#.assert_consumed()
|
||||
|
||||
|
||||
def get_summary_str(model):
|
||||
@@ -350,4 +389,17 @@ def replace_arrays(string):
|
||||
|
||||
out += string[i+1:]
|
||||
|
||||
return out
|
||||
return out
|
||||
|
||||
|
||||
def group_inputs_for_levels(batch, config):
|
||||
levels_input = []
|
||||
for res in config['pyramid']['resolutions']:
|
||||
res_modifier = '_' + str(res) if res != 512 else ''
|
||||
if config['use_skinning']:
|
||||
uv_orig = batch['uv_unposed' + res_modifier]
|
||||
else:
|
||||
uv_orig = batch['uv_posed' + res_modifier]
|
||||
levels_input.append([uv_orig, batch['uv_static' + res_modifier], batch['uv_body_posed' + res_modifier], batch['uv_curvature' + res_modifier], batch['uv_mask' + res_modifier], batch['uv_mask']])
|
||||
conds = [batch['uv_static'], batch['uv_body_posed'], batch['uv_curvature']]
|
||||
return levels_input, conds
|
||||
+19
-2
@@ -34,12 +34,14 @@ eval_joints = {
|
||||
|
||||
class SMPL:
|
||||
|
||||
def __init__(self, orig_smpl=False, use_one_hot=False):
|
||||
def __init__(self, orig_smpl=False, use_one_hot=False, is_skirt=False):
|
||||
self.J_regressor = []
|
||||
self.v_template = []
|
||||
self.shapedirs = []
|
||||
self.posedirs = []
|
||||
self.weights = []
|
||||
self.use_one_hot = use_one_hot
|
||||
self.is_skirt = is_skirt
|
||||
# Load SMPL models
|
||||
# path = os.path.abspath(os.path.dirname(__file__))
|
||||
with open(os.path.join('custom_utils/super_model_f.pkl'), 'rb') as f:
|
||||
@@ -299,7 +301,22 @@ class SMPL:
|
||||
|
||||
def run_garment(self, pose, betas, v_cloth, v_shaped=None):
|
||||
J = self.get_joints_template(betas, v_shaped)
|
||||
R = self.run_rodrigues(pose)
|
||||
|
||||
if self.use_one_hot and self.is_skirt:
|
||||
# p_avg = (pose[:, 3:6] + pose[:, 6:9]) / 2
|
||||
# pose_dress = tf.concat([pose[:, :3], p_avg, p_avg, pose[:, 9:]], axis=-1)
|
||||
# R = self.run_rodrigues(pose_dress).numpy()
|
||||
# for b in range(betas.shape[0]):
|
||||
# R[b][[4,5,7,8,10,11],:,:] = np.eye(3)
|
||||
|
||||
pose_dress = pose
|
||||
# p_avg = (pose_dress[:, 3:6] + pose_dress[:, 6:9]) / 2
|
||||
# pose_dress[:,3:9] = np.concatenate([p_avg, p_avg], axis=-1)
|
||||
R = self.run_rodrigues(pose_dress).numpy()
|
||||
for b in range(betas.shape[0]):
|
||||
R[b][[4,5,7,8,10,11],:,:] = np.eye(3)
|
||||
else:
|
||||
R = self.run_rodrigues(pose)
|
||||
|
||||
# if filter is not None:
|
||||
# weights = tf.boolean_mask(self.weights, filter)
|
||||
|
||||
Reference in New Issue
Block a user