所以我在一个简单的神经网络上使用 js 中的 ml5,该神经网络将使用 p5 js 库通过图像进行训练,将图像放入数组中,然后通过 ml5 训练它们,但我遇到了一个我一直遇到的主要问题花费数小时寻找此错误的答案,但无法在任何地方找到它。使用库 p5,p5.sound,sketch,ml5
JS文件
let RustImage = [];
function preload() {
for (let i = 0; i < 5; i++) {
RustImage[i] = loadImage(`RustPhotos/2020-12-08 (${i+7}).png`);
}
}
let NodeClassifier;
function setup() {
createCanvas(440, 440);
// background(0);
// image(RustImage[0], 0, 0, width, height);
let options = {
inputs: [128, 128, 4],
task: "imageClassification",
debug: true,
};
NodeClassifier = ml5.neuralNetwork(options);
for (let i = 0; i < RustImage.length; i++) {
NodeClassifier.addData({ image: RustImage[i] }, { label: "SulfurNode" });
}
NodeClassifier.normalizeData();
NodeClassifier.train({ epochs: 5 }, finishedTraining);
}
function finishedTraining() {
console.log("Finished Training!");
}
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<title>Getting Started with ml5.js</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdn.jsdelivr.net/npm/p5@1.1.9/lib/p5.js"></script>
<script src="p5.js"></script>
<script src="p5.sound.js"></script>
<script src="sketch.js"></script>
<script src="https://unpkg.com/ml5@latest/dist/ml5.min.js"></script>
</head>
<body>
<script src="improring.js"></script>
</body>
</html>
如果有人可以提供帮助并且他们知道此错误的答案或简单的修复,请发表评论。
完全错误
Uncaught Error: Error in oneHot: depth must be >=2, but it is 1
node_modules/@tensorflow/tfjs-core/dist/tf-core.esm.js:17
oneHot_ @ c:\Users\mattd\Desktop\Xamp\htdocs\Js Importing Lib\node_modules\@tensorflow\tfjs-core\dist\tf-core.esm.js:17:357944
oneHot @ c:\Users\mattd\Desktop\Xamp\htdocs\Js Importing Lib\node_modules\@tensorflow\tfjs-core\dist\tf-core.esm.js:17:71801
◀ load ▶
<anonymous> @ cdn.jsdelivr.net/npm/p5@1.1.9/lib/p5.js:65707:28
◀ Promise.then ▶
_main.default.loadImage @ cdn.jsdelivr.net/npm/p5@1.1.9/lib/p5.js:65671:30
<anonymous> @ cdn.jsdelivr.net/npm/p5@1.1.9/lib/p5.js:48748:67
preload @ C:\Users\mattd\Desktop\Xamp\htdocs\Js Importing Lib\improring.js:5:24
_start @ cdn.jsdelivr.net/npm/p5@1.1.9/lib/p5.js:48706:19
p5 @ cdn.jsdelivr.net/npm/p5@1.1.9/lib/p5.js:49057:22
_globalInit @ cdn.jsdelivr.net/npm/p5@1.1.9/lib/p5.js:48197:17
◀ Promise.then ▶
51.../core/main @ cdn.jsdelivr.net/npm/p5@1.1.9/lib/p5.js:48222:71
o @ cdn.jsdelivr.net/npm/p5@1.1.9/lib/p5.js:34:19
<anonymous> @ cdn.jsdelivr.net/npm/p5@1.1.9/lib/p5.js:38:22
38../color/color_conversion @ cdn.jsdelivr.net/npm/p5@1.1.9/lib/p5.js:41211:11
o @ cdn.jsdelivr.net/npm/p5@1.1.9/lib/p5.js:34:19
r @ cdn.jsdelivr.net/npm/p5@1.1.9/lib/p5.js:51:9
<anonymous> @ cdn.jsdelivr.net/npm/p5@1.1.9/lib/p5.js:55:7
<anonymous> @ cdn.jsdelivr.net/npm/p5@1.1.9/lib/p5.js:18:12
<anonymous> @ cdn.jsdelivr.net/npm/p5@1.1.9/lib/p5.js:20:3