Пример #1
0
    def testCreatePhasesWithControlFlowOpsNotWrappedInApplyFunction(self):
        int_placeholder = tf.placeholder(tf.int64, shape=(None, ))
        int_placeholder_minus_10 = _subtract_ten(int_placeholder)
        # We need to call an analyzer after the loop because only the transitive
        # parents of analyzers are inspected by create_phases
        mappers.scale_to_0_1(int_placeholder_minus_10)

        with self.assertRaisesRegexp(ValueError, 'Cycle detected'):
            impl_helper.create_phases()
Пример #2
0
    def testCreatePhasesWithControlFlowOpsWrappedInApplyFunction(self):
        int_placeholder = tf.placeholder(tf.int64, shape=(None, ))
        int_placeholder_minus_10 = api.apply_function(_subtract_ten,
                                                      int_placeholder)
        # We need to call an analyzer after the loop because only the transitive
        # parents of analyzers are inspected by create_phases
        mappers.scale_to_0_1(int_placeholder_minus_10)

        phases = impl_helper.create_phases()
        self.assertEqual(len(phases), 1)
        #  tft.scale_to_0_1 uses a single analyzer: analyzers._min_and_max.
        self.assertEqual(len(phases[0].analyzer_infos), 1)
Пример #3
0
  def test_create_phases_with_tf_while(self):
    int_placeholder = tf.placeholder(tf.int64, shape=(None,))
    int_placeholder_minus_10 = _subtract_ten_with_tf_while(int_placeholder)

    # We need to call an analyzer after the loop because only the transitive
    # parents of analyzers are inspected by create_phases.
    mappers.scale_to_0_1(int_placeholder_minus_10)

    phases = impl_helper.create_phases({'x': int_placeholder})
    self.assertEqual(len(phases), 1)

    # tft.scale_to_0_1 uses a single analyzer: analyzers._min_and_max.
    self.assertEqual(len(phases[0].analyzer_infos), 1)
Пример #4
0
  def test_create_phases_with_assert_equal(self):
    # Create a graph with a assert_equal, which tests the case when an op has
    # control flow inputs that are ops (not tensors).
    x = tf.placeholder(tf.float32, shape=(None,))
    y = tf.placeholder(tf.float32, shape=(None,))
    x = control_flow_ops.with_dependencies([tf.assert_equal(x, y)], x)
    # We need to call an analyzer after the loop because only the transitive
    # parents of analyzers are inspected by create_phases
    mappers.scale_to_0_1(x)

    phases = impl_helper.create_phases({'x': x, 'y': y})
    self.assertEqual(len(phases), 1)
    #  tft.scale_to_0_1 uses a single analyzer: analyzers._min_and_max.
    self.assertEqual(len(phases[0].analyzer_infos), 1)
Пример #5
0
  def test_create_phases_with_tf_cond(self):
    int_placeholder = tf.placeholder(tf.int64, shape=(None,))
    abs_int_placeholder = tf.cond(
        tf.reduce_sum(int_placeholder) > 0,
        lambda: int_placeholder,
        lambda: -int_placeholder)

    # We need to call an analyzer after the tf.cond because only the transitive
    # parents of analyzers are inspected by create_phases.
    mappers.scale_to_0_1(abs_int_placeholder)

    phases = impl_helper.create_phases({'x': int_placeholder})
    self.assertEqual(len(phases), 1)

    # tft.scale_to_0_1 uses a single analyzer: analyzers._min_and_max.
    self.assertEqual(len(phases[0].analyzer_infos), 1)
Пример #6
0
 def preprocessing_fn(inputs):
   def _subtract_ten(x):
     i = tf.constant(0)
     c = lambda i, x: tf.less(i, 10)
     b = lambda i, x: (tf.add(i, 1), tf.add(x, -1))
     return tf.while_loop(c, b, [i, x])[1]
   scaled_to_0_1 = mappers.scale_to_0_1(_subtract_ten(inputs['x']))
   return {'x_scaled': scaled_to_0_1}
Пример #7
0
 def preprocessing_fn(inputs):
     return {
         'dense_out':
         mappers.scale_to_0_1(inputs['dense_1']),
         'sparse_out':
         api.map(lambda x: tf.sparse_reshape(x, (1, 10)),
                 inputs['sparse'])
     }
Пример #8
0
 def preprocessing_fn(inputs):
   return {
       'dense_out': mappers.scale_to_0_1(inputs['dense_1']),
       'sparse_out': tf.sparse_reshape(inputs['sparse'], (1, 10)),
   }