tensorflow - 如何使用 P5 createVector 创建的向量作为 tensorflow.js 中的张量
问题描述
我正在使用 p5 返回绘制线的矢量路径。该行中的所有向量都被推入一个包含所有向量的数组中。我正在尝试将其用作张量,但我不断收到错误消息
检查模型输入时出错:您传递给模型的张量数组不是模型预期的大小。预计会看到 1 个张量,但得到了以下张量列表:当我在开发工具上打开数组时,每个向量都打印如下:
0:向量{p5:p5,x:0.5150300601202404,y:-0.25450901803607207,z:0}
可能是向量数组中的 p5 文本给了我错误吗?这是我的模型和拟合代码:
let vectorpath = []; //vector path array
// model, setting layers till next '-----'
const model = tf.sequential();
model.add(tf.layers.dense({units: 4, inputShape: [2, 2], activation: 'sigmoid'}));
model.add(tf.layers.dense({units: 2, activation: 'sigmoid'}));
console.log(JSON.stringify(model.outputs[0].shape));
model.weights.forEach(w => {
console.log(w.name, w.shape);
});
// -----
//this is under the draw function so it is continually updated
const labels = tf.randomUniform([0, 1]);
function onBatchEnd(batch, logs) {
console.log('Accuracy', logs.acc);
}
model.fit(vectorpath, labels, {
epochs: 5,
batchSize: 32,
callbacks: {onBatchEnd}
}).then(info => {
console.log('Final accuracy', info.history.acc);
});
什么可能导致错误?我该如何解决?这个问题很模糊,但我真的不确定。
解决方案
推荐阅读
- python - 返回比较中较大的值
- replace - SQLDeveloper 导入多个存储过程或全局替换
- xml - 可以有不同子节点的 XSLT 格式 XML
- c - 相同尺寸类型的 C 联合效率
- javascript - Javascript 搜索数组列表的数组
- java - ProGuard 阻止构造函数
- flutter - Flutter,我如何设置具有灵活高度且最大高度为 300 的项目列表的高度?
- powershell - Powershell 和 MailKit - 脚本失败
- r - 什么是密钥服务器(R 安装)
- vue.js - 网站的一部分可以是静态网站生成的,而另一部分是传统的水疗中心吗?