def testL1RegularizerWithScope(self): with self.test_session(): shape = [5, 5, 5] num_elem = 5 * 5 * 5 tensor = tf.constant(1.0, shape=shape) loss = losses.l1_regularizer(scope='L1')(tensor) self.assertEqual(loss.op.name, 'L1/value') self.assertAlmostEqual(loss.eval(), num_elem, 5)
def testL1RegularizerWithScope(self): with self.test_session(): shape = [5, 5, 5] num_elem = 5 * 5 * 5 tensor = tf.constant(1.0, shape=shape) loss = losses.l1_regularizer(scope='L1')(tensor) self.assertEquals(loss.op.name, 'L1/value') self.assertAlmostEqual(loss.eval(), num_elem, 5)
def testL1RegularizerWithWeight(self): with self.test_session(): shape = [5, 5, 5] num_elem = 5 * 5 * 5 tensor = tf.constant(1.0, shape=shape) weight = 0.01 loss = losses.l1_regularizer(weight)(tensor) self.assertEqual(loss.op.name, 'L1Regularizer/value') self.assertAlmostEqual(loss.eval(), num_elem * weight, 5)
def testL1RegularizerWithWeight(self): with self.test_session(): shape = [5, 5, 5] num_elem = 5 * 5 * 5 tensor = tf.constant(1.0, shape=shape) weight = 0.01 loss = losses.l1_regularizer(weight)(tensor) self.assertEquals(loss.op.name, 'L1Regularizer/value') self.assertAlmostEqual(loss.eval(), num_elem * weight, 5)