如何在BrainJS中使用带有已加载模型的toSVG

时间:2019-04-17 15:04:52

标签: javascript svg machine-learning brain.js

我正在使用BrainJS中的toSVG()函数将神经网络绘制为svg文件。这个基本示例有效:

const config = {
        inputSize: 3,
        inputRange: 3,
        hiddenLayers: [4],
        outputSize: 3
};
const svgoptions ={
        fontSize : "12px",
        width : 600,
        height : 400,
        radius : 6,
        line : {width:0.5, color:"rgba(0,0,0,1)" },
        inputs : {color:"rgba(0,127,0,0.6)", label:[]},
        hidden : {color:"rgba(255,127,80,0.6)"},
        outputs : {color:"rgba(100,149,237,0.6)" }
}
const net = new brain.NeuralNetwork(config)
div.innerHTML = brain.utilities.toSVG(net, svgoptions)

,当我使用net.fromJSON()从JSON文件加载现有模型时,出现以下错误:

fetch("model.json")
        .then(res => res.json())
        .then(res => startApp(res))


function startApp(res){
    const net = new brain.NeuralNetwork(config)
    net.fromJSON(res)
    div.innerHTML = brain.utilities.toSVG(net, svgoptions)
}
  

未处理的承诺拒绝:TypeError:Array.from需要类似数组的对象-不是null或未定义

如何通过JSON加载模型并将其绘制为带有BrainJS的SVG?

0 个答案:

没有答案