2023-02-16 19:05:43 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
import nomnoml from 'nomnoml';
|
|
|
|
|
|
|
|
export default function make_graph(summary) {
|
|
|
|
const result = [];
|
2023-02-16 19:24:48 +00:00
|
|
|
|
|
|
|
result.push("#.title: visual=none title=center,bold body=center,bold");
|
|
|
|
result.push(`[<title>Model: ${summary.title}|Total params: ${summary.params}|Trainable params: ${summary.params_trainable}|Non-trainable params: ${summary.params_trainable}|${summary.layers.length} layers, ${summary.edges.length} edges]`)
|
|
|
|
|
2023-02-16 19:05:43 +00:00
|
|
|
for(const layer of summary.layers) {
|
|
|
|
const output_shape = layer.output_shape.replace(/\[/, "\\[")
|
|
|
|
.replace(/\]/, "\\]");
|
|
|
|
result.push(`[${layer.name}|${layer.type}|Params: ${layer.params}|Output shape: ${output_shape}]`);
|
|
|
|
}
|
|
|
|
for(const edge of summary.edges) {
|
|
|
|
result.push(`[${edge.from}] --> [${edge.to}]`);
|
|
|
|
}
|
|
|
|
|
|
|
|
const nomnoml_source = result.join("\n");
|
|
|
|
|
2023-02-18 02:04:40 +00:00
|
|
|
console.info(`[make_graph] nomnoml source:\n${nomnoml_source}`);
|
|
|
|
|
2023-02-16 19:05:43 +00:00
|
|
|
const svg = nomnoml.renderSvg(nomnoml_source);
|
|
|
|
return svg;
|
|
|
|
}
|