1***@qq.com
1***@qq.com
  • 发布:2021-11-29 17:48
  • 更新:2021-11-29 23:16
  • 阅读:898

【报Bug】 Could not get context for WebGL version 2

分类:uni-app

产品分类: uniapp/App

PC开发环境操作系统: Mac

PC开发环境操作系统版本号: 11.5.2 (20G95)

HBuilderX类型: 正式

HBuilderX版本号: 3.2.16

手机系统: Android

手机系统版本号: Android 8.0

手机厂商: 华为

手机机型: mate10

页面类型: vue

vue版本: vue2

打包方式: 云端

项目创建方式: HBuilderX

示例代码:

‘’‘
<template>
<view>
111
<button @click="sss">444</button>
<button @click="sss2">222</button>
<button @click="sss">444</button>
<button @click="sss">444</button>
<button @click="sss">444</button>
<button @click="sss">444</button>

</view>  

</template>

<script>
import * as tf from '@tensorflow/tfjs';

export default {  
    data() {  
        return {  

        }  
    },  
    methods: {  
        sss(){  
            console.log('ok1')  
            // Define a model for linear regression.   
            const model = tf.sequential();   
            model.add(tf.layers.dense({units: 1, inputShape: [1]}));  

            model.compile({loss: 'meanSquaredError', optimizer: 'sgd'});  

            // Generate some synthetic data for training.   
            const xs = tf.tensor2d([1, 2, 3, 4], [4, 1]);   
            const ys = tf.tensor2d([1, 3, 5, 7], [4, 1]);  

            // Train the model using the data.   
            model.fit(xs, ys, {epochs: 10}).then(() => {   
                // Use the model to do inference on a data point the model hasn't seen before:   
                model.predict(tf.tensor2d([5], [1, 1])).print();  
                 // Open the browser devtools to see the output   
                 console.log('ok')  
                 });  
        },  
        sss2(){  
            console.log('ok1');  
            const a = tf.variable(tf.scalar(Math.random()));  
            const b = tf.variable(tf.scalar(Math.random()));  
            const c = tf.variable(tf.scalar(Math.random()));  
            const d = tf.variable(tf.scalar(Math.random()));  
            function predict(x) {  
              // y = a * x ^ 3 + b * x ^ 2 + c * x + d  
              return tf.tidy(() => {  
                return a.mul(x.pow(tf.scalar(3))) // a * x^3  
                  .add(b.mul(x.square())) // + b * x ^ 2  
                  .add(c.mul(x)) // + c * x  
                  .add(d); // + d  
              });  
            };  
            function loss(predictions, labels) {  
              // 将labels(实际的值)进行抽象  
              // 然后获取平均数.  
              const meanSquareError = predictions.sub(labels).square().mean();  
              return meanSquareError;  
            };  
            const learningRate = 0.5;  
            const optimizer = tf.train.sgd(learningRate);  
            function train(xs, ys, numIterations = 75) {  

              const learningRate = 0.5;  
              const optimizer = tf.train.sgd(learningRate);  

              for (let iter = 0; iter < numIterations; iter++) {  
                optimizer.minimize(() => {  
                  const predsYs = predict(xs);  
                  return loss(predsYs, ys);  
                });  
              };  
              };  
        }  
    }  
}  

</script>

<style>

</style>

’‘’

操作步骤:

运行到内置模拟器中

预期结果:

应该是GL渲染到图片

实际结果:

发生报警,没有显示

bug描述:

在运行tensorflowjs时会有报警
Could not get context for WebGL version 2

2021-11-29 17:48 负责人:无 分享
已邀请:
1***@qq.com

1***@qq.com (作者)

'''
import '@tensorflow/tfjs-backend-webgl';
import '@tensorflow/tfjs-core/dist/public/chained_ops/sum'; // add the 'sum' chained op to all tensors
'''
新tf需要添加这些引用,之后警报会消除。

该问题目前已经被锁定, 无法添加新回复