本文整理汇总了Python中tensorflow.python.ops.resource_variable_ops.resource_scatter_add方法的典型用法代码示例。如果您正苦于以下问题:Python resource_variable_ops.resource_scatter_add方法的具体用法?Python resource_variable_ops.resource_scatter_add怎么用?Python resource_variable_ops.resource_scatter_add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow.python.ops.resource_variable_ops
的用法示例。
在下文中一共展示了resource_variable_ops.resource_scatter_add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _resource_apply_sparse
# 需要导入模块: from tensorflow.python.ops import resource_variable_ops [as 别名]
# 或者: from tensorflow.python.ops.resource_variable_ops import resource_scatter_add [as 别名]
def _resource_apply_sparse(self, grad, var, indices):
momentum_buffer = self.get_slot(var, "momentum")
learning_rate = math_ops.cast(self._learning_rate_tensor, var.dtype.base_dtype)
momentum = math_ops.cast(self._momentum_tensor, var.dtype.base_dtype)
nu = math_ops.cast(self._nu_tensor, var.dtype.base_dtype)
momentum_op = training_ops.resource_sparse_apply_momentum(
var.handle,
momentum_buffer.handle,
nu * (1.0 - momentum) * learning_rate,
grad,
indices,
momentum,
use_locking=self._use_locking,
use_nesterov=False,
)
with ops.control_dependencies([momentum_op]):
delta = (nu - 1.0) * learning_rate * grad
gd_op = resource_variable_ops.resource_scatter_add(var.handle, indices, delta)
return control_flow_ops.group(momentum_op, gd_op)
示例2: _resource_scatter_add
# 需要导入模块: from tensorflow.python.ops import resource_variable_ops [as 别名]
# 或者: from tensorflow.python.ops.resource_variable_ops import resource_scatter_add [as 别名]
def _resource_scatter_add(self, x, i, v):
with ops.control_dependencies(
[resource_variable_ops.resource_scatter_add(x.handle, i, v)]):
return x.value()
示例3: _resource_scatter_add
# 需要导入模块: from tensorflow.python.ops import resource_variable_ops [as 别名]
# 或者: from tensorflow.python.ops.resource_variable_ops import resource_scatter_add [as 别名]
def _resource_scatter_add(self, x, i, v):
with ops.control_dependencies(
[resource_variable_ops.resource_scatter_add(
x.handle, i, v)]):
return x.value()
示例4: _resource_apply_sparse_duplicate_indices
# 需要导入模块: from tensorflow.python.ops import resource_variable_ops [as 别名]
# 或者: from tensorflow.python.ops.resource_variable_ops import resource_scatter_add [as 别名]
def _resource_apply_sparse_duplicate_indices(self, grad, handle, indices):
return resource_variable_ops.resource_scatter_add(
handle.handle, indices, -grad * self._learning_rate)
示例5: _resource_apply_sparse
# 需要导入模块: from tensorflow.python.ops import resource_variable_ops [as 别名]
# 或者: from tensorflow.python.ops.resource_variable_ops import resource_scatter_add [as 别名]
def _resource_apply_sparse(self, grad, handle, indices):
return resource_variable_ops.resource_scatter_add(
handle, indices, -grad * self._learning_rate)
示例6: _resource_scatter_add
# 需要导入模块: from tensorflow.python.ops import resource_variable_ops [as 别名]
# 或者: from tensorflow.python.ops.resource_variable_ops import resource_scatter_add [as 别名]
def _resource_scatter_add(self, x, i, v):
with tf.control_dependencies(
[resource_variable_ops.resource_scatter_add(x.handle, i, v)]):
return x.value()
示例7: _resource_scatter_add
# 需要导入模块: from tensorflow.python.ops import resource_variable_ops [as 别名]
# 或者: from tensorflow.python.ops.resource_variable_ops import resource_scatter_add [as 别名]
def _resource_scatter_add(self, x, i, v):
with ops.control_dependencies([resource_variable_ops.resource_scatter_add(x.handle, i, v)]):
return x.value()
示例8: _resource_scatter_add
# 需要导入模块: from tensorflow.python.ops import resource_variable_ops [as 别名]
# 或者: from tensorflow.python.ops.resource_variable_ops import resource_scatter_add [as 别名]
def _resource_scatter_add(self, x, i, v):
with ops.control_dependencies([resource_variable_ops.resource_scatter_add(x.handle, i, v)]):
return x.value()
示例9: _resource_scatter_add
# 需要导入模块: from tensorflow.python.ops import resource_variable_ops [as 别名]
# 或者: from tensorflow.python.ops.resource_variable_ops import resource_scatter_add [as 别名]
def _resource_scatter_add(self, x, i, v, _=None):
# last argument allows for one overflow argument, to have the same function
# signature as state_ops.scatter_add
with ops.control_dependencies(
[resource_variable_ops.resource_scatter_add(x.handle, i, v)]):
return x.value()
示例10: _resource_scatter_add
# 需要导入模块: from tensorflow.python.ops import resource_variable_ops [as 别名]
# 或者: from tensorflow.python.ops.resource_variable_ops import resource_scatter_add [as 别名]
def _resource_scatter_add(self, x, i, v, _=None):
# last argument allows for one overflow argument, to have the same function
# signature as state_ops.scatter_add
with ops.control_dependencies(
[resource_variable_ops.resource_scatter_add(x.handle, i, v)]):
return x.value()
示例11: _resource_apply_sparse
# 需要导入模块: from tensorflow.python.ops import resource_variable_ops [as 别名]
# 或者: from tensorflow.python.ops.resource_variable_ops import resource_scatter_add [as 别名]
def _resource_apply_sparse(self, grad, var, indices):
def resource_scatter_add(x, i, v):
with ops.control_dependencies([resource_variable_ops.resource_scatter_add(x.handle, i, v)]):
return x.value()
return self._apply_sparse_shared(grad, var, indices, resource_scatter_add)
示例12: testScatterAdd
# 需要导入模块: from tensorflow.python.ops import resource_variable_ops [as 别名]
# 或者: from tensorflow.python.ops.resource_variable_ops import resource_scatter_add [as 别名]
def testScatterAdd(self):
with self.test_session():
handle = resource_variable_ops.var_handle_op(
dtype=dtypes.int32, shape=[1, 1])
resource_variable_ops.create_variable_op(
handle, constant_op.constant([[1]], dtype=dtypes.int32)).run()
resource_variable_ops.resource_scatter_add(
handle, [0], constant_op.constant([[2]], dtype=dtypes.int32)).run()
read = resource_variable_ops.read_variable_op(handle, dtype=dtypes.int32)
self.assertEqual(read.eval(), [[3]])
示例13: _resource_scatter_add
# 需要导入模块: from tensorflow.python.ops import resource_variable_ops [as 别名]
# 或者: from tensorflow.python.ops.resource_variable_ops import resource_scatter_add [as 别名]
def _resource_scatter_add(self, x, i, v):
with ops.control_dependencies(
[resource_variable_ops.resource_scatter_add(
x.handle, i, v)]):
return x.value()
示例14: _resource_scatter_add
# 需要导入模块: from tensorflow.python.ops import resource_variable_ops [as 别名]
# 或者: from tensorflow.python.ops.resource_variable_ops import resource_scatter_add [as 别名]
def _resource_scatter_add(self, x, i, v):
with ops.control_dependencies(
[resource_variable_ops.resource_scatter_add(x, i, v)]):
return x.value()
示例15: _resource_scatter_add
# 需要导入模块: from tensorflow.python.ops import resource_variable_ops [as 别名]
# 或者: from tensorflow.python.ops.resource_variable_ops import resource_scatter_add [as 别名]
def _resource_scatter_add(self, x, i, v):
with ops.control_dependencies(
[resource_variable_ops.resource_scatter_add(
x.handle, i, v)]):
return x.value()