-
Notifications
You must be signed in to change notification settings - Fork 0
/
install-models.js
35 lines (30 loc) · 1.06 KB
/
install-models.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const axios = require("axios");
const fs = require("fs");
const path = require("path");
const modelUrls = {
"facenet-model":
"https://github.com/GOOD-I-DEER/node-red-contrib-face-vectorization/raw/main/model/facenet-model.onnx",
};
const downloadDir = path.join(__dirname, "model");
async function downloadModels() {
try {
if (!fs.existsSync(downloadDir)) {
fs.mkdirSync(downloadDir, { recursive: true });
}
for (const modelName in modelUrls) {
const modelUrl = modelUrls[modelName];
const response = await axios.get(modelUrl, { responseType: "stream" });
const modelPath = path.join(downloadDir, `${modelName}.onnx`);
const fileStream = fs.createWriteStream(modelPath);
response.data.pipe(fileStream);
await new Promise((resolve, reject) => {
fileStream.on("finish", resolve);
fileStream.on("error", reject);
});
console.log(`Model file ${modelName}.onnx Download Complete`);
}
} catch (error) {
console.error("Error downloading model file:", error);
}
}
downloadModels();