Пример #1
0
    def testCalibrationLayerRegularization(self):
        with ops.Graph().as_default():
            # Shape: [batch_size=2, 3, 2]
            uncalibrated = array_ops.constant([
                [[0.1, 0.2], [0.9, 0.8], [0.4, 0.6]],
                [[0.2, 0.3], [1.0, 0.9], [0.5, 0.7]],
            ])
            kp_init_0 = self._UniformKeypoints(10)
            kp_init_1 = self._UniformKeypoints(5, 0, 1000)
            num_keypoints = [10, 10, 10, 10, 5, 5]
            kp_init = [
                kp_init_0, kp_init_0, kp_init_0, kp_init_0, kp_init_1,
                kp_init_1
            ]
            _, _, regularization = (pwl_calibration_layers.calibration_layer(
                uncalibrated,
                num_keypoints,
                keypoints_initializers=kp_init,
                l1_reg=0.1,
                l2_reg=1.0,
                l1_laplacian_reg=[0.3, 0.1, 0.2, 0.3, 0.4, 0.5],
                l2_laplacian_reg=[None, 1.0, None, None, None, None],
                name='test'))

            with self.test_session() as sess:
                sess.run(variables.global_variables_initializer())
                got = sess.run(regularization)
                expected_value = 6294341.5
                self.assertAlmostEqual(got, expected_value, delta=1e-1)
Пример #2
0
 def testCalibrationLayerWithUnknownBatchSize(self):
     with ops.Graph().as_default():
         # Shape: [batch_size=2, 3, 2]
         uncalibrated = array_ops.placeholder(dtypes.float32,
                                              shape=[None, 3, 2])
         kp_init_0 = self._UniformKeypoints(10)
         kp_init_1 = self._UniformKeypoints(5, 0, 1000)
         num_keypoints = [10, 10, 10, 10, 5, 5]
         kp_init = [
             kp_init_0, kp_init_0, kp_init_0, kp_init_0, kp_init_1,
             kp_init_1
         ]
         calibrated, projection_ops, regularization = (
             pwl_calibration_layers.calibration_layer(
                 uncalibrated,
                 num_keypoints,
                 keypoints_initializers=kp_init,
                 name='test'))
         self.assertEqual(projection_ops, [])
         self.assertEqual(regularization, None)
         got = keypoints_initialization._materialize_locally(
             calibrated,
             num_steps=1,
             feed_dict={
                 uncalibrated: [
                     [[0.1, 0.2], [0.9, 0.8], [0.4, 0.6]],
                     [[0.2, 0.3], [1.0, 0.9], [0.5, 0.7]],
                 ]
             })
         want = [
             [[210., 220.], [290., 280.], [400., 600.]],
             [[220., 230.], [300., 290.], [500., 700.]],
         ]
         self.assertAllClose(got, want)
 def testCalibrationLayer(self):
     with tf.Graph().as_default():
         # Shape: [batch_size=2, 3, 2]
         uncalibrated = tf.constant([
             [[0.1, 0.2], [0.9, 0.8], [0.4, 0.6]],
             [[0.2, 0.3], [1.0, 0.9], [0.5, 0.7]],
         ])
         kp_init_0 = self._UniformKeypoints(10)
         kp_init_1 = self._UniformKeypoints(5, 0, 1000)
         num_keypoints = [10, 10, 10, 10, 5, 5]
         kp_init = [
             kp_init_0, kp_init_0, kp_init_0, kp_init_0, kp_init_1,
             kp_init_1
         ]
         calibrated, projection_ops, regularization = (
             pwl_calibration_layers.calibration_layer(
                 uncalibrated,
                 num_keypoints,
                 keypoints_initializers=kp_init,
                 name='test'))
         self.assertEqual(projection_ops, [])
         self.assertEqual(regularization, None)
         got = keypoints_initialization._materialize_locally(calibrated,
                                                             num_steps=1)
         want = [
             [[210., 220.], [290., 280.], [400., 600.]],
             [[220., 230.], [300., 290.], [500., 700.]],
         ]
         self.assertAllClose(got, want)
Пример #4
0
def _calibration_layer(input_tensor, input_dim, input_min, input_max,
                       num_keypoints, output_min, output_max):
    """Create an intermediate calibration layer."""
    init_keypoints = keypoints_initialization.uniform_keypoints_for_signal(
        num_keypoints=num_keypoints,
        input_min=input_min,
        input_max=input_max,
        output_min=output_min,
        output_max=output_max,
        dtype=input_tensor.dtype)
    packed_results = pwl_calibration_layers.calibration_layer(
        input_tensor,
        num_keypoints=num_keypoints,
        keypoints_initializers=[init_keypoints] * input_dim,
        bound=True,
        monotonic=+1)
    (calibrated_input_tensor, projection_ops, _) = packed_results
    return (calibrated_input_tensor, projection_ops)