首页 > 解决方案 > Tensorflow.js 节点未找到后端

问题描述

我想创建一个使用 @tensorflow-models/qna 库的 Discord 机器人,但我已经收到相同的错误 4 小时了,但没有任何进展。当我尝试运行此脚本时:

const qna = require('@tensorflow-models/qna');

(async () => {
    const passage = "Google LLC is an American multinational technology company that specializes in Internet-related services and products, which include online advertising technologies, search engine, cloud computing, software, and hardware. It is considered one of the Big Four technology companies, alongside Amazon, Apple, and Facebook. Google was founded in September 1998 by Larry Page and Sergey Brin while they were Ph.D. students at Stanford University in California. Together they own about 14 percent of its shares and control 56 percent of the stockholder voting power through supervoting stock. They incorporated Google as a California privately held company on September 4, 1998, in California. Google was then reincorporated in Delaware on October 22, 2002. An initial public offering (IPO) took place on August 19, 2004, and Google moved to its headquarters in Mountain View, California, nicknamed the Googleplex. In August 2015, Google announced plans to reorganize its various interests as a conglomerate called Alphabet Inc. Google is Alphabet's leading subsidiary and will continue to be the umbrella company for Alphabet's Internet interests. Sundar Pichai was appointed CEO of Google, replacing Larry Page who became the CEO of Alphabet."
    const question = "Who is the CEO of Google?"
    const model = await qna.load();
    const answers = await model.findAnswers(question, passage);
    console.log(answers);
})();

它给了我以下错误:

(node:16340) UnhandledPromiseRejectionWarning: Error: No backend found in registry.

我试过安装几十个不同版本的 tensorflow 及其后端“tfjs-backend-cpu”。但似乎没有任何效果,我在谷歌上找到的现有答案都没有任何帮助。有人知道如何让该代码在 Node 14 上运行吗?

标签: javascriptnode.jstensorflownpm

解决方案


尝试添加:

require('@tensorflow/tfjs-core'); /* or @tensorflow/tfjs-node */
require('@tensorflow/tfjs-backend-cpu');

到文件的顶部。tfjs -backend-cpu NPM 页面上的说明表明这应该是自动发生的,但我想情况并非如此。


推荐阅读