Method: Tensorflow::Graph::FunctionDef#build_function

Defined in:
lib/tensorflow/graph/function_def.rb

#build_function(object) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/tensorflow/graph/function_def.rb', line 46

def build_function(object)
  Graph::new.as_default do |graph|
    placeholders = self.ruby_method.parameters.map.with_index do |param, index|
      signature = self.signatures[index]
      Tensorflow.placeholder(signature.dtype, name: param.last, shape: signature.shape)
    end

    # Call the original ruby_method to build the graph

    bound_method = self.ruby_method.bind(object)
    result = bound_method.call(*placeholders)

    graph.to_function(self.ruby_method.original_name.to_s, nil, placeholders, Array(result))
  end
end