Skip to content

Commit

Permalink
black formating
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin de La Gorce committed Dec 15, 2020
1 parent a9495ba commit d5835bd
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 10 deletions.
2 changes: 1 addition & 1 deletion deodr/examples/mesh_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def mesh_viewer(
scene.sigma = 0.0

if key == ord("s"):
filename = os.path.abspath("scene.pickle")
filename = os.path.abspath("scene.pickle")
# save scene and camera in pickle file
with open(filename, "wb") as file:
# dump information to the file
Expand Down
8 changes: 7 additions & 1 deletion deodr/examples/rgb_multiview_hand.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@
import numpy as np


def run(dl_library="pytorch", plot_curves=False, save_images=False, display=True, max_iter=400):
def run(
dl_library="pytorch",
plot_curves=False,
save_images=False,
display=True,
max_iter=400,
):

file_folder = os.path.dirname(__file__)
hand_images = [
Expand Down
31 changes: 24 additions & 7 deletions deodr/mesh_fitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@
import scipy.spatial.transform.rotation

from . import Camera, ColoredTriMesh, LaplacianRigidEnergy, Scene3D, TriMesh
from .tools import normalize, normalize_backward, qrot, qrot_backward, check_jacabian_finite_difference
from .tools import (
normalize,
normalize_backward,
qrot,
qrot_backward,
check_jacabian_finite_difference,
)


class MeshDepthFitter:
Expand Down Expand Up @@ -594,7 +600,7 @@ def energy_data(self, vertices, return_images=True):
return energy_data

def step(self, check_gradient=False):

self.vertices = self.vertices - np.mean(self.vertices, axis=0)[None, :]

self.nb_facesrames = len(self.hand_images)
Expand All @@ -607,20 +613,31 @@ def step(self, check_gradient=False):
) = self.rigid_energy.evaluate(self.vertices)

if check_gradient:

def func(x):
return self.rigid_energy.evaluate(x, return_grad=False, return_hessian=False)
check_jacabian_finite_difference(grad_rigidity.flatten(), func, self.vertices)
return self.rigid_energy.evaluate(
x, return_grad=False, return_hessian=False
)

check_jacabian_finite_difference(
grad_rigidity.flatten(), func, self.vertices
)

def func(x):
return self.energy_data(x, return_images=False)

grad_data = self.vertices_b.copy()
check_jacabian_finite_difference(grad_data.flatten(), func, self.vertices)

energy = energy_data + energy_rigid
print(f"iter {self.iter} Energy={energy} : EData={energy_data} E_rigid={energy_rigid}")
print(
f"iter {self.iter} Energy={energy} : EData={energy_data} E_rigid={energy_rigid}"
)

if self.iter < 500:
self.vertices_b = self.vertices_b - np.mean(self.vertices_b, axis=0)[None, :]
self.vertices_b = (
self.vertices_b - np.mean(self.vertices_b, axis=0)[None, :]
)
# update v
grad = self.vertices_b + grad_rigidity

Expand All @@ -639,7 +656,7 @@ def mult_and_clamp(x, a, t):
)
self.vertices = self.vertices + self.speed_vertices
# update rotation

step_quaternion = mult_and_clamp(
-self.transform_quaternion_b,
self.step_factor_quaternion,
Expand Down
5 changes: 4 additions & 1 deletion deodr/triangulated_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@ def __init__(self, faces, vertices=None, clockwise=False, compute_adjacencies=Tr
self.compute_adjacencies()

def compute_adjacencies(self):
self.adjacencies = TriMeshAdjacencies(self.faces, self.clockwise, nb_vertices=self.nb_vertices)
self.adjacencies = TriMeshAdjacencies(
self.faces, self.clockwise, nb_vertices=self.nb_vertices
)

if self.vertices is not None:

Expand Down Expand Up @@ -418,5 +420,6 @@ def to_trimesh(self):
@staticmethod
def load(filename):
import trimesh

mesh_trimesh = trimesh.load(filename)
return ColoredTriMesh.from_trimesh(mesh_trimesh)

0 comments on commit d5835bd

Please sign in to comment.