Requested texture size [0x0] is invalid. on tfjs face-detection

I got this error when implemented face detection on video stream. I’v use webgl as a backend on tfjs

Uncaught (in promise) Error: Requested texture size [0x0] is invalid.
    at Module.validateTextureSize (webgl_util.ts:210:1)
    at createAndConfigureTexture (gpgpu_util.ts:57:1)
    at Module.createUnsignedBytesMatrixTexture (gpgpu_util.ts:129:1)
    at GPGPUContext.createUnsignedBytesMatrixTexture (gpgpu_context.ts:211:1)
    at TextureManager.acquireTexture (texture_manager.ts:77:1)
    at MathBackendWebGL.acquireTexture (backend_webgl.ts:1215:1)
    at MathBackendWebGL.uploadToGPU (backend_webgl.ts:1187:1)
    at MathBackendWebGL.getTexture (backend_webgl.ts:717:1)
    at Object.fromPixels [as kernelFunc] (FromPixels.ts:81:1)
    at kernelFunc (engine.ts:647:1)

The listener

    // console.log('detector started')
    if (this.detectorInterval === null) {
      this.detectorInterval = setInterval(async () => {
        await this.detect(video, canvas, onFaceDetected, onMultiFaceDetected);
      }, 100);
    }

and detect function

async detect(input, canvas, onFaceDetected, onMultiFaceDetected) {
    const estimationConfig = { flipHorizontal: false };
    const faces = await this.detector.estimateFaces(input, estimationConfig);
    const ctx = canvas.getContext("2d");
    // console.log(faces)

    if (faces.length !== 0) onFaceDetected(true);
    else onFaceDetected(false);

    if (faces.length > 1) onMultiFaceDetected(true);
    else onMultiFaceDetected(false);

    requestAnimationFrame(() => drawFaces(faces, ctx));
  }

The input(video) param is always have hight and weight but got that error Error: Requested texture size [0x0] is invalid. how to resolve the error? Thanks for your help :pray:

Hi @irufano ,

In a video stream, there’s a continuous flow of frames. Some of these frames might have zero dimensions. To prevent this, we can check the texture of each frame before passing it to detector.estimateFaces.

if (! input.videoWidth || ! input.videoHeight) {
    return;
  }

So it will not process video frames that have empty dimensions.

Also, in the latest TensorFlow.js face detection model, the valid syntax is:

const model = faceDetection.SupportedModels.MediaPipeFaceDetector;
const detectorConfig = {
  runtime: 'mediapipe', // or 'tfjs'
}
const detector = await faceDetection.createDetector(model, detectorConfig);
const faces = await detector.estimateFaces(image);

Let me know, if it helps. Thank You!!