module TensorStream class Graphml def initialize end def serialize(session, tensor, filename) @session = session @last_session_context = session.last_session_context arr_buf = [] arr_buf << '' arr_buf << '' arr_buf << '' arr_buf << '' arr_buf << '' arr_buf << '' arr_buf << "" arr_buf << "" arr_buf << "out" arr_buf << "red" arr_buf << "" to_graph_ml(tensor, arr_buf) arr_buf << "" arr_buf << "" arr_buf << "" File.write(filename, arr_buf.join("\n")) end private def _val(tensor) JSON.pretty_generate(@last_session_context[tensor.name]) end def to_graph_ml(tensor, arr_buf = [], added = {}, _id = 0) puts tensor.name added[tensor.name] = true arr_buf << "" arr_buf << "#{tensor.operation}" arr_buf << "#{tensor.to_math(true, 1)}" arr_buf << "blue" if @last_session_context[tensor.name] arr_buf << "#{_val(tensor)}" end arr_buf << "" tensor.items.each do |item| next unless item next if _added[item.name] next to_graph_ml(item, arr_buf, added) if item.is_a?(Operation) added[item.name] = true if item.is_a?(Variable) arr_buf << "" arr_buf << "#{item.name}" arr_buf << "green" if @last_session_context[item.name] arr_buf << "#{_val(tensor)}" end arr_buf << "" elsif item.is_a?(Placeholder) arr_buf << "" arr_buf << "#{item.name}" arr_buf << "yellow" if @last_session_context[item.name] arr_buf << "#{_val(tensor)}" end arr_buf << "" else arr_buf << "" arr_buf << "#{item.name}" arr_buf << "black" if @last_session_context[item.name] arr_buf << "#{_val(tensor)}" end arr_buf << "" end end tensor.items.each do |item| next unless item arr_buf << "" end end def _gml_string(str) str.gsub('/','-') end end end