コード例 #1
0
 def testL1L2RegularizerWithScope(self):
     with self.test_session():
         shape = [5, 5, 5]
         num_elem = 5 * 5 * 5
         tensor = tf.constant(1.0, shape=shape)
         loss = losses.l1_l2_regularizer(scope='L1L2')(tensor)
         self.assertEqual(loss.op.name, 'L1L2/value')
         self.assertAlmostEqual(loss.eval(), num_elem + num_elem / 2, 5)
コード例 #2
0
ファイル: losses_test.py プロジェクト: 1206lyp/models
 def testL1L2RegularizerWithScope(self):
   with self.test_session():
     shape = [5, 5, 5]
     num_elem = 5 * 5 * 5
     tensor = tf.constant(1.0, shape=shape)
     loss = losses.l1_l2_regularizer(scope='L1L2')(tensor)
     self.assertEquals(loss.op.name, 'L1L2/value')
     self.assertAlmostEqual(loss.eval(), num_elem + num_elem / 2, 5)
コード例 #3
0
 def testL1L2RegularizerWithWeights(self):
   with self.test_session():
     shape = [5, 5, 5]
     num_elem = 5 * 5 * 5
     tensor = tf.constant(1.0, shape=shape)
     weight_l1 = 0.01
     weight_l2 = 0.05
     loss = losses.l1_l2_regularizer(weight_l1, weight_l2)(tensor)
     self.assertEquals(loss.op.name, 'L1L2Regularizer/value')
     self.assertAlmostEqual(loss.eval(),
                            num_elem * weight_l1 + num_elem * weight_l2 / 2, 5)