当前位置: 首页>>代码示例>>Python>>正文


Python backend.get_value方法代码示例

本文整理汇总了Python中tensorflow.python.keras.backend.get_value方法的典型用法代码示例。如果您正苦于以下问题:Python backend.get_value方法的具体用法?Python backend.get_value怎么用?Python backend.get_value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tensorflow.python.keras.backend的用法示例。


在下文中一共展示了backend.get_value方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_config

# 需要导入模块: from tensorflow.python.keras import backend [as 别名]
# 或者: from tensorflow.python.keras.backend import get_value [as 别名]
def get_config(self):
        config = {
            "percent_on": self.percent_on,
            "k_inference_factor": self.k_inference_factor,
            "boost_strength": K.get_value(self.boost_strength),
            "boost_strength_factor": self.boost_strength_factor,
            "duty_cycle_period": self.duty_cycle_period,
        }
        config.update(super(KWinnersBase, self).get_config())
        return config 
开发者ID:numenta,项目名称:nupic.tensorflow,代码行数:12,代码来源:k_winners.py

示例2: call

# 需要导入模块: from tensorflow.python.keras import backend [as 别名]
# 或者: from tensorflow.python.keras.backend import get_value [as 别名]
def call(self, inputs, training=None, **kwargs):
        inputs = super().call(inputs, **kwargs)
        k = K.in_test_phase(x=self.k_inference, alt=self.k, training=training)
        kwinners = compute_kwinners(
            x=inputs,
            k=k,
            duty_cycles=self.duty_cycles,
            boost_strength=K.get_value(self.boost_strength),
        )

        duty_cycles = K.in_train_phase(
            lambda: self.compute_duty_cycle(kwinners),
            self.duty_cycles,
            training=training,
        )
        self.add_update(self.duty_cycles.assign(duty_cycles, read_value=False))

        increment = K.in_train_phase(K.shape(inputs)[0], 0, training=training)
        self.add_update(
            self.learning_iterations.assign_add(increment, read_value=False)
        )

        return kwinners 
开发者ID:numenta,项目名称:nupic.tensorflow,代码行数:25,代码来源:k_winners.py

示例3: testSetTFVariableHyper

# 需要导入模块: from tensorflow.python.keras import backend [as 别名]
# 或者: from tensorflow.python.keras.backend import get_value [as 别名]
def testSetTFVariableHyper(self, name, val):
    kwargs = {'learning_rate': 0.01, 'damping': 0.001}
    kwargs[name] = tf.Variable(45.0)
    opt = optimizers.Kfac(model=_simple_mlp(), loss='mse', **kwargs)
    setattr(opt, name, val)

    with self.subTest(name='AssignedCorrectly'):
      self.assertEqual(backend.get_value(getattr(opt, name)), val)
      if hasattr(opt.optimizer, name):
        self.assertEqual(backend.get_value(getattr(opt.optimizer, name)), val)

    with self.subTest(name='SetError'):
      with self.assertRaisesRegex(ValueError, 'Dynamic reassignment only.*'):
        setattr(opt, name, tf.convert_to_tensor(2))
      with self.assertRaisesRegex(ValueError, 'Dynamic reassignment only.*'):
        setattr(opt, name, tf.Variable(2)) 
开发者ID:tensorflow,项目名称:kfac,代码行数:18,代码来源:keras_optimizers_test.py

示例4: testSetFloatHyper

# 需要导入模块: from tensorflow.python.keras import backend [as 别名]
# 或者: from tensorflow.python.keras.backend import get_value [as 别名]
def testSetFloatHyper(self, name, val):
    kwargs = {'learning_rate': 0.01, 'damping': 0.001}
    kwargs[name] = 45.0
    opt = optimizers.Kfac(model=_simple_mlp(), loss='mse', **kwargs)
    setattr(opt, name, val)

    with self.subTest(name='AssignedCorrectly'):
      self.assertEqual(backend.get_value(getattr(opt, name)), val)
      if hasattr(opt.optimizer, name):
        self.assertEqual(backend.get_value(getattr(opt.optimizer, name)), val)

    with self.subTest(name='SetError'):
      with self.assertRaisesRegex(ValueError, 'Dynamic reassignment only.*'):
        setattr(opt, name, tf.convert_to_tensor(2))
      with self.assertRaisesRegex(ValueError, 'Dynamic reassignment only.*'):
        setattr(opt, name, tf.Variable(2)) 
