class TensorStream::Variable
Class that defines a TensorStream
variable
Attributes
buffer[RW]
op[RW]
options[RW]
trainable[RW]
value[W]
Public Class Methods
global_variables_initializer()
click to toggle source
# File lib/tensor_stream/variable.rb, line 78 def self.global_variables_initializer variables_initializer(TensorStream::GraphKeys::GLOBAL_VARIABLES) end
new(data_type)
click to toggle source
# File lib/tensor_stream/variable.rb, line 7 def initialize(data_type) @data_type = data_type @options = {} @is_const = false end
variables_initializer(collection)
click to toggle source
# File lib/tensor_stream/variable.rb, line 70 def self.variables_initializer(collection) global_variables_ops = TensorStream.get_default_graph.get_collection(collection).map do |variable| _op(:assign, variable.initializer, var_name: variable.name) end TensorStream.group(global_variables_ops) end
Public Instance Methods
assign(value, name: nil, use_locking: false)
click to toggle source
# File lib/tensor_stream/variable.rb, line 47 def assign(value, name: nil, use_locking: false) TensorStream.check_data_types(self, value) _op(:assign, value, name: name, var_name: @name) end
assign_add(value, name: nil)
click to toggle source
# File lib/tensor_stream/variable.rb, line 56 def assign_add(value, name: nil) TensorStream.check_data_types(self, value) _op(:assign_add, value, data_type: data_type, name: name, var_name: @name) end
assign_sub(value)
click to toggle source
# File lib/tensor_stream/variable.rb, line 65 def assign_sub(value) TensorStream.check_data_types(self, value) _op(:assign_sub, value, data_type: data_type, name: name, var_name: @name) end
initialized_value()
click to toggle source
# File lib/tensor_stream/variable.rb, line 40 def initialized_value init_op = @initalizer_tensor.op init_op.shape = @shape || init_op.shape init_op.data_type = @data_type || init_op.data_type init_op end
initializer()
click to toggle source
# File lib/tensor_stream/variable.rb, line 33 def initializer init_op = @initalizer_tensor.op init_op.shape = @shape || init_op.shape init_op.data_type = @data_type || init_op.data_type assign(init_op) end
inspect()
click to toggle source
# File lib/tensor_stream/variable.rb, line 82 def inspect "Variable(#{@name} shape: #{@shape || "?"} data_type: #{@data_type})" end
prepare(rank, shape, variable_scope, options = {})
click to toggle source
# File lib/tensor_stream/variable.rb, line 13 def prepare(rank, shape, variable_scope, options = {}) setup_initial_state(options) @rank = rank @value = nil scope_name = variable_scope ? variable_scope.name : nil variable_scope_initializer = variable_scope ? variable_scope.initializer : nil @name = [scope_name, options[:name] || build_name].compact.reject(&:empty?).join("/") @initalizer_tensor = options[:initializer] || variable_scope_initializer || TensorStream.glorot_uniform_initializer shape = @initalizer_tensor.shape.shape if shape.nil? && @initalizer_tensor && @initalizer_tensor.shape @shape = TensorShape.new(shape, rank) @trainable = options.fetch(:trainable, true) end
read_value()
click to toggle source
# File lib/tensor_stream/variable.rb, line 52 def read_value Evaluator.read_variable(@graph, @name) end
to_math(_tensor, _name_only = false, _max_depth = 99, _unused = 0)
click to toggle source
# File lib/tensor_stream/variable.rb, line 61 def to_math(_tensor, _name_only = false, _max_depth = 99, _unused = 0) @name end
trainable?()
click to toggle source
# File lib/tensor_stream/variable.rb, line 29 def trainable? @trainable end
Protected Instance Methods
build_name()
click to toggle source
# File lib/tensor_stream/variable.rb, line 88 def build_name "Variable#{graph.get_var_counter}:#{@rank}" end