コード例 #1
0
def check_cam_coherence(path):
    """Check the coherence of a camera path."""
    cam_gt = path + 'cam0_gt.visim'
    cam_render = path + 'cam0.render'
    lines = tf.string_split([tf.read_file(cam_render)], '\n').values
    lines = lines[3:]
    lines = tf.strided_slice(lines, [0], [lines.shape_as_list()[0]], [2])
    fields = tf.reshape(tf.string_split(lines, ' ').values, [-1, 10])
    timestamp_from_render, numbers = tf.split(fields, [1, 9], -1)
    numbers = tf.strings.to_number(numbers)
    eye, lookat, up = tf.split(numbers, [3, 3, 3], -1)
    up_vector = tf.nn.l2_normalize(up - eye)
    lookat_vector = tf.nn.l2_normalize(lookat - eye)
    rotation_from_lookat = lookat_matrix(up_vector, lookat_vector)

    lines = tf.string_split([tf.read_file(cam_gt)], '\n').values
    lines = lines[1:]
    fields = tf.reshape(tf.string_split(lines, ',').values, [-1, 8])
    timestamp_from_gt, numbers = tf.split(fields, [1, 7], -1)
    numbers = tf.strings.to_number(numbers)
    position, quaternion = tf.split(numbers, [3, 4], -1)
    rotation_from_quaternion = from_quaternion(quaternion)

    assert tf.reduce_all(tf.equal(timestamp_from_render, timestamp_from_gt))
    assert tf.reduce_all(tf.equal(eye, position))
    so3_diff = (tf.trace(
        tf.matmul(rotation_from_lookat,
                  rotation_from_quaternion,
                  transpose_a=True)) - 1) / 2
    tf.assert_near(so3_diff, tf.ones_like(so3_diff))
コード例 #2
0
 def assert_ops():
     """Creates a list of assert operations."""
     if not self._validate_args:
         return []
     assert_ops = []
     if previous_solver_internal_state is not None:
         assert_initial_state_matches_previous_solver_internal_state = (
             tf1.assert_near(
                 tf.norm(
                     initial_state_vec - previous_solver_internal_state.
                     backward_differences[0], np.inf),
                 0.,
                 message=
                 '`previous_solver_internal_state` does not match '
                 '`initial_state`.'))
         assert_ops.append(
             assert_initial_state_matches_previous_solver_internal_state
         )
     if solution_times_chosen_by_solver:
         assert_ops.append(
             util.assert_positive(final_time - initial_time,
                                  'final_time - initial_time'))
     else:
         assert_ops += [
             util.assert_increasing(solution_times, 'solution_times'),
             util.assert_nonnegative(
                 solution_times[0] - initial_time,
                 'solution_times[0] - initial_time'),
         ]
     if max_num_steps is not None:
         assert_ops.append(
             util.assert_positive(max_num_steps, 'max_num_steps'))
     if max_num_newton_iters is not None:
         assert_ops.append(
             util.assert_positive(max_num_newton_iters,
                                  'max_num_newton_iters'))
     assert_ops += [
         util.assert_positive(rtol, 'rtol'),
         util.assert_positive(atol, 'atol'),
         util.assert_positive(first_step_size, 'first_step_size'),
         util.assert_positive(safety_factor, 'safety_factor'),
         util.assert_positive(min_step_size_factor,
                              'min_step_size_factor'),
         util.assert_positive(max_step_size_factor,
                              'max_step_size_factor'),
         tf.Assert((max_order >= 1) & (max_order <= bdf_util.MAX_ORDER),
                   [
                       '`max_order` must be between 1 and {}.'.format(
                           bdf_util.MAX_ORDER)
                   ]),
         util.assert_positive(newton_tol_factor, 'newton_tol_factor'),
         util.assert_positive(newton_step_size_factor,
                              'newton_step_size_factor'),
     ]
     return assert_ops