Example #1
0
def run():
  """Runs training steps with a mesh summary."""
  # Mesh summaries only work on TensorFlow 2.x.
  if int(tf.__version__.split('.')[0]) < 1:
    raise ImportError('TensorFlow 2.x is required to run this demo.')
  # Flag mesh_path is required.
  if FLAGS.mesh_path is None:
    raise ValueError(
      'Flag --mesh_path is required and must contain path to PLY file.')
  # Camera and scene configuration.
  config_dict = {
      'camera': {'cls': 'PerspectiveCamera', 'fov': 75}
  }

  # Read sample PLY file.
  vertices, colors, faces = demo_utils.read_ascii_ply(FLAGS.mesh_path)

  # Add batch dimension.
  vertices = np.expand_dims(vertices, 0)
  faces = np.expand_dims(faces, 0)
  colors = np.expand_dims(colors, 0)

  # Create summary writer.
  writer = tf.summary.create_file_writer(FLAGS.logdir)

  with writer.as_default():
    for step in range(_MAX_STEPS):
      train_step(vertices, faces, colors, config_dict, step)
Example #2
0
 def test_read_ascii_ply(self):
     """Tests end-to-end PLY file reading and parsing."""
     test_ply = os.path.join(os.path.dirname(os.environ['TEST_BINARY']),
                             'test_data', 'icosphere.ply')
     vertices, colors, faces = demo_utils.read_ascii_ply(test_ply)
     self.assertEqual(len(vertices), 82)
     self.assertEqual(len(vertices), len(colors))
     self.assertEqual(len(faces), 80)
Example #3
0
def run():
    """Runs session with a mesh summary."""
    # Mesh summaries only work on TensorFlow 1.x.
    if int(tf.__version__.split(".")[0]) > 1:
        raise ImportError("TensorFlow 1.x is required to run this demo.")
    # Flag mesh_path is required.
    if FLAGS.mesh_path is None:
        raise ValueError(
            "Flag --mesh_path is required and must contain path to PLY file."
        )
    # Camera and scene configuration.
    config_dict = {"camera": {"cls": "PerspectiveCamera", "fov": 75}}

    # Read sample PLY file.
    vertices, colors, faces = demo_utils.read_ascii_ply(FLAGS.mesh_path)

    # Add batch dimension.
    vertices = np.expand_dims(vertices, 0)
    faces = np.expand_dims(faces, 0)
    colors = np.expand_dims(colors, 0)

    # Create placeholders for tensors representing the mesh.
    step = tf.placeholder(tf.int32, ())
    vertices_tensor = tf.placeholder(tf.float32, vertices.shape)
    faces_tensor = tf.placeholder(tf.int32, faces.shape)
    colors_tensor = tf.placeholder(tf.int32, colors.shape)

    # Change colors over time.
    t = tf.cast(step, tf.float32) / _MAX_STEPS
    transformed_colors = t * (255 - colors) + (1 - t) * colors

    meshes_summary = mesh_summary.op(
        "mesh_color_tensor",
        vertices=vertices_tensor,
        faces=faces_tensor,
        colors=transformed_colors,
        config_dict=config_dict,
    )

    # Create summary writer and session.
    writer = tf.summary.FileWriter(FLAGS.logdir)
    sess = tf.Session()

    for i in range(_MAX_STEPS):
        summary = sess.run(
            meshes_summary,
            feed_dict={
                vertices_tensor: vertices,
                faces_tensor: faces,
                colors_tensor: colors,
                step: i,
            },
        )
        writer.add_summary(summary, global_step=i)
Example #4
0
def run():
    """Runs training steps with a mesh summary."""
    # Camera and scene configuration.
    config_dict = {"camera": {"cls": "PerspectiveCamera", "fov": 75}}

    # Read sample PLY file.
    vertices, colors, faces = demo_utils.read_ascii_ply(DEMO_PLY_MESH_PATH)

    # Add batch dimension.
    vertices = np.expand_dims(vertices, 0)
    faces = np.expand_dims(faces, 0)
    colors = np.expand_dims(colors, 0)

    # Create summary writer.
    writer = tf.summary.create_file_writer(FLAGS.logdir)

    with writer.as_default():
        for step in range(_MAX_STEPS):
            train_step(vertices, faces, colors, config_dict, step)