train on template only with mask applied
This commit is contained in:
+69
-21
@@ -22,10 +22,10 @@ def m2uv_array(m2uv):
|
||||
def uv_to_mesh(uv):
|
||||
uv_res = 256
|
||||
# m2uv = np.load('/workspace/Code/featurelines/MeshUtils/m2uv.npy', allow_pickle=True).item()
|
||||
m2uv = np.load(r'D:\Work\Code\featurelines\MeshUtils\m2uv.npy', allow_pickle=True).item()
|
||||
m2uv = np.load('custom_utils\m2uv.npy', allow_pickle=True).item()
|
||||
m2uv = m2uv_array(m2uv)
|
||||
# uv_map = np.load('/workspace/Code/featurelines/Meshutils/stretched_uv_map_3.npy')
|
||||
uv_map = np.load(r'D:\Work\Code\featurelines\MeshUtils\stretched_uv_map_3.npy')
|
||||
uv_map = np.load('custom_utils\stretched_uv_map_3.npy')
|
||||
uv_map_discreet = np.floor(uv_map * uv_res).astype(np.int32)
|
||||
|
||||
mesh = np.zeros((14475, 3))
|
||||
@@ -36,36 +36,84 @@ def uv_to_mesh(uv):
|
||||
return mesh
|
||||
|
||||
|
||||
def plot(uv, mesh):
|
||||
fig = plt.figure(figsize=(15, 15))
|
||||
ax = fig.add_subplot(111, projection='3d')
|
||||
ax.set_xlim3d(-1, 1)
|
||||
ax.set_ylim3d(-1, 1)
|
||||
ax.set_zlim3d(-1, 1)
|
||||
ax.set_xlabel("X")
|
||||
ax.set_ylabel("Y")
|
||||
ax.set_zlabel("Z")
|
||||
ax.scatter(mesh[:, 0], mesh[:, 1], mesh[:, 2], s=5)
|
||||
# plt.show()
|
||||
def _maskFaces(V, F, mask):
|
||||
V_mask = mask
|
||||
F_mask = np.take(V_mask, F.reshape(-1), axis=0)
|
||||
F_mask = F_mask.reshape((-1, 3)).sum(axis=1) == 3
|
||||
|
||||
V_ind = np.zeros(V_mask.shape)
|
||||
V_ind[V_mask] = np.arange(V_mask.sum())
|
||||
F_new = np.take(V_ind, F[F_mask, :].reshape(-1), axis=0).reshape((-1, 3))
|
||||
V_new = V[V_mask, :]
|
||||
|
||||
return V_new, F_new
|
||||
|
||||
def maskFacesBatch(V, F, mask):
|
||||
Vs = []
|
||||
Fs = []
|
||||
for i in range(mask.shape[0]):
|
||||
v, f = _maskFaces(V[i], F, mask[i])
|
||||
Vs.append(v)
|
||||
Fs.append(f)
|
||||
return Vs, Fs
|
||||
|
||||
def plot(uv, mesh, faces, body, F, template, uv_gt, mesh_gt):
|
||||
# fig = plt.figure(figsize=(15, 15))
|
||||
# ax = fig.add_subplot(111, projection='3d')
|
||||
# ax.set_xlim3d(-1, 1)
|
||||
# ax.set_ylim3d(-1, 1)
|
||||
# ax.set_zlim3d(-1, 1)
|
||||
# ax.set_xlabel("X")
|
||||
# ax.set_ylabel("Y")
|
||||
# ax.set_zlabel("Z")
|
||||
# ax.scatter(mesh[:, 0], mesh[:, 1], mesh[:, 2], s=5)
|
||||
# # plt.show()
|
||||
|
||||
fig = plt.figure(figsize=(15, 15))
|
||||
ax = fig.add_subplot(111)
|
||||
ax.imshow(np.round( (uv - uv.min()) / (uv.max() - uv.min()) * 255).astype(np.int32))
|
||||
ax = fig.add_subplot(131)
|
||||
ax.imshow(np.round((uv + 1) * 128).astype(np.int32))
|
||||
ax = fig.add_subplot(132)
|
||||
ax.imshow(np.round((template + 1) * 128).astype(np.int32))
|
||||
ax = fig.add_subplot(133)
|
||||
ax.imshow(np.round((uv_gt + 1) * 128).astype(np.int32))
|
||||
plt.show()
|
||||
|
||||
F = np.load(r'D:\Work\Code\featurelines\FeatureLines\superSMPL\smpl_faces.npy')
|
||||
tm.Trimesh(mesh, F).show()
|
||||
collision = np.concatenate((body, mesh), axis=0)
|
||||
collision_faces = np.concatenate((F, faces + 14475), axis=0)
|
||||
collision_color = np.concatenate((np.ones_like(body, dtype=np.int32)*100, np.ones_like(mesh, dtype=np.int32)*230), axis=0)
|
||||
|
||||
|
||||
tm.Trimesh(mesh, faces).show()
|
||||
tm.Trimesh(mesh_gt, faces).show()
|
||||
# tm.Trimesh(collision, collision_faces, vertex_colors=collision_color).show()
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
file = sys.argv[1]
|
||||
|
||||
uv = np.load(file)
|
||||
uv = np.transpose(uv['uv'][0], [1,2,0])
|
||||
mesh = uv_to_mesh(uv)
|
||||
for i in range(50):
|
||||
file = r'Z:\Work\Huni\Barcelona\Output\stylegan\test-12-15000\\' + str(i) + '.npz'
|
||||
|
||||
plot(uv, mesh)
|
||||
F = np.load('custom_utils\smpl_faces.npy')
|
||||
data = np.load(file)
|
||||
uv = np.transpose(data['uv'], [1,2,0])
|
||||
uv_gt = np.transpose(data['gt'], [1,2,0])
|
||||
mask = data['mask'].astype(bool)
|
||||
template = np.transpose(data['template'], [1,2,0])
|
||||
|
||||
|
||||
mesh = uv_to_mesh(uv)
|
||||
mesh_gt = uv_to_mesh(uv_gt)
|
||||
|
||||
template_mesh = uv_to_mesh(template)
|
||||
filter = np.abs(np.sum(mesh, axis=-1)) < 1e-2
|
||||
overlap = np.sum((((np.sum(template_mesh, axis=-1) * mask) * (np.sum(mesh, axis=-1) * filter * mask))) > 0)
|
||||
|
||||
mesh, faces = _maskFaces(mesh, F, mask)
|
||||
plot(uv, mesh, faces, data['body'], F, template, uv_gt, mesh_gt[mask, :])
|
||||
|
||||
pass
|
||||
|
||||
pass
|
||||
|
||||
|
||||
Reference in New Issue
Block a user