0

我已经在Teachable Machine上训练了我自己的模型,我下载了它,然后我对其进行了测试,它使用纯 JavaScript 代码运行良好,但是当我尝试使用 ml5 包在我的角度项目中实现它时,我在尝试时遇到了一些问题将我拥有的经过训练的模型传递给他,它总是告诉我我的模型无效,即使我遵循了ML5 文档中的整个文档,他们说我可以将 url 作为参数传递给我的训练模型,但仍然同样的问题,我不知道问题出在哪里。

我用于加载模型的组件功能:

async loadModel() {
    this.model = await ml5.imageClassifier('https://teachablemachine.withgoogle.com/models/6QKQUqglC/model.json', this.modelLoadedf);
    console.log(this.model);
    this.modelLoaded = true;
    await this.loadTrainableModel();
}

 async loadTrainableModel() {
    // Initialize the Image Classifier method with MobileNet
    this.customModel.modelLoaded = false;
    const features = await ml5.featureExtractor('https://teachablemachine.withgoogle.com/models/6QKQUqglC/model.json');
    console.log('feature extractor loaded ....');

    this.customModel.model = await features.classification();
    console.log('custom classifier loaded....');
    this.customModel.modelLoaded = true;
}

由于我传递给它们的模型,这两个“imageClassifier”和“featureExtractor”总是返回错误。

我的问题有什么解决方案吗?

4

1 回答 1

0

您提到的相同逻辑在 React 中实现。这可能会有所帮助:https ://dementorwriter.medium.com/picture-classification-with-react-ml5-c45672aeb961

      const setup = (p5: p5Types, canvasParentRef: Element) => {
        capture.current = p5.createCapture(p5.VIDEO).parent(canvasParentRef);
        const featureExtractor = ml5.featureExtractor("MobileNet", {epochs: props.numberOfEpochs}, modelReady);
        classifier.current = featureExtractor.classification(
          capture.current,
          videoReady
        );
      };
于 2021-08-07T16:30:48.730 回答