One热中出错:深度必须为>=2,但它是1

Error in oneHot: depth must be gt;=2, but it is 1(One热中出错:深度必须为gt;=2,但它是1)

本文介绍了One热中出错:深度必须为>=2,但它是1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我在js中使用ml5在一个简单的NeuralNetwork上工作,它将使用P5 js库通过图像进行训练,将图像放入一个数组中,然后通过ml5训练它们,但我遇到了一个主要问题,我花了几个小时寻找这个错误的答案,但在任何地方都找不到它。 使用库p5、p5、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:UsersmattdDesktopXamphtdocsJs Importing Lib
ode_modules@tensorflow	fjs-coredist	f-core.esm.js:17:357944
oneHot @ c:UsersmattdDesktopXamphtdocsJs Importing Lib
ode_modules@tensorflow	fjs-coredist	f-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:UsersmattdDesktopXamphtdocsJs Importing Libimproring.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

推荐答案

不确定它们是否相同,但在我的情况下,某些训练数据集只有1个输出标签的单一结果,因此模型不会训练。

它似乎与";深度必须为>;=2有某种匹配,但它是1条消息(&q;)。

为确保我只需在数据集中手动添加另一个结果并重新启动

这篇关于One热中出错:深度必须为&gt;=2,但它是1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:One热中出错:深度必须为&gt;=2,但它是1

基础教程推荐