Skip to content

Commit

Permalink
Migrate several files to TensorFlow 2 and Python 3.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 380159321
  • Loading branch information
tensorflower-gardener authored and Copybara-Service committed Jun 18, 2021
1 parent f4f04cb commit 4021d25
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def energy(vertices_rest_pose,
edge_weight=None,
conformal_energy=True,
aggregate_loss=True,
name=None):
name="as_conformal_as_possible_energy"):
"""Estimates an As Conformal As Possible (ACAP) fitting energy.
For a given mesh in rest pose, this function evaluates a variant of the ACAP
Expand Down Expand Up @@ -92,10 +92,7 @@ def energy(vertices_rest_pose,
ValueError: if the shape of `vertices_rest_pose`, `vertices_deformed_pose`,
`quaternions`, `edges`, `vertex_weight`, or `edge_weight` is not supported.
"""
with tf.compat.v1.name_scope(name, "as_conformal_as_possible_energy", [
vertices_rest_pose, vertices_deformed_pose, quaternions, edges,
conformal_energy, vertex_weight, edge_weight
]):
with tf.name_scope(name):
vertices_rest_pose = tf.convert_to_tensor(value=vertices_rest_pose)
vertices_deformed_pose = tf.convert_to_tensor(value=vertices_deformed_pose)
quaternions = tf.convert_to_tensor(value=quaternions)
Expand Down Expand Up @@ -126,12 +123,12 @@ def energy(vertices_rest_pose,
broadcast_compatible=False)
shape.check_static(
tensor=edges, tensor_name="edges", has_rank=2, has_dim_equals=(-1, 2))
tensors_with_vertices = [vertices_rest_pose,
vertices_deformed_pose,
quaternions]
names_with_vertices = ["vertices_rest_pose",
"vertices_deformed_pose",
"quaternions"]
tensors_with_vertices = [
vertices_rest_pose, vertices_deformed_pose, quaternions
]
names_with_vertices = [
"vertices_rest_pose", "vertices_deformed_pose", "quaternions"
]
axes_with_vertices = [-2, -2, -2]
if vertex_weight is not None:
shape.check_static(
Expand Down Expand Up @@ -197,5 +194,6 @@ def energy(vertices_rest_pose,
return (average_energy_ij + average_energy_ji) / 2.0
return tf.concat((energy_ij_squared, energy_ji_squared), axis=-1)


# API contains all public functions and classes.
__all__ = export_api.get_functions_and_classes()
10 changes: 4 additions & 6 deletions tensorflow_graphics/rendering/triangle_rasterizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@


def _dim_value(dim):
return 1 if dim is None else tf.compat.v1.dimension_value(dim)
return 1 if dim is None else tf.compat.dimension_value(dim)


def _merge_batch_dims(tensor, last_axis):
Expand All @@ -50,7 +50,7 @@ def rasterize(vertices,
image_size,
enable_cull_face=True,
backend=rasterization_backend.RasterizationBackends.OPENGL,
name=None):
name="triangle_rasterizer_rasterize"):
"""Rasterizes the scene.
Note:
Expand All @@ -73,7 +73,7 @@ def rasterize(vertices,
False.
backend: A rasterization_backend.RasterizationBackends enum containing the
backend method to use for rasterization.
name: A name for this op. Defaults to 'triangle_rasterizer_rasterize'.
name: A name for this op. Defaults to "triangle_rasterizer_rasterize".
Returns:
A dictionary. The key "mask" is of shape `[A1, ..., An, height, width, 1]`
Expand All @@ -83,9 +83,7 @@ def rasterize(vertices,
the dictionary contains perspective correct interpolated attributes of shape
`[A1, ..., An, height, width, K]` per entry in the `attributes` dictionary.
"""
with tf.compat.v1.name_scope(
name, "triangle_rasterizer_rasterize",
(vertices, triangles, attributes, view_projection_matrix)):
with tf.name_scope(name):
vertices = tf.convert_to_tensor(value=vertices)
triangles = tf.convert_to_tensor(value=triangles)
view_projection_matrix = tf.convert_to_tensor(value=view_projection_matrix)
Expand Down

0 comments on commit 4021d25

Please sign in to comment.