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

442
Visualizações
Uncaught (in promise) Error: Failed to compile fragment shader

So I'm using tensorflow JS and python for training models. Now I'm working on the website so that abstract doctors could upload an MRI image and get the prediction. Here's my code:

<script>
    async function LoadModels(){  
               model = undefined;
               model = await tf.loadLayersModel("http://127.0.0.1:5500/modelsBrain/modelBrain.json");
               const image = document.getElementById("image");
               const image1 = tf.browser.fromPixels(image);
               const image2 = tf.reshape(image1, [1,200,200,3]);
               const prediction = model.predict(image2);
               const softmaxPred = prediction.softmax().dataSync();
               alert(softmaxPred);

               let top5 = Array.from(softmaxPred)
                    .map(function (p, i) {
                        return {
                            probability: p,
                            className: TARGET_CLASSES_BRAIN[i]
                        };
                    }).sort(function (a, b) {
                        return b.probability - a.probability;
                    }).slice(0, 4);
                    
            const pred = [[]];
            top5.forEach(function (p) {
            pred.push(p.className, p.probability);
            alert(p.className + ' ' + p.probability);
        });
            }

    const fileInput = document.getElementById("file-input");
    const image = document.getElementById("image");

    function getImage() {
        if(!fileInput.files[0])
        throw new Error("Image not found");
        const file = fileInput.files[0];

        const reader = new FileReader();

        reader.onload = function (event) {
            const dataUrl = event.target.result;
            const imageElement = new Image();
            imageElement.src = dataUrl;

            imageElement.onload = async function () {
                image.setAttribute("src", this.src);
                image.setAttribute("height", this.height);
                image.setAttribute("width", this.width);
                await LoadModels();
            };
        };

        reader.readAsDataURL(file);
    }
    fileInput.addEventListener("change", getImage);
</script>

This error occurrs not every (!) Live Server open. I am confused, what seems to be the problem?

enter image description here

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

0

Error CONTEXT_LOST_WEBGL is 99% due to low GPU memory - what kind of HW do you have available? Alternatively, you can try WASM backend which runs computation on CPU and doesn't require GPU resources.

Btw, you're not deallocating your tensors anywhere so if you're running this in a loop for multiple inputs, you do have a massive memory leak. But if error occurs on the first input already, your GPU simply is not good enough for this model.

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