Python tensorflow.python.ops.resource_variable_ops.assign_variable_op() Examples
The following are 6
code examples of tensorflow.python.ops.resource_variable_ops.assign_variable_op().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
tensorflow.python.ops.resource_variable_ops
, or try the search function
.
Example #1
Source File: resource_variable_ops_test.py From deep_image_model with Apache License 2.0 | 6 votes |
def testManyAssigns(self): with self.test_session() as session: handle = resource_variable_ops.var_handle_op(dtype=dtypes.int32, shape=[]) create = resource_variable_ops.create_variable_op( handle, constant_op.constant(1, dtype=dtypes.int32)) with ops.control_dependencies([create]): first_read = resource_variable_ops.read_variable_op( handle, dtype=dtypes.int32) with ops.control_dependencies([first_read]): write = resource_variable_ops.assign_variable_op( handle, constant_op.constant(2, dtype=dtypes.int32)) with ops.control_dependencies([write]): second_read = resource_variable_ops.read_variable_op( handle, dtype=dtypes.int32) f, s = session.run([first_read, second_read]) self.assertEqual(f, 1) self.assertEqual(s, 2)
Example #2
Source File: saver.py From lambda-packs with MIT License | 5 votes |
def restore(self, restored_tensors, restored_shapes): restored_tensor = restored_tensors[0] if restored_shapes is not None: restored_tensor = array_ops.reshape(restored_tensor, restored_shapes[0]) return resource_variable_ops.assign_variable_op( self.handle_op, restored_tensor)
Example #3
Source File: saver.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def restore(self, restored_tensors, restored_shapes): restored_tensor = restored_tensors[0] if restored_shapes is not None: restored_tensor = array_ops.reshape(restored_tensor, restored_shapes[0]) return resource_variable_ops.assign_variable_op( self.read_op.op.inputs[0], restored_tensor)
Example #4
Source File: saver.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 5 votes |
def restore(self, restored_tensors, restored_shapes): restored_tensor = restored_tensors[0] if restored_shapes is not None: restored_tensor = array_ops.reshape(restored_tensor, restored_shapes[0]) # Copy the restored tensor to the variable's device. with ops.device(self._var_device): restored_tensor = array_ops.identity(restored_tensor) return resource_variable_ops.assign_variable_op( self.handle_op, restored_tensor)
Example #5
Source File: graph_callable.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 5 votes |
def initializing_scope(self): """Context manager to capture variable creations. Forcibly initializes all created variables. Yields: nothing """ # TODO(apassos) ignoring the regularizer and partitioner here; figure out # how to deal with these. def _custom_getter(getter=None, name=None, shape=None, dtype=dtypes.float32, # pylint: disable=missing-docstring initializer=None, regularizer=None, reuse=None, trainable=True, collections=None, caching_device=None, # pylint: disable=redefined-outer-name partitioner=None, validate_shape=True, use_resource=None): del getter, regularizer, collections, caching_device, partitioner del use_resource, validate_shape if name in self.tf_variables: if reuse: return self.tf_variables[name].initialized_value() else: raise ValueError("Specified reuse=%s but tried to reuse variables." % reuse) # TODO(apassos): ensure this is on the same device as above v = _CapturedVariable(name, initializer, shape, dtype, trainable) self.variables[name] = v graph_mode_resource = resource_variable_ops.var_handle_op( shared_name=name, shape=shape, dtype=dtype) if initializer is None: initializer = _default_initializer(name, shape, dtype) resource_variable_ops.assign_variable_op( graph_mode_resource, initializer(shape, dtype)) return _VariableFromResource( graph_mode_resource, dtype, name, shape=v.shape) scope = variable_scope.get_variable_scope() with variable_scope.variable_scope(scope, custom_getter=_custom_getter): yield
Example #6
Source File: saver.py From keras-lambda with MIT License | 5 votes |
def restore(self, restored_tensors, restored_shapes): restored_tensor = restored_tensors[0] if restored_shapes is not None: restored_tensor = array_ops.reshape(restored_tensor, restored_shapes[0]) return resource_variable_ops.assign_variable_op( self.read_op.op.inputs[0], restored_tensor)