Class: Tensorflow::Savedmodel

Inherits:
Object
  • Object
show all
Defined in:
lib/tensorflow/savedmodel.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#graphObject

Returns the value of attribute graph.



2
3
4
# File 'lib/tensorflow/savedmodel.rb', line 2

def graph
  @graph
end

#sessionObject

Returns the value of attribute session.



2
3
4
# File 'lib/tensorflow/savedmodel.rb', line 2

def session
  @session
end

Instance Method Details

#LoadSavedModel(exportDir, tags, options) ⇒ Object

LoadSavedModel creates a new SavedModel from a model previously exported to a directory on disk.

Exported models contain a set of graphs and, optionally, variable values. Tags in the model identify a single graph. LoadSavedModel initializes a session with the identified graph and with variables initialized to from the checkpoints on disk.

The tensorflow package currently does not have the ability to export a model to a directory from Go. This function thus currently targets loading models exported in other languages, such as using tf.saved_model.builder in Python. See: www.tensorflow.org/code/tensorflow/python/saved_model/



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/tensorflow/savedmodel.rb', line 16

def LoadSavedModel(exportDir, tags, options)
    status = Tensorflow::Status.new
    copt = if options.nil?
               Tensorflow::TF_NewSessionOptions()
           else
               options.c
            end
    c_export_dir = CString(exportDir)
    c_array = Tensorflow::String_Vector.new
    tags.each_with_index { |value, i| c_array[i] = value }
    graph = Tensorflow::Graph.new
    csess = Tensorflow::Saved_model_helper(copt, c_export_dir, tags, graph.c, status.c)
    session_op = Tensorflow::Session_options.new
    session = Tensorflow::Session.new(graph, session_op)
    session.c = csess
    self.session = session
    self.graph = graph
end