Class: TensorStream::Pbtext
- Inherits:
-
Serializer
- Object
- Serializer
- TensorStream::Pbtext
- Includes:
- OpHelper, StringHelper
- Defined in:
- lib/tensor_stream/graph_serializers/pbtext.rb
Instance Method Summary collapse
Methods included from OpHelper
#_op, #cons, #dtype_eval, #format_source, #fp_type?, #i_cons, #i_op, #shape_eval, #val_to_dtype
Methods included from StringHelper
Methods inherited from Serializer
Constructor Details
This class inherits a constructor from TensorStream::Serializer
Instance Method Details
#get_string(tensor_or_graph, session = nil) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/tensor_stream/graph_serializers/pbtext.rb', line 6 def get_string(tensor_or_graph, session = nil) graph = tensor_or_graph.is_a?(Tensor) ? tensor_or_graph.graph : tensor_or_graph @lines = [] graph.nodes.each do |k, node| @lines << "node {" @lines << " name: #{node.name.to_json}" if node.is_a?(TensorStream::Operation) @lines << " op: #{camelize(node.operation.to_s).to_json}" node.inputs.each do |input| next unless input @lines << " input: #{input.name.to_json}" end # type pb_attr('T', "dtype: #{sym_to_protobuf_type(node.data_type)}") (node) elsif node.is_a?(TensorStream::Tensor) && node.is_const @lines << " op: \"Const\"" # type pb_attr('T', "dtype: #{sym_to_protobuf_type(node.data_type)}") pb_attr('value', tensor_value(node)) elsif node.is_a?(TensorStream::Variable) @lines << " op: \"VariableV2\"" pb_attr('T', "dtype: #{sym_to_protobuf_type(node.data_type)}") pb_attr('shape', shape_buf(node, 'shape')) (node) end @lines << "}" end @lines << "versions {" @lines << " producer: 26" @lines << "}" @lines.flatten.join("\n") end |