deeplearn-graph-serializer
WARNING: This is an unofficial serialization/deserialization library for DeepLearnJs graphs, it is currently obsolete and only compatible with DeepLearnJs versions less than 0.6.
Usage
Require or import this module in your code:
const GraphSerializer =
After a graph is created its structure and values can be exported using GraphSerializer.graphToJson
:
const graphJson = GraphSerializerconsole
A network can be recreated from JSON using GraphSerializer.jsonToGraph
:
const net = GraphSerializerconst graph placeholders variables tensors = net
The GraphSerializer.jsonToGraph
method returns a graph object, any tensors created, placeholder references to tensors by name, and variable data by name.
Advanced Usage
The GraphSerializer.graphToJson
method normally returns a JSON that references tensors starting from id 0
. To preserve the tensor id we can pass false
as the second parameter to GraphSerializer.graphToJson
. In this way it is possible to serialize a collection of graphs that reference shared tensors:
const graph1 = const v = graph1const graph2 = const result = graph2graph2 const graph1Json = GraphSerializerconst graph2Json = GraphSerializer
Then when using GraphSerializer.jsonToGraph
we would pass a deserialized tensors object as the second parameter, this allows the deserializer to chain tensor references from other graphs:
let deserial = GraphSerializerdeserialvariablesvdeserial = GraphSerializerconst session = deserialgraph mathconst squared = await sessionconsole // = 9