Class: TensorStream::Yaml

Inherits:
Serializer show all
Includes:
OpHelper, StringHelper
Defined in:
lib/tensor_stream/graph_serializers/yaml.rb

Overview

Parses pbtext files and loads it as a graph

Instance Method Summary collapse

Methods included from OpHelper

#_op, #cons, #format_source, #fp_type?, #i_cons, #i_op, #i_var, #int_type?, #reduced_shape, #shape_eval, #shape_full_specified, #shapes_fully_specified_and_equal

Methods included from StringHelper

#camelize, #constantize, #symbolize_keys, #underscore

Methods inherited from Serializer

#serialize

Instance Method Details

#get_string(tensor_or_graph, session = nil, graph_keys = nil) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/tensor_stream/graph_serializers/yaml.rb', line 7

def get_string(tensor_or_graph, session = nil, graph_keys = nil)
  graph = tensor_or_graph.is_a?(Tensor) ? tensor_or_graph.graph : tensor_or_graph
  serialized_arr = []

  node_keys = graph_keys.nil? ? graph.node_keys : graph.node_keys.select { |k| graph_keys.include?(k) }

  node_keys.each do |k|
    node = if block_given?
      yield graph, k
    else
      graph.get_tensor_by_name(k)
    end
    next unless node.is_a?(Operation)

    serialized_arr << node.to_h
  end

  serialized_arr.to_yaml
end