adjusted test for new model

This commit is contained in:
znetsixe
2025-11-25 16:19:09 +01:00
parent 77adb043b0
commit 3971b4e328
3 changed files with 132 additions and 341 deletions

File diff suppressed because one or more lines are too long

View File

@@ -1,11 +1,14 @@
const tf = require('@tensorflow/tfjs');
const fs = require('fs');
const path = require('path');
class ModelLoader {
constructor(logger) {
this.logger = logger || console;
this.model = null;
}
/*
async loadModel(modelUrl, inputShape = [null, 24, 166]) {
try {
this.logger.debug(`Fetching model JSON from: ${modelUrl}`);
@@ -63,6 +66,34 @@ this.model = await tf.loadLayersModel(tf.io.fromMemory(artifacts));
throw error;
}
}
*/
async loadModelPath(modelPath, inputShape = [1,48,6]) {
try {
const resolvedModelPath = path.resolve(modelPath);
this.logger.debug(`Loading model JSON from: ${resolvedModelPath}`);
const modelJSON = JSON.parse(fs.readFileSync(resolvedModelPath, 'utf-8'));
this.configureInputLayer(modelJSON, inputShape);
const baseDir = path.dirname(resolvedModelPath);
const weightFile = path.resolve(baseDir, modelJSON.weightsManifest[0].paths[0]);
const weightBuffer = fs.readFileSync(weightFile).buffer;
const artifacts = {
modelTopology: modelJSON.modelTopology,
weightSpecs: modelJSON.weightsManifest[0].weights,
weightData: weightBuffer
};
this.model = await tf.loadLayersModel(tf.io.fromMemory(artifacts));
this.logger.debug('Model loaded successfully');
return this.model;
} catch (error) {
this.logger.error(`Failed to load model: ${error.message}`);
throw error;
}
}
@@ -101,11 +132,22 @@ this.model = await tf.loadLayersModel(tf.io.fromMemory(artifacts));
const modelLoader = new ModelLoader();
//example!!
/*
(async () => {
try {
const localURL = "http://localhost:1880/generalFunctions/datasets/lstmData/tfjs_model/model.json";
//const localURL = "http://localhost:1880/generalFunctions/datasets/lstmData/tfjs_model/model.json";
const model = await modelLoader.loadModel(localURL);
const localPath = path.join(
__dirname,
'../../../generalFunctions/datasets/lstmData/tfjs_model/model.json'
);
const model = await modelLoader.loadModelPath(localPath);
//const model = await modelLoader.loadModel(localURL); USES URL
console.log('Model loaded successfully');
const denseLayer = model.getLayer('dense_8');
@@ -118,5 +160,5 @@ const modelLoader = new ModelLoader();
}
})();
//*/
module.exports = ModelLoader;

View File

@@ -1,256 +0,0 @@
{
"general": {
"name": {
"default": "Monster Configuration",
"rules": {
"type": "string",
"description": "A human-readable name or label for this configuration."
}
},
"id": {
"default": null,
"rules": {
"type": "string",
"nullable": true,
"description": "A unique identifier for this configuration. If not provided, defaults to null."
}
},
"unit": {
"default": "unitless",
"rules": {
"type": "string",
"description": "The unit for this configuration (e.g., 'meters', 'seconds', 'unitless')."
}
},
"logging": {
"logLevel": {
"default": "info",
"rules": {
"type": "enum",
"values": [
{
"value": "debug",
"description": "Log messages are printed for debugging purposes."
},
{
"value": "info",
"description": "Informational messages are printed."
},
{
"value": "warn",
"description": "Warning messages are printed."
},
{
"value": "error",
"description": "Error messages are printed."
}
]
}
},
"enabled": {
"default": true,
"rules": {
"type": "boolean",
"description": "Indicates whether logging is active. If true, log messages will be generated."
}
}
}
},
"functionality": {
"softwareType": {
"default": "monster",
"rules": {
"type": "string",
"description": "Specified software type for this configuration."
}
},
"role": {
"default": "samplingCabinet",
"rules": {
"type": "string",
"description": "Indicates the role this configuration plays (e.g., sensor, controller, etc.)."
}
}
},
"asset": {
"uuid": {
"default": null,
"rules": {
"type": "string",
"nullable": true,
"description": "Asset tag number which is a universally unique identifier for this asset. May be null if not assigned."
}
},
"geoLocation": {
"default": {
"x": 0,
"y": 0,
"z": 0
},
"rules": {
"type": "object",
"description": "An object representing the asset's physical coordinates or location.",
"schema": {
"x": {
"default": 0,
"rules": {
"type": "number",
"description": "X coordinate of the asset's location."
}
},
"y": {
"default": 0,
"rules": {
"type": "number",
"description": "Y coordinate of the asset's location."
}
},
"z": {
"default": 0,
"rules": {
"type": "number",
"description": "Z coordinate of the asset's location."
}
}
}
}
},
"supplier": {
"default": "Unknown",
"rules": {
"type": "string",
"description": "The supplier or manufacturer of the asset."
}
},
"type": {
"default": "sensor",
"rules": {
"type": "enum",
"values": [
{
"value": "sensor",
"description": "A device that detects or measures a physical property and responds to it (e.g. temperature sensor)."
}
]
}
},
"subType": {
"default": "pressure",
"rules": {
"type": "string",
"description": "A more specific classification within 'type'. For example, 'pressure' for a pressure sensor."
}
},
"model": {
"default": "Unknown",
"rules": {
"type": "string",
"description": "A user-defined or manufacturer-defined model identifier for the asset."
}
},
"emptyWeightBucket": {
"default": 3,
"rules": {
"type": "number",
"description": "The weight of the empty bucket in kilograms."
}
}
},
"constraints": {
"samplingtime": {
"default": 0,
"rules": {
"type": "number",
"description": "The time interval between sampling events (in seconds) if not using a flow meter."
}
},
"samplingperiod": {
"default": 24,
"rules": {
"type": "number",
"description": "The fixed period in hours in which a composite sample is collected."
}
},
"minVolume": {
"default": 5,
"rules": {
"type": "number",
"min": 5,
"description": "The minimum volume in liters."
}
},
"maxWeight": {
"default": 23,
"rules": {
"type": "number",
"max": 23,
"description": "The maximum weight in kilograms."
}
},
"subSampleVolume": {
"default": 50,
"rules": {
"type": "number",
"min": 50,
"max": 50,
"description": "The volume of each sub-sample in milliliters."
}
},
"storageTemperature": {
"default": {
"min": 1,
"max": 5
},
"rules": {
"type": "object",
"description": "Acceptable storage temperature range for samples in degrees Celsius.",
"schema": {
"min": {
"default": 1,
"rules": {
"type": "number",
"min": 1,
"description": "Minimum acceptable storage temperature in degrees Celsius."
}
},
"max": {
"default": 5,
"rules": {
"type": "number",
"max": 5,
"description": "Maximum acceptable storage temperature in degrees Celsius."
}
}
}
}
},
"flowmeter": {
"default": true,
"rules": {
"type": "boolean",
"description": "Indicates whether a flow meter is used for proportional sampling."
}
},
"closedSystem": {
"default": false,
"rules": {
"type": "boolean",
"description": "Indicates if the sampling system is closed (true) or open (false)."
}
},
"intakeSpeed": {
"default": 0.3,
"rules": {
"type": "number",
"description": "Minimum intake speed in meters per second."
}
},
"intakeDiameter": {
"default": 12,
"rules": {
"type": "number",
"description": "Minimum inner diameter of the intake tubing in millimeters."
}
}
}
}