GithubHelp home page GithubHelp logo

Comments (5)

Apj-infinty avatar Apj-infinty commented on July 23, 2024

@Linchenn
#3457

from tfjs.

Linchenn avatar Linchenn commented on July 23, 2024

Draw API currently does not have implementation for WebGL backend.

from tfjs.

Apj-infinty avatar Apj-infinty commented on July 23, 2024

Thank you for your reply, I was able to complete the objective using WebGPU Kernel! It is almost 100x faster than tf.browser.toPixels() method. Not sure if WebGL will be faster than WebGPU although.


   //importing the WebGPUBackend from npm package @tensorflow/tfjs-backend-webgpu
   import {WebGPUBackend} from @tensorflow/tfjs-backend-webgpu


   //Register the Backend Kernel 
      if (!navigator.gpu) {
        throw new Error("WebGPU not supported on this browser.");
      }

      const customBackendName = 'custom-webgpu';
      const kernels = tf.getKernelsForBackend('webgpu');

      kernels.forEach(kernelConfig => {
        const newKernelConfig = {...kernelConfig, backendName: customBackendName};
        tf.registerKernel(newKernelConfig);
      });
      
      const adapter = await navigator.gpu.requestAdapter({powerPreference: 'low-power'});
      if (!adapter) {
        throw new Error("No appropriate GPUAdapter found.");
      }

      const device = await adapter.requestDevice();

      tf.registerBackend('custom-webgpu', () => new WebGPUBackend(device));

      await tf.setBackend('custom-webgpu')

      await tf.ready()
      const canvas = document.getElementById("imgCanvas2");
      const context =  canvas.getContext("webgpu");
      const canvasFormat = navigator.gpu.getPreferredCanvasFormat();
      context.configure({
        device: device,
        format: canvasFormat,
      });

    //calling Draw API:         
        tf.browser.draw(<input tensor>,canvas);



@Linchenn Shall I close the issue or keep it?

from tfjs.

Linchenn avatar Linchenn commented on July 23, 2024

WebGPU is typically faster than WebGL, while WebGL has more device coverage.

from tfjs.

google-ml-butler avatar google-ml-butler commented on July 23, 2024

Are you satisfied with the resolution of your issue?
Yes
No

from tfjs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.