Hyuto/yolov5-onnxruntime-web

How to use yolov5x-seg.onnx?

winktool opened this issue ยท 10 comments

How to use yolov5x-seg.onnx?

How to change these codes for getting masks?

  const dims = [1, 3, height, width];
  const imageTensor = await imageDataToTensor(image, dims);
  const feeds = {};
  feeds[session.inputNames[0]] = imageTensor;
  const results = await session.run(feeds);
  const output0 = results[session.outputNames[0]];
  const boxes = [];
  for (let r = 0; r < output0.data.length; r += output0.dims[2]) {
    const data = output0.data.slice(r, r + output0.dims[2]); // get rows
    console.log("data", output0.data);
    const scores = data.slice(5); // classes probability scores
    const confidence = data[4]; // detection confidence
    const classId = scores.indexOf(Math.max(...scores)); // class id of maximum probability scores
    const maxClassProb = scores[classId]; // maximum probability scores
    if (confidence >= confidenceThreshold && maxClassProb >= classThreshold) {
      const [x, y, w, h] = data.slice(0, 4);
      boxes.push({
        name: labels[classId],
        score: (maxClassProb * 100).toFixed(1),
        classId: classId,
        probability: maxClassProb,
        confidence: confidence,
        bounding: [x - 0.5 * w, y - 0.5 * h, w, h],
      });
    }
  }

Like this: https://github.com/UNeedCryDear/yolov5-seg-opencv-dnn-cpp/blob/master/yolo_seg.cpp#L115

Hey,bro,i found these,maybe can help us.
ultralytics/yolov5#9746

Hyuto commented

Hello, sorry but I can't help you on this. Since I don't have any experience on object segmentation case, I still don't know how the model really work. Object segmentation is a new and exciting project, I'll surely do it in the future project but not in short time.

Yes, I'm looking forward to your new progress.

Hyuto commented

I've create new repo on deploy YOLOv5-seg on onnxruntime but in python. You can take a look here https://github.com/Hyuto/yolov5-seg-onnxruntime

You're a really good guy!

but do you know how to use them with nodejs.
python version link:https://github.com/ultralytics/yolov5/blob/master/segment/predict.py

Hyuto commented

Hello just a little bit update here, I've implemented it using onnxruntime-web although the performance is bad and can't do live detection (video), but hey IT WORKS ๐Ÿ˜

https://github.com/Hyuto/yolov5-seg-onnxruntime-web

If any issue on yolov5-seg you can put it there. I'm closing this issue