Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

127
Visualizações
Teachable machine model returning same prediction on html canvas element

I am trying to predict drawing made on html canvas element with the help of Teachable Machine tensorflow.js. However when I am trying to predict using model.predict(image) it is giving me the same output as [0.2351463884,0.76485371] . I have tried using an html image element and it is working fine. The problem is only when I use Html canvas element.

const URL = "https://teachablemachine.withgoogle.com/models/S5O-110Gl/";

let model, labelContainer, maxPredictions;

// predict drawing on canvas when button is pressed
document.getElementById('start').addEventListener('click', async function() {
  const modelURL = URL + "model.json";
  const metadataURL = URL + "metadata.json";

  // load the model and metadata
  // Refer to tmImage.loadFromFiles() in the API to support files from a file picker
  // or files from your local hard drive
  // Note: the pose library adds "tmImage" object to your window (window.tmImage)
  model = await tmImage.load(modelURL, metadataURL);
  maxPredictions = model.getTotalClasses();

  var canvas = document.getElementById('myCanvas');

  const prediction = await model.predict(image);
  console.log(prediction)




});

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The TensorFlow algorithm probably does not accept canvas as a source, only image elements. But you can draw a canvas back into an image.

<canvas id="canvas" width="640" height="360"></canvas>

let canvas = document.getElementById("canvas");
let image = new Image();
image.src = canvas.toDataURL();
document.appendChild(image);
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda