@epfml/discojs-node 2.1.2-p20240515133413.0 → 2.1.2-p20240531085945.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import { serialization } from '@epfml/discojs';
|
|
3
|
+
export async function saveModelToDisk(model, modelFolder, modelFileName) {
|
|
4
|
+
try {
|
|
5
|
+
await fs.access(modelFolder);
|
|
6
|
+
}
|
|
7
|
+
catch {
|
|
8
|
+
await fs.mkdir(modelFolder);
|
|
9
|
+
}
|
|
10
|
+
const encoded = await serialization.model.encode(model);
|
|
11
|
+
await fs.writeFile(`${modelFolder}/${modelFileName}`, encoded);
|
|
12
|
+
}
|
|
13
|
+
export async function loadModelFromDisk(modelPath) {
|
|
14
|
+
const content = await fs.readFile(modelPath);
|
|
15
|
+
return await serialization.model.decode(content);
|
|
16
|
+
}
|