问题
So I was working with ml5 in js on a simple NeuralNetwork that was going to be trained by images using the p5 js lib to get the images into a array and then train them through ml5, But I ran into a major issue that I have been spending hours looking for the answer of this error but cant find it anywhere. Using Libraries p5,p5.sound,sketch,ml5
Js File
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>
If anybody can help and they know the answer to this error or a simple fix, Please comment.
FULL ERROR
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
来源:https://stackoverflow.com/questions/65210563/error-in-onehot-depth-must-be-2-but-it-is-1