繁体   English   中英

TensorFlow.js 训练使用多个输入一个 output

[英]TensorFlow.js train using multiple inputs one output

我目前正在尝试编写一个可以将特定数字序列分类为动作的系统。 到目前为止,尝试使用 tensorflow.js 构建它运行良好,但现在我遇到了一些问题。

我正在尝试使用类似的输入来训练 model

[
    [0,1,2,3,4,5,6,7,8,9],
    [0,1,2,3,4,5,6,7,8,9],
    [0,1,2,3,4,5,6,7,8,9],
    [0,1,2,3,4,5,6,7,8,9],
    [0,1,2,3,4,5,6,7,8,9],
]

例如应该导致 output [1]

如下制作张量

let t = tf.tensor2d([...Array.from({ length: (5 * 25) }, (v, i) => i)], [5, 25])

//Tensor
//   [[0  , 1  , 2  , ..., 22 , 23 , 24 ],
//     [25 , 26 , 27 , ..., 47 , 48 , 49 ],
//     [50 , 51 , 52 , ..., 72 , 73 , 74 ],
//     [75 , 76 , 77 , ..., 97 , 98 , 99 ],
//     [100, 101, 102, ..., 122, 123, 124]]

现在这看起来像是我想要的,现在 t.shape 给了我[ 5, 25 ]我想我会用它作为我的 model 的 inputShape,经过研究我发现我需要将它定义为batchInputShape而不是inputShape又消除了一个错误。

loadedModel.add(tf.layers.dense({ units: 256, activation: 'relu', batchInputShape: [5, 25] }));

现在我遇到的问题是 model 将张量视为多个值,因此寻找多个输出,但我试图让它只给一个 output

在运行await loadedModel.fit(t, tf.tensor([0]), { epochs: 5 })

我得到Input Tensors should have the same number of samples as target Tensors. Found 5 input sample(s) and 1 target sample(s). Input Tensors should have the same number of samples as target Tensors. Found 5 input sample(s) and 1 target sample(s).

我认为这表明了我上面写的内容。

现在我的最后一个问题是,我应该如何设置 inputShape(如果那是我做错的),以便只需要一个output。

亲切的问候

发现如果我只是缩小数据数组,它也应该可以解决

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM