bubbliiiing / unet-pytorch

这是一个unet-pytorch的源码,可以训练自己的模型

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

When running the onnx model, encountered an error outputMap. values is not a function

zddhandsome opened this issue · comments

my code is

document.addEventListener('DOMContentLoaded', function() {
    //  
    const sess = new onnx.InferenceSession();
    sess.loadModel('./onnx_model.onnx').then(() => {
      //  
      document.getElementById('button').addEventListener('click', predictImage);
    });
    
    async function predictImage() {
      //  
      const fileInput = document.getElementById('file-input');
      const file = fileInput.files[0];
      if (!file) return;
      //  
      const reader = new FileReader();
      reader.readAsDataURL(file);
      reader.onload = async function(event) {
        //  
        const img = new Image();
        img.src = event.target.result;
        img.onload = function() {
        //  
        const canvas = document.createElement('canvas');
        const ctx = canvas.getContext('2d');
        canvas.width = 224;
        canvas.height = 224;
        ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
        //  
        const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
        const inputData = new Float32Array(1 * 1 * 224 * 224);
        for (let i = 0; i < 224 * 224 * 3; i += 3) {
        inputData[i / 3] = imageData.data[i] / 255;
        }
        const inputTensor = new onnx.Tensor(inputData, 'float32', [1, 1, 224, 224]);
        //  
        const outputMap = sess.run([inputTensor]);
        const outputTensor = outputMap.values().next().value;
        //  
        const predictions = outputTensor.data;
        console.log(predictions);
        };
      };
    }
  });

but i got the error "outputMap.values is not a function"

After reading the official documents, I came up with the answer
here is the link https://github.com/microsoft/onnxjs/blob/master/README.md