开发者ID:tensorflow,项目名称:kfac,代码行数:18,代码来源:keras_optimizers_test.py

示例5: testInferredBatchSize

# 需要导入模块: from tensorflow.python.keras import backend [as 别名]
# 或者: from tensorflow.python.keras.backend import get_value [as 别名]
def testInferredBatchSize(self):
    dataset = tf.data.Dataset.from_tensors(([1.], [1.]))
    dataset = dataset.repeat().batch(11, drop_remainder=True)
    train_batch = dataset.make_one_shot_iterator().get_next()

    model = tf.keras.Sequential([tf.keras.layers.Dense(1, input_shape=(1,))])
    loss = 'mse'
    train_batch = dataset.make_one_shot_iterator().get_next()
    optimizer = optimizers.Kfac(damping=10.,
                                train_batch=train_batch,
                                model=model,
                                adaptive=True,
                                loss=loss,
                                qmodel_update_rescale=0.01)
    model.compile(optimizer, loss)
    model.train_on_batch(train_batch[0], train_batch[1])
    self.assertEqual(
        tf.keras.backend.get_value(optimizer.optimizer._batch_size), 11) 
开发者ID:tensorflow,项目名称:kfac,代码行数:20,代码来源:keras_optimizers_test.py

示例6: testGettingHyper

# 需要导入模块: from tensorflow.python.keras import backend [as 别名]
# 或者: from tensorflow.python.keras.backend import get_value [as 别名]
def testGettingHyper(self, hyper_ctor):
    kwarg_values = {'learning_rate': 3, 'damping': 20, 'momentum': 13}
    kwargs = {k: hyper_ctor(v) for k, v in kwarg_values.items()}
    opt = optimizers.Kfac(model=_simple_mlp(), loss='mse', **kwargs)
    get_value = backend.get_value
    tf_opt = opt.optimizer
    with self.subTest(name='MatchesFloat'):
      for name, val in kwarg_values.items():
        self.assertEqual(get_value(getattr(opt, name)), val)
    with self.subTest(name='MatchesTfOpt'):
      self.assertEqual(get_value(opt.lr), get_value(tf_opt.learning_rate))
      self.assertEqual(get_value(opt.damping), get_value(tf_opt.damping))
      self.assertEqual(get_value(opt.momentum), get_value(tf_opt.momentum)) 
开发者ID:tensorflow,项目名称:kfac,代码行数:15,代码来源:keras_optimizers_test.py

示例7: testGettingVariableHyperFails

# 需要导入模块: from tensorflow.python.keras import backend [as 别名]
# 或者: from tensorflow.python.keras.backend import get_value [as 别名]
def testGettingVariableHyperFails(self):
    self.skipTest('This is not fixed in TF 1.14 yet.')
    opt = optimizers.Kfac(model=_simple_mlp(),
                          loss='mse',
                          learning_rate=tf.Variable(0.1),
                          damping=tf.Variable(0.1))
    with self.assertRaisesRegex(tf.errors.FailedPreconditionError,
                                '.*uninitialized.*'):
      backend.get_value(opt.learning_rate) 
开发者ID:tensorflow,项目名称:kfac,代码行数:11,代码来源:keras_optimizers_test.py

示例8: testModifyingTensorHypersFails

