This commit is contained in:
2023-03-06 09:55:48 +00:00
parent dfdf8d408e
commit 0b518e7f0e
46 changed files with 3392 additions and 160 deletions
+71 -5
View File
@@ -11,10 +11,11 @@ import tensorflow as tf
import cmapy as cm
import plotly.graph_objects as go
import plotly.express as ex
import scipy.io as sio
from plotly.subplots import make_subplots
from dataset import DatasetFactory, StaticDataset
from custom_utils.custom_utils import batch_to_dict, UV2Mesh, _maskFaces, load_model
from custom_utils.custom_utils import batch_to_dict, UV2Mesh, _maskFaces, load_model, save_stl
from custom_utils.smpl import SMPL
from convert_to_uv_api import convert_to_uv_api
from models.upscaler import UpscalerBasicConv as Upscaler
@@ -121,6 +122,69 @@ def uv_mapping_example(mesh, faces, colors, mask):
print()
def faces2graph(F, v=None):
if v: v = set(v) # Only this verts
G = {}
for f in F:
for i in f:
if v and i not in v: continue
if not i in G:
G[i] = {}
for j in f:
if v and j not in v: continue
if i == j: continue
G[i][j] = 1
return G
SMOOTH_IT = 100
SMOOTH_EXHAUST_IT = 100
def smooth(M, F, segm):
f_skirt = []
for f in F:
f_skirt.append(f[0])
G = faces2graph(f_skirt)
# Segmentation for skirt smoothing
# Laplacian smoothing
for _ in range(SMOOTH_EXHAUST_IT):
for v in segm['exhaustive'].reshape(-1):
M[v] = M[list(G[v].keys())].mean(0)
for _ in range(SMOOTH_IT):
# aux = M.copy()
# FRONT
for v in segm['front'].reshape(-1):
M[v] = M[list(G[v].keys())].mean(0)
for v in segm['frontBoundary'].reshape(-1):
M[v,:2] = M[list(G[v].keys()),:2].mean(0) # No z-smoothing
# BACK
for v in segm['back'].reshape(-1):
M[v] = M[list(G[v].keys())].mean(0)
for v in segm['backBoundary'].reshape(-1):
M[v,:2] = M[list(G[v].keys()),:2].mean(0) # No z-smoothing
# M = aux.copy()
return M
def uv_mapping_example_skirt(mesh, faces, colors, mask):
segm = sio.loadmat('custom_utils/vg_skirt_smoothing')
F = sio.loadmat("custom_utils/faces_skirt.mat")['F'][0]
faces = np.load('custom_utils/smpl_faces_skirt.npy')
mesh = smooth(mesh, F, segm)
fig = plot_fixed(mesh, faces, colors)
fig.write_image('examples/' + type + '_' + id_str + '_' + frame_nr + '_body.png')
# stop inbetween
uv = convert_to_uv_api(mesh, mask, is_skirt=True)
plot = custom_imshow((uv+1)/2)
# plot = custom_imshow(result)
# plot.write_image('examples/' + type + '_' + id_str + '_' + frame_nr + '_uv_body_pre.png')
plot.write_image('examples/' + type + '_' + id_str + '_' + frame_nr + '_uv_body_inpainted.png')
print()
def curvature_example(mesh_curvature, uv_curvature, posed, faces, mask):
colors = np.array([cm.color('jet', 1 - i) for i in np.linspace(0, 1, mesh_curvature.max()+1)]) / 255.0
color_mesh = np.zeros((mesh_curvature.shape[0], 3), np.float32)
@@ -172,7 +236,7 @@ def plot_upscaling(uv_low, uv_high, uv_mask_low, uv_mask_high, faces, color, mas
print()
if __name__ == '__main__':
if __name__ == '__main__':
uv2mesh = UV2Mesh()
smpl = SMPL()
@@ -209,8 +273,9 @@ def plot_upscaling(uv_low, uv_high, uv_mask_low, uv_mask_high, faces, color, mas
do_repeat=False,
resolutions=[512, 32],
# frames_file='/home/workspace/data/dataset/test_ready/frames_pose_cluster_20_sample_10.txt',
# frames_file='/home/workspace/data/dataset/test_ready/frames_00438_146.txt',
frames_file='/home/workspace/data/dataset/test_ready/frames_00228_137.txt',
frames_file='/home/workspace/data/dataset/test_ready/frames_00438_146.txt',
# frames_file='/home/workspace/data/dataset/test_ready/frames_00228_137.txt',
# frames_file='/home/workspace/data/dataset/test_ready/frames_02572_1.txt',
)
static_dataset = StaticDataset(folder='/home/workspace/data/dataset/test_ready',
resolutions=[512, 32],
@@ -302,7 +367,8 @@ def plot_upscaling(uv_low, uv_high, uv_mask_low, uv_mask_high, faces, color, mas
# fig.write_image('examples/' + type + '_' + id_str + '_' + frame_nr + '_unposed_shaped.svg')
# uv_mapping_example(body, F, colors[:14475, :], np.ones((14475), bool))
uv_mapping_example_skirt(body, F, colors[:14475, :], np.ones((14475), bool))
# curvature_example(batch['mesh_curvature'][0].numpy(), uv_curvature, posed, faces_garment, mask)
plot_upscaling(batch['uv_unposed_32'].numpy()[0], batch['uv_unposed'].numpy()[0], batch['uv_mask_32'].numpy()[0], batch['uv_mask'].numpy()[0], faces_garment, colors_garment, mask)
# plot_upscaling(batch['uv_unposed_32'].numpy()[0], batch['uv_unposed'].numpy()[0], batch['uv_mask_32'].numpy()[0], batch['uv_mask'].numpy()[0], faces_garment, colors_garment, mask)
print()