Javascript 标量输出张量流
使用序列模型,如何获取二维输入数组(三维输入),并让模型对每个二维输入执行预测,以生成标量?输入形状(板):[153,8,8]。输出形状(结果):[153] 型号:Javascript 标量输出张量流,javascript,tensorflow,machine-learning,neural-network,tensorflow.js,Javascript,Tensorflow,Machine Learning,Neural Network,Tensorflow.js,使用序列模型,如何获取二维输入数组(三维输入),并让模型对每个二维输入执行预测,以生成标量?输入形状(板):[153,8,8]。输出形状(结果):[153] 型号: const model = tf.sequential(); model.add(tf.layers.dense({units: 8, inputShape: [8]})); model.add(tf.layers.dense({units:1, activation: 'sigmoid'})); // Prepare the m
const model = tf.sequential();
model.add(tf.layers.dense({units: 8, inputShape: [8]}));
model.add(tf.layers.dense({units:1, activation: 'sigmoid'}));
// Prepare the model for training: Specify the loss and the optimizer.
model.compile({loss: 'meanSquaredError', optimizer: 'sgd'});
const xs = tf.tensor(boards);
const ys = tf.tensor(results);
model.fit(xs, ys, {batchSize: 8, epoch: 10000}).then(() => {
});
model.predict(tf.tensor(brokenFen)).print();
console.log(JSON.stringify(model.outputs[0].shape));
输出:
Tensor
[[1],
[1],
[1],
[1],
[1],
[1],
[1],
[1]]
[null,1]
期望输出:
Tensor
[1]
如果你有任何进一步的问题,lmk 一点理论… 预测的数量是给定给
predict
方法的特征的批量大小。为了更好地理解哪些特性和标签,让我们考虑以下内容:
| feature 1 | feature 2 | ... | feature n | Label |
|----------:|----------:|----:|-----------|------:|
| x11 | x12 | ... | x1n | y1 |
| x21 | x22 | ... | x2n | y2 |
| ... | ... | .. | ... | ... |
在上图中,数据有n个特征,对应于n个维度,标签有一个维度-为了简单和适合问题。构建模型的输入(第一层)应与要素的尺寸匹配,输出(最后一层)应与标签的尺寸匹配。在训练和预测时,我们给模型一组不同的样本n1,n2。给出的样本数量与批量大小相对应。模型将返回与标签尺寸相同数量的形状元素
该模型具有以下
inputShape:[8]
,这表明我们有8个功能。最后一层有单位:1
,表示标签大小为1。当我们预测价值时会发生什么
const model=tf.sequential();
//第一层
add(tf.layers.dense({units:8,inputShape:[8],activation:'sigmoid'}));
//第二层
add(tf.layers.densite({units:1}));
compile({loss:'meanSquaredError',优化器:'sgd'});
console.log(model.predict(tf.ones([3,8])).shape)/[3,1]3个预测元素
console.log(model.predict(tf.ones([1,8])).shape)/[1,1]单元素预测
一点理论… 预测的数量是给定给
predict
方法的特征的批量大小。为了更好地理解哪些特性和标签,让我们考虑以下内容:
| feature 1 | feature 2 | ... | feature n | Label |
|----------:|----------:|----:|-----------|------:|
| x11 | x12 | ... | x1n | y1 |
| x21 | x22 | ... | x2n | y2 |
| ... | ... | .. | ... | ... |
在上图中,数据有n个特征,对应于n个维度,标签有一个维度-为了简单和适合问题。构建模型的输入(第一层)应与要素的尺寸匹配,输出(最后一层)应与标签的尺寸匹配。在训练和预测时,我们给模型一组不同的样本n1,n2。给出的样本数量与批量大小相对应。模型将返回与标签尺寸相同数量的形状元素
该模型具有以下
inputShape:[8]
,这表明我们有8个功能。最后一层有单位:1
,表示标签大小为1。当我们预测价值时会发生什么
const model=tf.sequential();
//第一层
add(tf.layers.dense({units:8,inputShape:[8],activation:'sigmoid'}));
//第二层
add(tf.layers.densite({units:1}));
compile({loss:'meanSquaredError',优化器:'sgd'});
console.log(model.predict(tf.ones([3,8])).shape)/[3,1]3个预测元素
console.log(model.predict(tf.ones([1,8])).shape)/[1,1]单元素预测
如果您的模型对8个2d输入中的每一个进行预测,则您将获得8个输出,每个输入1个预测。你想用某种方式组合或平均这些预测吗?所以最初我以为我可以取8个输出的平均值,并做我自己的标量值,但是,这意味着网络只是检查每个等级,所以预测将不能考虑整个画面。谢谢你的帮助,我将进一步探讨这个想法。如果你的模型对8个2d输入中的每一个进行预测,那么你将得到8个输出,每个输入1个预测。你想用某种方式组合或平均这些预测吗?所以最初我以为我可以取8个输出的平均值,并做我自己的标量值,但是,这意味着网络只是检查每个等级,所以预测将不能考虑整个画面。谢谢你的帮助,tho,我将进一步研究这个想法。