Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

91
Vistas
How to draw tensorflow js results to canvas? Problems with tf.browser.toPixels - shows old results only

I am new to JS. I have a ML model which does image segmentation. I provide the model with one image, to which it predicts output. I get the correct output array, I've verified.

But when I try to draw this output to a canvas using tf.browser.toPixel I always get the old Image.

Meaning, If I provide input as:

Input : img1 -> img2 -> img3...

output: <random shape> -> img1_prediction -> img2_prediction...

Where the random shape is this always, no matter what the input is. I've checked, this is not the output of my model.

Here's the code for this:

async function detect_custom(imgTag, canvas) {

    let tensor = tf.browser.fromPixels(imgTag).toFloat(); //imgTag is img element in html (input image)
    tensor = tensor.expandDims(0);
    const res = model.predict(tensor).squeeze(); 
    tf.dispose(tensor);
    // Everything is working correctly up to this point.

    await tf.browser.toPixels(res, canvas); // Problematic (I think)
}

I found the await tf.browser.toPixels(res, canvas) from this answer. Can anyone help what am i doing wrong?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I've checked, this is not the output of my model.

What is the output of the model?

And are you sure it takes 0..255 as input range? if input is float32, its likely expecting values in range 0..1 - and it does seems like output is blown up.

try tensor = tensor.div(255.0) before inference to normalize to 0..1
or tensor = tensor.div(127.5).sub(1) to normalize to -1..1

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda