Tensorflow.js 节点未找到后端
2021-03-05
1188
我想创建一个使用 @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”。但似乎没有任何效果,我在 Google 上找到的所有现有答案都没有任何帮助。有人知道如何让该代码在 Node 14 上运行吗?
1个回答
尝试添加:
require('@tensorflow/tfjs-core'); /* or @tensorflow/tfjs-node */
require('@tensorflow/tfjs-backend-cpu');
到文件顶部。 tfjs-backend-cpu NPM 页面 上的说明表明这应该会自动发生,但我猜事实并非如此。
Rem-D
2021-03-05