尝试在我制作的游戏中使用ml5 (ml5js.org) KNN分类器。但我不知道怎么把我自己的数据加进去。
<!DOCTYPE html>
<html>
<head>
<title>Getting Started with ml5.js</title>
<script src="https://unpkg.com/ml5@0.1.3/dist/ml5.min.js"></script>
</head>
<body>
<script>
let grid = [
[1, 2],
[3, 4]
];
let knnClassifier = ml5.KNNClassifier();
console.log('trying to add to classifier');
addExample('left');
function addExample(label) {
knnClassifier.addExample(grid, label);
}
</script>
</body>
</html>
我希望代码能够添加到分类器中,而不是得到一个错误消息:
“未定义的TypeError:无法读取未定义属性的‘长度’”
ml5页面有一个KNN分类器示例,其中他们以以下方式转换数据。
// Convert poses results to a 2d array [[score0, x0, y0],...,[score16, x16, y16]]
const poseArray = poses[0].pose.keypoints.map(p => [p.score, p.position.x, p.position.y]);不确定,但我认为他们的数据看起来像是:
{
"score": 0.32371445304906,
"keypoints": [ { "position": { "x": 301.42237830162, "y": 177.69162777066 }, "score": 0.99799561500549 },...
]
}发布于 2019-05-29 15:48:38
需要最后一个版本,所以将链接的一部分更改为ml5@0.1.3到ml5@0.3.0
而且它是有效的。
https://stackoverflow.com/questions/56357353
复制相似问题