Compare commits
2 Commits
8af5846490
...
4a6d092de1
Author | SHA1 | Date | |
---|---|---|---|
4a6d092de1 | |||
a6fd117736 |
36
tool/convert_mnn.js
Normal file
36
tool/convert_mnn.js
Normal file
@ -0,0 +1,36 @@
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const { spawnSync } = require("child_process");
|
||||
|
||||
const CONVERTER_PATH = "C:/Develop/Libs/mnn/bin/MNNConvert.exe";
|
||||
const MODEL_PATH = path.join(__dirname, "../models");
|
||||
|
||||
function onnx2mnn(model) {
|
||||
const name = path.basename(model, ".onnx");
|
||||
const outputFile = path.join(path.dirname(model), name + ".mnn");
|
||||
if (fs.existsSync(outputFile)) console.log(`Skip ${name}`);
|
||||
else {
|
||||
const result = spawnSync(CONVERTER_PATH, [
|
||||
"-f", "ONNX",
|
||||
"--modelFile", model,
|
||||
"--MNNModel", outputFile,
|
||||
"--bizCode", "biz"
|
||||
]);
|
||||
if (result.status !== 0) {
|
||||
console.error(`Failed to convert ${name}`);
|
||||
console.log(result.stdout.toString());
|
||||
}
|
||||
else console.log(`Convert ${name} success`);
|
||||
}
|
||||
}
|
||||
|
||||
function resolveDir(dir) {
|
||||
const files = fs.readdirSync(dir);
|
||||
for (const file of files) {
|
||||
const filepath = path.join(dir, file);
|
||||
if (fs.statSync(filepath).isDirectory()) resolveDir(filepath);
|
||||
else if (path.extname(file) == ".onnx") onnx2mnn(filepath);
|
||||
}
|
||||
}
|
||||
|
||||
resolveDir(MODEL_PATH)
|
Reference in New Issue
Block a user