javascript - WebGL:使用 tf.browser.fromPixels 转换本地镜像时出现 INVALID_VALUE

标签 javascript html tensorflow webgl

执行以下代码后:

  var myImage = new Image(48,48);
  myImage.src = '1.png';
  document.body.appendChild(myImage);
  console.log(tf.browser.fromPixels(myImage));

出现警告消息:

WebGL: INVALID_VALUE: texImage2D: no image

尽管图像已成功加载并显示在 html 页面上,但转换似乎失败了。怎么解决这个问题?

最佳答案

通常您需要等待图像加载。

const myImage = new Image();
myImage.onload = function() {
  console.log(tf.browser.fromPixels(myImage));
};
myImage.src = '1.png';
document.body.appendChild(myImage);

关于javascript - WebGL:使用 tf.browser.fromPixels 转换本地镜像时出现 INVALID_VALUE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58507432/

相关文章:

javascript - 使用 blur.js (blurjs.js) 模糊远程托管的图像

python - 在 python 中转义 html?

jquery - bootstrap navbar-collapse 正在改变导航项的方向

html - 在 CSS 中创建图像拼贴

tensorflow 2 : Customized Loss Function works differently from the original Keras SparseCategoricalCrossentropy

python - E1120 :No value for argument 'y' in function call on Tensorflow

javascript - 用于 ES6 生成器的 hasNext()

javascript - react ES5 : one button invoked two functions

javascript - 简单的 Javascript 计算器,出了问题吗?

python - 重新训练 Tensorflow 的 Inception v3 模型时没有反向移植错误