javascript - 解决在chrome中运行的tensorflow js的 "Uncaught (in promise) TypeError: fs.writeFile is not a function"的替代方法

标签 javascript node.js typescript tensorflow tensorflow.js

我一直在尝试在下面的代码片段中导出在 Chrome 浏览器中运行的 tensorflow posenet模型中的变量。然而,通过阅读讨论,似乎无法在 Chrome 浏览器中使用 fswritefile 导出变量。我想知道是否还有其他可能的方式导出到 json 文件?如果有人成功了?

export function drawKeypoints(keypoints, minConfidence, ctx, scale = 1) {
  for (let i = 0; i < keypoints.length; i++) {
    const keypoint = keypoints[i];

    if (keypoint.score < minConfidence) {
      continue;
    }

    const {y, x} = keypoint.position;
    drawPoint(ctx, y * scale, x * scale, 3, color);
  }
  //console.log(keypoints);
 let test = JSON.stringify(keypoints);
 fs.writeFile('extract.json', test, (err) => {  
  if (err) throw err;
  console.log('Data written to file');
});

最佳答案

fs 是 Nodejs 特定的模块。它不能在浏览器中使用。 Blob 保存到文件是在浏览器环境中写入文件的标准方式

关于javascript - 解决在chrome中运行的tensorflow js的 "Uncaught (in promise) TypeError: fs.writeFile is not a function"的替代方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55553972/

相关文章:

node.js - npm install 与 edit package.json 和 npm update

javascript - Mongoose - 保存时更新引用的文档

angular - 无法在 Angular 2 模块中导出接口(interface)?

javascript - 使用 .next 从一个 UL 遍历到另一个 UL

javascript - 使用javascript的图像溢出效果

javascript - 如何为 Selenium IDE 选择用 CSS 编码的下拉菜单中的元素?

javascript - 将温度调整为 LAB 色彩空间

node.js - Stub Mongoose 查找方法

javascript - 如何在 Typescript 库中导出子模块

c# - Nuget 包 Microsoft.TypeScript.MSBuild 在 Dockerfile 中失败