Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid draw API warning if the current backend does not have implementation #7744

Merged
merged 5 commits into from
Jun 9, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions tfjs-core/src/ops/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import {ENGINE} from '../engine';
import {env} from '../environment';
import {getBackend} from '../globals';
import {Draw, DrawAttrs, DrawInputs, FromPixels, FromPixelsAttrs, FromPixelsInputs} from '../kernel_names';
import {getKernel, NamedAttrMap} from '../kernel_registry';
import {Tensor, Tensor2D, Tensor3D} from '../tensor';
Expand Down Expand Up @@ -372,10 +373,13 @@ export async function toPixels(

if (canvas != null) {
if (!hasToPixelsWarned) {
console.warn(
'tf.browser.toPixels is not efficient to draw tensor on canvas. ' +
'Please try tf.browser.draw instead.');
hasToPixelsWarned = true;
const backendName = getBackend();
if (backendName !== 'webgl' && backendName !== 'webgpu') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about checking like below? Then we don't need to revisit it anymore.

 const kernel = getKernel(Draw, ENGINE.backendName);
  if (kernel != null) {
        console.warn(
            'tf.browser.toPixels is not efficient to draw tensor on canvas. ' +
            'Please try tf.browser.draw instead.');
  }

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch, thanks!

console.warn(
'tf.browser.toPixels is not efficient to draw tensor on canvas. ' +
'Please try tf.browser.draw instead.');
hasToPixelsWarned = true;
}
}

canvas.width = width;
Expand Down