tensorflowjs Could not get context for WebGL version 2

在案例运行中,出现

Could not get context for WebGL version 2

import * as tf from '@tensorflow/tfjs';

几乎所有的博文都只是照搬原文,但是原文只引入了上文,应该添加下文

import '@tensorflow/tfjs-backend-webgl';
import '@tensorflow/tfjs-core/dist/public/chained_ops/sum'; // add the 'sum' chained op to all tensors

另外在

https://developer.aliyun.com/article/700350

https://www.w3cschool.cn/tensorflowjs/tensorflowjs-uc9p2q2m.html

这两个案例中,注意其中的const首字母大写了

新版tensorflowjs中有所变动,详见

https://tensorflow.google.cn/js/tutorials/upgrading_to_3_0

风雨兼程,前程可待!
原文地址:https://www.cnblogs.com/xingnie/p/15622081.html