【发布时间】:2019-04-18 00:10:28
【问题描述】:
这似乎很基本,但我无法弄清楚。
所以我有样本/数据/输入,它是一个 10 个整数数组的数组,输出/标签只是一个整数数组。
让我解释一下,可能是我的数据结构不正确。基于 10 个整数的输入,我告诉模型结果是标签/输出中的第 1 个整数。
除此之外,我无法对数据进行批处理,因为它们是连续的。这意味着输入向右移动 1,因此 sample[i+1] 中的前 9 个整数是 sample[i] 的最后 9 个整数加上一个新整数。
这是我的编码方式。
let labels = [1,0,0...]
let samples = [[0,1,1,0,1,0,1,1,1,0], ...]
基本上是 10 个数组的数组。
const model = tf.sequential();
let input = tf.tensor2d(samples);
model.add(tf.layers.dense({ units: 10, batchInputShape: [1, 10], activation: "sigmoid" }));
model.add(tf.layers.dense({ units: 1, activation: "softmax" }));
model.summary();
model.compile({ loss: "meanSquaredError", optimizer: "sgd", metrics: ["accuracy"] });
model.fit(labels, input, { batchSize: 1, shuffle: false, verbose: 1 });
当我尝试这个或任何其他输入组合时,我得到以下内容
UnhandledPromiseRejectionWarning: Error: Error when checking model input: the Array of Tensors that you are passing to your model is not the size the model expected. Expected to see 1 Tensor(s), but instead got the following list of Tensor(s): 0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0
提前感谢您的帮助。
【问题讨论】:
-
最后只需要切换输入和标签
标签: node.js tensorflow tensorflow.js