Comments (5)
Sorry but I'm not going to create new repo for this but you could use this project folder as I said before. Mostly YOLOv5 and YOLOv7 work the same way when we deploy it on onnxruntime
, but the problem is YOLOv5 exported onnx model doesn't have NMS layer on it so we have to implement this manually (the performance is really bad compared to NMS on the model, but it works 😆) .
-
Add YOLOv5
onnx
model to the project. Move it tosrc
folder -
Change model and model configuration in
src/index.js
... // model configs const modelInfo = { name: "yolov5n.onnx", inputShape: [1, 3, 640, 640], }; const confidenceThreshold = 0.25; const classThreshold = 0.25; const iouThreshold = 0.45; // overlap threshold ...
Note: I use yolov5 lightest model
yolov5n
here, as for the thresholds you can tweak it yourself -
Add NMS algorithm on
src/index.js
... const NMS = (boxes, overlapThresh) => { // source : https://github.com/Hyuto/yolov5-onnxruntime-web/blob/master/src/utils/nms.js if (boxes.length === 0) { return []; } const pick = []; boxes.sort((b1, b2) => { return b1.confidence - b2.confidence; }); while (boxes.length > 0) { let last = boxes[boxes.length - 1]; pick.push(last); let suppress = [last]; for (let i = 0; i < boxes.length - 1; i++) { const box = boxes[i]; const xx1 = Math.max(box.bounding[0], last.bounding[0]); const yy1 = Math.max(box.bounding[1], last.bounding[1]); const xx2 = Math.min(box.bounding[0] + box.bounding[2], last.bounding[0] + last.bounding[2]); const yy2 = Math.min(box.bounding[1] + box.bounding[3], last.bounding[1] + last.bounding[3]); const w = Math.max(0, xx2 - xx1 + 1); const h = Math.max(0, yy2 - yy1 + 1); const overlap = (w * h) / ((box.bounding[2] + 1) * (box.bounding[3] + 1)); if (overlap > overlapThresh) { suppress.push(boxes[i]); } } boxes = boxes.filter((box) => { return !suppress.find((supp) => { return supp === box; }); }); } return pick; };
-
Modifying
detect
function onsrc/index.js
... const detect = async (frame) => { const input = new Float32Array(frame.buffer); const tensor = new ort.Tensor("float32", input, modelInfo.inputShape); // to ort.Tensor const { output0 } = await session.run({ images: tensor }); // run session and get output layer const boxes = []; // looping through output for (let r = 0; r < output0.data.length; r += output0.dims[2]) { const data = output0.data.slice(r, r + output0.dims[2]); // get rows 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 // filtering by thresholds if (confidence >= confidenceThreshold && maxClassProb >= classThreshold) { const [x, y, w, h] = data.slice(0, 4); boxes.push({ classId: classId, probability: maxClassProb, confidence: confidence, bounding: [x - 0.5 * w, y - 0.5 * h, w, h], }); } } // filtering boxes using Non Maximum Suppression algorithm const selectedBoxes = NMS(boxes, iouThreshold); return selectedBoxes; }; ...
-
And run the project like always
yarn start
from yolov7-node.
With additional configuration on preprocessing model output, I think it's possible to serve yolov5 model.
from yolov7-node.
I am new to this field and look forward to your release of the new version about yolov5.
from yolov7-node.
Thank you very much!
from yolov7-node.
Since there's no problem occur, I'm closing this issue.
from yolov7-node.
Related Issues (5)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from yolov7-node.