# 需要导入模块: from tensorflow.python.keras import backend [as 别名]
# 或者: from tensorflow.python.keras.backend import get_value [as 别名]
def testModifyingTensorHypersFails(self, name, val):
    kwargs = {'learning_rate': 3, 'damping': 5, 'momentum': 7}
    kwargs[name] = tf.convert_to_tensor(val)
    opt = optimizers.Kfac(model=_simple_mlp(), loss='mse', **kwargs)
    with self.subTest(name='AssignedCorrectly'):
      self.assertEqual(backend.get_value(getattr(opt, name)), val)
    with self.subTest(name='RaisesError'):
      with self.assertRaisesRegex(AttributeError,
                                  "Can't set attribute: {}".format(name)):
        setattr(opt, name, 17) 
开发者ID:tensorflow,项目名称:kfac,代码行数:12,代码来源:keras_optimizers_test.py

示例9: get_lr

# 需要导入模块: from tensorflow.python.keras import backend [as 别名]
# 或者: from tensorflow.python.keras.backend import get_value [as 别名]
def get_lr(self):
        return K.get_value(self.training_models[0].optimizer.lr) 
开发者ID:Ouwen,项目名称:MimickNet,代码行数:4,代码来源:multi_reducelronplateau.py

示例10: test_ragged_input_pad_and_mask

# 需要导入模块: from tensorflow.python.keras import backend [as 别名]
# 或者: from tensorflow.python.keras.backend import get_value [as 别名]
def test_ragged_input_pad_and_mask(self):
    input_data = ragged_factory_ops.constant([[1, 2, 3, 4, 5], []])
    expected_mask = np.array([True, False])

    output = ToDense(pad_value=-1, mask=True)(input_data)
    self.assertTrue(hasattr(output, "_keras_mask"))
    self.assertIsNot(output._keras_mask, None)
    self.assertAllEqual(K.get_value(output._keras_mask), expected_mask) 
开发者ID:tensorflow,项目名称:text,代码行数:10,代码来源:todense_test.py

示例11: test_sparse_input_pad_and_mask

# 需要导入模块: from tensorflow.python.keras import backend [as 别名]
# 或者: from tensorflow.python.keras.backend import get_value [as 别名]
def test_sparse_input_pad_and_mask(self):
    input_data = sparse_tensor.SparseTensor(
        indices=[[0, 0], [1, 2]], values=[1, 2], dense_shape=[3, 4])

    expected_mask = np.array([True, True, False])

    output = ToDense(pad_value=-1, mask=True)(input_data)
    self.assertTrue(hasattr(output, "_keras_mask"))
    self.assertIsNot(output._keras_mask, None)
    self.assertAllEqual(K.get_value(output._keras_mask), expected_mask) 
开发者ID:tensorflow,项目名称:text,代码行数:12,代码来源:todense_test.py

示例12: get_config

# 需要导入模块: from tensorflow.python.keras import backend [as 别名]
# 或者: from tensorflow.python.keras.backend import get_value [as 别名]
def get_config(self):
        config = {
            'lr': float(K.get_value(self.lr)),
            'beta_1': float(K.get_value(self.beta_1)),
            'beta_2': float(K.get_value(self.beta_2)),
            'decay': float(K.get_value(self.decay)),
            'epsilon': self.epsilon,
            'amsgrad': self.amsgrad
        }
        base_config = super(RAdam, self).get_config()
        return dict(list(base_config.items()) + list(config.items())) 
开发者ID:zheng-yuwei,项目名称:multi-label-classification,代码行数:13,代码来源:radam.py

示例13: get_config

# 需要导入模块: from tensorflow.python.keras import backend [as 别名]
# 或者: from tensorflow.python.keras.backend import get_value [as 别名]
def get_config(self):
        config = {'lr': float(K.get_value(self.lr)),
                  'beta_1': float(K.get_value(self.beta_1)),
                  'beta_2': float(K.get_value(self.beta_2)),
                  'decay': float(K.get_value(self.decay)),
                  'weight_decay': float(K.get_value(self.wd)),
                  'epsilon': self.epsilon}
        base_config = super(AdamW, self).get_config()
        return dict(list(base_config.items()) + list(config.items())) 
开发者ID:jkjung-avt,项目名称:keras_imagenet,代码行数:11,代码来源:adamw.py


注:本文中的tensorflow.python.keras.backend.get_value方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。