简体   繁体   English

解决在chrome中运行的tensorflow js解决“未捕获(承诺)TypeError:fs.​​writeFile不是函数”的另一种方法

[英]Alternative way to solve “Uncaught (in promise) TypeError: fs.writeFile is not a function” for tensorflow js running in chrome

I have been trying to export a variable in the the tensorflow posenet model running in chrome browser in the code snippet below. 我一直在尝试在下面的代码片段中在chrome浏览器中运行的tensorflowposenet模型中导出变量。 However reading through discussions , it seems one cannot export a variable using fswritefile in the chrome browser. 但是,通读讨论,似乎无法在chrome浏览器中使用fswritefile导出变量。 I was wondering if there is any other possible way to export to json file ? 我想知道是否还有其他可能的方法可以导出到json文件? if some one has managed it ? 如果有人管理好了吗?

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 is a nodejs specific module. fs是nodejs特定的模块。 It can't be used in the browser. 无法在浏览器中使用。 Blob saving to a file is the standard way of writing to a file in the browser environment 将Blob保存到文件是在浏览器环境中写入文件的标准方法

Fs is Node.js/commonJS module and you need an equivalent browser-based ES6 supported module. Fs是Node.js / commonJS模块,您需要一个等效的基于浏览器的ES6支持模块。 In my personal experience,I had to use Fs wrapper in browser like browserfs , browserify-fs or fs-es6 as a workaround. 以我的个人经验,我不得不在浏览器(例如browserfsbrowserify -fsfs-es6)中使用Fs包装器作为解决方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM