edge-impulse-linux 1.25.3 → 1.26.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.
- package/README.md +53 -0
- package/build/cli/linux/agent-runner-metadata.d.ts +19 -0
- package/build/cli/linux/agent-runner-metadata.js +59 -0
- package/build/cli/linux/agent-runner-metadata.js.map +1 -0
- package/build/cli/linux/audio-utils.d.ts +10 -0
- package/build/cli/linux/audio-utils.js +29 -0
- package/build/cli/linux/audio-utils.js.map +1 -0
- package/build/cli/linux/linux-device.d.ts +0 -1
- package/build/cli/linux/linux-device.js +2 -31
- package/build/cli/linux/linux-device.js.map +1 -1
- package/build/cli/linux/runner-utils.d.ts +3 -1
- package/build/cli/linux/runner-utils.js +34 -3
- package/build/cli/linux/runner-utils.js.map +1 -1
- package/build/cli/linux/runner.js +198 -29
- package/build/cli/linux/runner.js.map +1 -1
- package/build/cli-common/model-monitor.d.ts +13 -0
- package/build/cli-common/model-monitor.js +68 -8
- package/build/cli-common/model-monitor.js.map +1 -1
- package/build/cli-common/remote-mgmt-service.d.ts +1 -0
- package/build/cli-common/remote-mgmt-service.js +31 -16
- package/build/cli-common/remote-mgmt-service.js.map +1 -1
- package/build/library/moving-average-filter.d.ts +1 -1
- package/build/library/sensors/sensors-helper.d.ts +12 -0
- package/build/library/sensors/sensors-helper.js +28 -3
- package/build/library/sensors/sensors-helper.js.map +1 -1
- package/build/sdk/studio/sdk/api/devicesApi.d.ts +92 -1
- package/build/sdk/studio/sdk/api/devicesApi.js +414 -0
- package/build/sdk/studio/sdk/api/devicesApi.js.map +1 -1
- package/build/sdk/studio/sdk/api/learnApi.d.ts +2 -0
- package/build/sdk/studio/sdk/api/learnApi.js +11 -0
- package/build/sdk/studio/sdk/api/learnApi.js.map +1 -1
- package/build/sdk/studio/sdk/model/datasetRatioDataRatio.d.ts +1 -1
- package/build/sdk/studio/sdk/model/datasetSplitOptions.d.ts +1 -1
- package/build/sdk/studio/sdk/model/deployPretrainedModelModelClassification.d.ts +1 -0
- package/build/sdk/studio/sdk/model/deployPretrainedModelModelClassification.js.map +1 -1
- package/build/sdk/studio/sdk/model/deploymentHistory.d.ts +5 -0
- package/build/sdk/studio/sdk/model/deviceDeploymentEvent.d.ts +39 -0
- package/build/sdk/studio/sdk/model/deviceDeploymentEvent.js +7 -0
- package/build/sdk/studio/sdk/model/deviceDeploymentEvent.js.map +1 -0
- package/build/sdk/studio/sdk/model/deviceModelDeploymentRequest.d.ts +6 -0
- package/build/sdk/studio/sdk/model/deviceModelDeploymentRequest.js +4 -0
- package/build/sdk/studio/sdk/model/deviceModelDeploymentRequest.js.map +1 -0
- package/build/sdk/studio/sdk/model/deviceTelemetryInterval.d.ts +21 -0
- package/build/sdk/studio/sdk/model/deviceTelemetryInterval.js +4 -0
- package/build/sdk/studio/sdk/model/deviceTelemetryInterval.js.map +1 -0
- package/build/sdk/studio/sdk/model/impulseLearnBlock.d.ts +2 -2
- package/build/sdk/studio/sdk/model/impulseSpecificGpuTrainingProcessor.d.ts +5 -0
- package/build/sdk/studio/sdk/model/impulseSpecificGpuTrainingProcessor.js +6 -0
- package/build/sdk/studio/sdk/model/impulseSpecificGpuTrainingProcessor.js.map +1 -0
- package/build/sdk/studio/sdk/model/impulseType.d.ts +4 -2
- package/build/sdk/studio/sdk/model/impulseType.js +1 -1
- package/build/sdk/studio/sdk/model/impulseType.js.map +1 -1
- package/build/sdk/studio/sdk/model/learnBlock.d.ts +2 -1
- package/build/sdk/studio/sdk/model/learnBlockType.d.ts +2 -3
- package/build/sdk/studio/sdk/model/learnBlockType.js +1 -1
- package/build/sdk/studio/sdk/model/learnBlockType.js.map +1 -1
- package/build/sdk/studio/sdk/model/listDeviceDeploymentHistoryResponse.d.ts +19 -0
- package/build/sdk/studio/sdk/model/listDeviceDeploymentHistoryResponse.js +4 -0
- package/build/sdk/studio/sdk/model/listDeviceDeploymentHistoryResponse.js.map +1 -0
- package/build/sdk/studio/sdk/model/listDeviceTelemetryResponse.d.ts +16 -0
- package/build/sdk/studio/sdk/model/listDeviceTelemetryResponse.js +4 -0
- package/build/sdk/studio/sdk/model/listDeviceTelemetryResponse.js.map +1 -0
- package/build/sdk/studio/sdk/model/listLatestDeviceTelemetryResponse.d.ts +12 -0
- package/build/sdk/studio/sdk/model/listLatestDeviceTelemetryResponse.js +4 -0
- package/build/sdk/studio/sdk/model/listLatestDeviceTelemetryResponse.js.map +1 -0
- package/build/sdk/studio/sdk/model/models.d.ts +7 -1
- package/build/sdk/studio/sdk/model/models.js +7 -1
- package/build/sdk/studio/sdk/model/models.js.map +1 -1
- package/build/sdk/studio/sdk/model/monitoringEventEvaluationConfig.d.ts +4 -2
- package/build/sdk/studio/sdk/model/monitoringEventEvaluationConfig.js +1 -1
- package/build/sdk/studio/sdk/model/monitoringEventEvaluationConfig.js.map +1 -1
- package/build/sdk/studio/sdk/model/organizationCreateProjectRequest.d.ts +1 -2
- package/build/sdk/studio/sdk/model/organizationCreateProjectRequest.js.map +1 -1
- package/build/sdk/studio/sdk/model/organizationPipelineStep.d.ts +1 -2
- package/build/sdk/studio/sdk/model/organizationPipelineStep.js.map +1 -1
- package/build/sdk/studio/sdk/model/organizationTransferLearningOperatesOn.d.ts +1 -1
- package/build/sdk/studio/sdk/model/organizationTransferLearningOperatesOn.js +1 -1
- package/build/sdk/studio/sdk/model/organizationTransferLearningOperatesOn.js.map +1 -1
- package/build/sdk/studio/sdk/model/setKerasParameterRequest.d.ts +2 -2
- package/build/sdk/studio/sdk/model/uploadPretrainedModelRequest.d.ts +8 -0
- package/build/sdk/studio/sdk/model/uploadPretrainedModelRequest.js.map +1 -1
- package/build/shared/MgmtInterfaceTypes.d.ts +1 -290
- package/package.json +4 -1
- package/test/agent-client.test.ts +853 -0
- package/test/agent-runner-metadata.test.ts +31 -0
- package/test/audio-utils.test.ts +26 -0
- package/test/model-monitor.test.ts +121 -0
- package/test/monitoring-policy-protocol.test.ts +62 -0
- package/test/sensor-selection.test.ts +26 -0
- package/build/sdk/studio/sdk/model/experimentalImpulseSpecificGpuTrainingProcessor.d.ts +0 -6
- package/build/sdk/studio/sdk/model/experimentalImpulseSpecificGpuTrainingProcessor.js +0 -6
- package/build/sdk/studio/sdk/model/experimentalImpulseSpecificGpuTrainingProcessor.js.map +0 -1
|
@@ -49,12 +49,15 @@ const uuid_1 = require("uuid");
|
|
|
49
49
|
const models = __importStar(require("../../sdk/studio/sdk/model/models"));
|
|
50
50
|
const runner_profiling_1 = require("./runner-profiling");
|
|
51
51
|
const os_1 = __importDefault(require("os"));
|
|
52
|
+
const agent_runner_metadata_1 = require("./agent-runner-metadata");
|
|
53
|
+
const audio_utils_1 = require("./audio-utils");
|
|
52
54
|
const RUNNER_PREFIX = '\x1b[33m[RUN]\x1b[0m';
|
|
53
55
|
const CLASSIFIER_THRESHOLD = { id: 42, type: 'classification', min_score: 0.001 };
|
|
54
56
|
let audioClassifier;
|
|
55
57
|
let imageClassifier;
|
|
56
58
|
let modelMonitor;
|
|
57
59
|
let configFactory;
|
|
60
|
+
let agentClient;
|
|
58
61
|
let vlmServerProcess = null;
|
|
59
62
|
// total inference count
|
|
60
63
|
let totalInferenceCount = 0;
|
|
@@ -63,8 +66,9 @@ commander_1.default
|
|
|
63
66
|
.description('Edge Impulse Linux runner ' + packageVersion)
|
|
64
67
|
.version(packageVersion)
|
|
65
68
|
.option('--model-file <file>', 'Specify model file (either path to .eim, or the socket on which the model is running), ' +
|
|
66
|
-
'if not provided the model will be fetched from Edge Impulse')
|
|
69
|
+
'if not provided the model will be fetched from Edge Impulse. Agent mode also reads EI_MODEL_FILE')
|
|
67
70
|
.option('--api-key <key>', 'API key to authenticate with Edge Impulse (overrides current credentials)')
|
|
71
|
+
.option('--agent <socket>', 'Report to the Edge Impulse device agent over this Unix socket. Also reads EI_AGENT_SOCKET')
|
|
68
72
|
.option('--download <file>', 'Just download the model and store it on the file system')
|
|
69
73
|
.option('--list-targets', 'List all supported targets and inference engines')
|
|
70
74
|
.option('--force-target <target>', 'Do not autodetect the target system, but set it by hand (e.g. "runner-linux-aarch64")')
|
|
@@ -72,8 +76,9 @@ commander_1.default
|
|
|
72
76
|
.option('--force-variant <variant>', 'Do not autodetect the model variant, but set it by hand (e.g. "int8")')
|
|
73
77
|
.option('--force-resize-mode <mode>', 'Do not use the resize method from the impulse, but set it by hand (valid: "squash", "fit-shortest" or "fit-longest")')
|
|
74
78
|
.option('--force-camera-resolution <width,height>', 'Do not auto-select camera resolution based on your impulse, but force a resolution (format: "1280,720" for w=1280, h=720)')
|
|
75
|
-
.option('--impulse-id <impulseId>', 'Select the impulse ID (if you have multiple impulses)')
|
|
76
|
-
.option('--run-http-server <port>', 'Do not run using a sensor, but instead expose an API server at the specified port'
|
|
79
|
+
.option('--impulse-id <impulseId>', 'Select the impulse ID (if you have multiple impulses). Agent mode also reads EI_IMPULSE_ID')
|
|
80
|
+
.option('--run-http-server <port>', 'Do not run using a sensor, but instead expose an API server at the specified port. ' +
|
|
81
|
+
'Agent mode also reads EI_RUNNER_HTTP_PORT')
|
|
77
82
|
.option('--preview-port <port>', 'Port to use to render the preview HTTP interface (default: 4912) (ignored when running with --run-http-server). ' +
|
|
78
83
|
'Alternatively you can use the PORT environmental variable. If both are set then `--preview-port` takes precedence.')
|
|
79
84
|
.option('--preview-host <host>', 'Host to listen on for the preview HTTP interface (default: 0.0.0.0) (ignored when running with --run-http-server). ' +
|
|
@@ -81,7 +86,7 @@ commander_1.default
|
|
|
81
86
|
.option('--preview-original-resolution', 'If set, does not resize the preview image to the impulse resolution')
|
|
82
87
|
.option('--monitor', 'Enable model monitoring', false)
|
|
83
88
|
.option('--monitor-max-storage-size <size>', 'The maximum storage size to be used for model monitoring, in MB. Defaults to 250.')
|
|
84
|
-
.option('--monitor-summary-interval-ms <ms>', `
|
|
89
|
+
.option('--monitor-summary-interval-ms <ms>', `Preferred summary interval in milliseconds (minimum ${model_monitor_1.MIN_MONITOR_SUMMARY_INTERVAL_MS}). Adapts to active alert rules; without cadence negotiation the effective interval is at least ${model_monitor_1.DEFAULT_MONITOR_SUMMARY_INTERVAL_MS}.`)
|
|
85
90
|
.option('--clean', 'Clear credentials')
|
|
86
91
|
.option('--silent', `Run in silent mode, don't prompt for credentials`)
|
|
87
92
|
.option('--quantized', 'Download int8 quantized neural networks, rather than the float32 neural networks. ' +
|
|
@@ -97,11 +102,11 @@ commander_1.default
|
|
|
97
102
|
.option('--thresholds <values>', 'Override model thresholds. E.g. --thresholds 4.min_anomaly_score=35 overrides the min. anomaly score for block ID 4 to 35.' +
|
|
98
103
|
'The current thresholds are printed on startup.')
|
|
99
104
|
.option('--mode <mode>', '(default: "streaming") Either: "streaming" (runs on a camera/audio stream and outputs a live inference server) or "http-server" (opens an HTTP server for inference on-demand).' +
|
|
100
|
-
'When passing --run-http-server XXX in, the mode will always default to "http-server"')
|
|
105
|
+
'When passing --run-http-server XXX in, the mode will always default to "http-server". Agent mode also reads EI_RUNNER_MODE')
|
|
101
106
|
.option('--camera <camera>', 'Which camera to use (either the name, or the device address - e.g. /dev/video0). ' +
|
|
102
|
-
'If this argument is omitted, and multiple cameras are found, a CLI selector is shown.')
|
|
107
|
+
'If this argument is omitted, and multiple cameras are found, a CLI selector is shown. Agent mode also reads EI_CAMERA')
|
|
103
108
|
.option('--microphone <microphone>', 'Which microphone to use (either the name, or the device address). ' +
|
|
104
|
-
'If this argument is omitted, and multiple microphones are found, a CLI selector is shown.')
|
|
109
|
+
'If this argument is omitted, and multiple microphones are found, a CLI selector is shown. Agent mode also reads EI_MICROPHONE')
|
|
105
110
|
.option('--shm-behavior <mode>', `Whether to use shared memory to communicate between .eim file and Linux runner (experimental feature), valid: "auto", "always", "never". ` +
|
|
106
111
|
`If not set, defaults to 'auto' - which will use shm if available, and fall back to JSON over TCP otherwise. ` +
|
|
107
112
|
`If set to 'always' will only use shm to communicate (errors out if not available), if set to 'never' will always use JSON over TCP socket.`)
|
|
@@ -130,15 +135,18 @@ const verboseArgv = !!commander_1.default.verbose;
|
|
|
130
135
|
const dontOutputRgbBuffersArgv = !!commander_1.default.dontOutputRgbBuffers;
|
|
131
136
|
const enableGpuArgv = !!commander_1.default.enableGpu;
|
|
132
137
|
const apiKeyArgv = commander_1.default.apiKey;
|
|
138
|
+
const agentSocketArgv = commander_1.default.agent || process.env.EI_AGENT_SOCKET;
|
|
133
139
|
const greengrassArgv = !!commander_1.default.greengrass;
|
|
134
|
-
const modelFileArgv = commander_1.default.modelFile
|
|
140
|
+
const modelFileArgv = commander_1.default.modelFile ||
|
|
141
|
+
(agentSocketArgv ? process.env.EI_MODEL_FILE : undefined);
|
|
135
142
|
const downloadArgv = commander_1.default.download;
|
|
136
143
|
const forceTargetArgv = commander_1.default.forceTarget;
|
|
137
144
|
const forceEngineArgv = commander_1.default.forceEngine;
|
|
138
145
|
const forceVariantArgv = commander_1.default.forceVariant;
|
|
139
146
|
const forceResizeModeArgv = commander_1.default.forceResizeMode;
|
|
140
147
|
const forceCameraResolutionArgv = commander_1.default.forceCameraResolution;
|
|
141
|
-
const impulseIdArgvStr = commander_1.default.impulseId
|
|
148
|
+
const impulseIdArgvStr = commander_1.default.impulseId ||
|
|
149
|
+
(agentSocketArgv ? process.env.EI_IMPULSE_ID : undefined);
|
|
142
150
|
const impulseIdArgv = impulseIdArgvStr && !isNaN(Number(impulseIdArgvStr)) ? Number(impulseIdArgvStr) : undefined;
|
|
143
151
|
const monitorArgv = !!commander_1.default.monitor;
|
|
144
152
|
const monitorMaxStorageSizeStr = commander_1.default.monitorMaxStorageSize;
|
|
@@ -146,12 +154,14 @@ const monitorMaxStorageSizeArgv = monitorMaxStorageSizeStr && !isNaN(Number(moni
|
|
|
146
154
|
? Number(monitorMaxStorageSizeStr)
|
|
147
155
|
: undefined;
|
|
148
156
|
const monitorSummaryIntervalStr = commander_1.default.monitorSummaryIntervalMs;
|
|
149
|
-
const monitorSummaryIntervalArgv = monitorSummaryIntervalStr
|
|
157
|
+
const monitorSummaryIntervalArgv = monitorSummaryIntervalStr !== undefined
|
|
150
158
|
? Number(monitorSummaryIntervalStr)
|
|
151
159
|
: undefined;
|
|
152
160
|
const listTargetsArgv = !!commander_1.default.listTargets;
|
|
153
161
|
const gstLaunchArgsArgv = commander_1.default.gstLaunchArgs;
|
|
154
|
-
|
|
162
|
+
const runHttpServerPortValue = commander_1.default.runHttpServer ||
|
|
163
|
+
(agentSocketArgv ? process.env.EI_RUNNER_HTTP_PORT : undefined);
|
|
164
|
+
let runHttpServerPort = runHttpServerPortValue ? Number(runHttpServerPortValue) : undefined;
|
|
155
165
|
let previewPortArgv = 4912;
|
|
156
166
|
if (commander_1.default.previewPort && !isNaN(Number(commander_1.default.previewPort))) {
|
|
157
167
|
previewPortArgv = Number(commander_1.default.previewPort);
|
|
@@ -173,11 +183,13 @@ const dontPrintPredictionsArgv = !!commander_1.default.dontPrintPredictions;
|
|
|
173
183
|
const thresholdsArgv = commander_1.default.thresholds;
|
|
174
184
|
const shmBehaviorArgv = (commander_1.default.shmBehavior || 'auto');
|
|
175
185
|
const profilingArgv = !!commander_1.default.profiling;
|
|
176
|
-
const cameraArgv = commander_1.default.camera;
|
|
177
|
-
const microphoneArgv = commander_1.default.microphone
|
|
186
|
+
const cameraArgv = commander_1.default.camera || (agentSocketArgv ? process.env.EI_CAMERA : undefined);
|
|
187
|
+
const microphoneArgv = commander_1.default.microphone ||
|
|
188
|
+
(agentSocketArgv ? process.env.EI_MICROPHONE : undefined);
|
|
178
189
|
const cameraColorFormatArgv = commander_1.default.cameraColorFormat;
|
|
179
190
|
const experimentalGstPreferJpegArgv = !!commander_1.default.experimentalGstPreferJpeg;
|
|
180
|
-
let modeArgv = commander_1.default.mode
|
|
191
|
+
let modeArgv = (commander_1.default.mode ||
|
|
192
|
+
(agentSocketArgv ? process.env.EI_RUNNER_MODE : undefined));
|
|
181
193
|
const fakeCameraArgv = commander_1.default.fakeCamera;
|
|
182
194
|
if (modeArgv === 'http-server' && typeof runHttpServerPort === 'undefined') {
|
|
183
195
|
runHttpServerPort = 1337;
|
|
@@ -244,6 +256,7 @@ const onSignal = async () => {
|
|
|
244
256
|
if (vlmServerProcess) {
|
|
245
257
|
await (0, runner_utils_1.stopVlmServer)(vlmServerProcess);
|
|
246
258
|
}
|
|
259
|
+
await agentClient?.close();
|
|
247
260
|
process.exit(0);
|
|
248
261
|
}
|
|
249
262
|
catch (ex2) {
|
|
@@ -255,6 +268,7 @@ const onSignal = async () => {
|
|
|
255
268
|
};
|
|
256
269
|
process.on('SIGHUP', onSignal);
|
|
257
270
|
process.on('SIGINT', onSignal);
|
|
271
|
+
process.on('SIGTERM', onSignal);
|
|
258
272
|
async function ensureVlmServer(opts) {
|
|
259
273
|
const { serverPath, modelFolder, modelName, serverDownloadUrl, modelDownloadUrl, serverAddress, serverPort, enableGpu } = opts;
|
|
260
274
|
const serverExists = node_fs_1.default.existsSync(serverPath);
|
|
@@ -343,6 +357,31 @@ async function ensureVlmServer(opts) {
|
|
|
343
357
|
if (modelFileArgv && downloadArgv) {
|
|
344
358
|
throw new Error('Cannot combine --model-file and --download');
|
|
345
359
|
}
|
|
360
|
+
const invalidHttpPort = !Number.isInteger(runHttpServerPort) || !runHttpServerPort ||
|
|
361
|
+
runHttpServerPort < 1 || runHttpServerPort > 65535;
|
|
362
|
+
if (runHttpServerPortValue && invalidHttpPort) {
|
|
363
|
+
throw new Error(`Invalid HTTP server port "${runHttpServerPortValue}", expected an integer from 1 to 65535`);
|
|
364
|
+
}
|
|
365
|
+
if (modeArgv && modeArgv !== 'streaming' && modeArgv !== 'http-server') {
|
|
366
|
+
throw new Error(`Invalid runner mode "${modeArgv}", expected "streaming" or "http-server"`);
|
|
367
|
+
}
|
|
368
|
+
if (agentSocketArgv) {
|
|
369
|
+
if (apiKeyArgv) {
|
|
370
|
+
throw new Error('Cannot combine --agent and --api-key');
|
|
371
|
+
}
|
|
372
|
+
if (monitorArgv) {
|
|
373
|
+
throw new Error('Cannot combine --agent and --monitor');
|
|
374
|
+
}
|
|
375
|
+
if (greengrassArgv) {
|
|
376
|
+
throw new Error('Cannot combine --agent and --greengrass');
|
|
377
|
+
}
|
|
378
|
+
if (!modelFileArgv) {
|
|
379
|
+
throw new Error('--agent currently requires --model-file until inference bundle activation is implemented');
|
|
380
|
+
}
|
|
381
|
+
if (!impulseIdArgv) {
|
|
382
|
+
throw new Error('--agent with --model-file requires --impulse-id because the .eim does not report its impulse ID');
|
|
383
|
+
}
|
|
384
|
+
}
|
|
346
385
|
if (forceVariantArgv && quantizedArgv) {
|
|
347
386
|
throw new Error('Cannot combine --force-variant and --quantized');
|
|
348
387
|
}
|
|
@@ -357,13 +396,15 @@ async function ensureVlmServer(opts) {
|
|
|
357
396
|
if (monitorMaxStorageSizeArgv && (isNaN(monitorMaxStorageSizeArgv) || monitorMaxStorageSizeArgv <= 0)) {
|
|
358
397
|
throw new Error('Invalid value for --monitor-max-storage-size (was: "' + monitorMaxStorageSizeArgv + '")');
|
|
359
398
|
}
|
|
360
|
-
if (monitorSummaryIntervalArgv && !monitorArgv) {
|
|
399
|
+
if (monitorSummaryIntervalArgv !== undefined && !monitorArgv) {
|
|
361
400
|
throw new Error('Cannot use --monitor-summary-interval-ms without --monitor');
|
|
362
401
|
}
|
|
363
|
-
if (monitorSummaryIntervalArgv &&
|
|
364
|
-
(
|
|
365
|
-
|
|
366
|
-
|
|
402
|
+
if (monitorSummaryIntervalArgv !== undefined &&
|
|
403
|
+
(!Number.isFinite(monitorSummaryIntervalArgv) ||
|
|
404
|
+
monitorSummaryIntervalArgv < model_monitor_1.MIN_MONITOR_SUMMARY_INTERVAL_MS)) {
|
|
405
|
+
throw new Error(`Invalid value for --monitor-summary-interval-ms (was: "${monitorSummaryIntervalStr}"). ` +
|
|
406
|
+
`Minimum value is ${model_monitor_1.MIN_MONITOR_SUMMARY_INTERVAL_MS} ` +
|
|
407
|
+
`(${model_monitor_1.MIN_MONITOR_SUMMARY_INTERVAL_MS / 1000} seconds).`);
|
|
367
408
|
}
|
|
368
409
|
if (forceResizeModeArgv) {
|
|
369
410
|
if (forceResizeModeArgv !== 'squash' && forceResizeModeArgv !== 'fit-longest' && forceResizeModeArgv !== 'fit-shortest') {
|
|
@@ -385,11 +426,11 @@ async function ensureVlmServer(opts) {
|
|
|
385
426
|
`but ${cameraType} detected.`);
|
|
386
427
|
}
|
|
387
428
|
// any of this arguments implies online mode, so we need to login to the studio or get the API key
|
|
388
|
-
const connectionRequired = monitorArgv ||
|
|
429
|
+
const connectionRequired = !agentSocketArgv && (monitorArgv ||
|
|
389
430
|
modelFileArgv === undefined ||
|
|
390
431
|
downloadArgv !== undefined ||
|
|
391
432
|
listTargetsArgv ||
|
|
392
|
-
devArgv;
|
|
433
|
+
devArgv);
|
|
393
434
|
if (connectionRequired) {
|
|
394
435
|
if (monitorArgv && modelFileArgv) {
|
|
395
436
|
cliOptions.connectProjectMsg = 'From which project do you want to monitor the model?';
|
|
@@ -463,6 +504,11 @@ async function ensureVlmServer(opts) {
|
|
|
463
504
|
'"edge-impulse-linux-runner --force-target <target> [--force-engine <engine>] [--force-variant <variant>]"');
|
|
464
505
|
process.exit(0);
|
|
465
506
|
}
|
|
507
|
+
if (agentSocketArgv) {
|
|
508
|
+
const AgentClientConstructor = await loadAgentClient();
|
|
509
|
+
agentClient = new AgentClientConstructor(agentSocketArgv);
|
|
510
|
+
await agentClient.connect(createAgentRegistration(undefined, undefined));
|
|
511
|
+
}
|
|
466
512
|
let initializedProjectState;
|
|
467
513
|
if (modelFileArgv) {
|
|
468
514
|
// if we have the model file, just use that and make it executable
|
|
@@ -644,6 +690,11 @@ async function ensureVlmServer(opts) {
|
|
|
644
690
|
shmBehavior: shmBehaviorArgv,
|
|
645
691
|
});
|
|
646
692
|
model = await runner.init();
|
|
693
|
+
if (agentClient) {
|
|
694
|
+
// Register before applying runner-only threshold defaults or command-line overrides. The agent receives
|
|
695
|
+
// the model metadata exactly as the .eim reported it.
|
|
696
|
+
await agentClient.updateRegistration(createAgentRegistration(model, impulseIdArgv));
|
|
697
|
+
}
|
|
647
698
|
// treat the user provided resize arguments as-if from the model
|
|
648
699
|
if (forceResizeModeArgv) {
|
|
649
700
|
const resizeParam = model.modelParameters.image_resize_mode;
|
|
@@ -719,7 +770,9 @@ async function ensureVlmServer(opts) {
|
|
|
719
770
|
console.log(RUNNER_PREFIX, 'Stored model version in', file);
|
|
720
771
|
}
|
|
721
772
|
}
|
|
722
|
-
|
|
773
|
+
if (!agentSocketArgv) {
|
|
774
|
+
await configFactory.setDeploymentVersion(model.project.deploy_version);
|
|
775
|
+
}
|
|
723
776
|
let param = model.modelParameters;
|
|
724
777
|
if (monitorArgv) {
|
|
725
778
|
// make sure the config is set
|
|
@@ -736,7 +789,7 @@ async function ensureVlmServer(opts) {
|
|
|
736
789
|
if (monitorMaxStorageSizeArgv) {
|
|
737
790
|
await configFactory.setStorageMaxSizeMb(monitorMaxStorageSizeArgv);
|
|
738
791
|
}
|
|
739
|
-
if (monitorSummaryIntervalArgv) {
|
|
792
|
+
if (monitorSummaryIntervalArgv !== undefined) {
|
|
740
793
|
await configFactory.setMonitorSummaryIntervalMs(monitorSummaryIntervalArgv);
|
|
741
794
|
}
|
|
742
795
|
let device = new linux_device_1.LinuxDevice(config, projectId, devKeys, param.sensorType === 'microphone', enableVideo, verboseArgv, configFactory);
|
|
@@ -873,6 +926,7 @@ async function ensureVlmServer(opts) {
|
|
|
873
926
|
projectStudioUrl,
|
|
874
927
|
port: runHttpServerPort,
|
|
875
928
|
printIncomingInferenceReqs: dontPrintPredictionsArgv ? false : true,
|
|
929
|
+
onInference: agentClient ? reportAgentInference : undefined,
|
|
876
930
|
});
|
|
877
931
|
}
|
|
878
932
|
catch (ex2) {
|
|
@@ -898,7 +952,8 @@ async function ensureVlmServer(opts) {
|
|
|
898
952
|
if (enableCameraArgv) {
|
|
899
953
|
const cameraInit = await (0, sensors_helper_1.initCamera)({
|
|
900
954
|
cameraType: cameraType,
|
|
901
|
-
cameraDeviceNameInConfig: cleanArgv ?
|
|
955
|
+
cameraDeviceNameInConfig: agentSocketArgv || cleanArgv ?
|
|
956
|
+
undefined : await configFactory.getCamera(),
|
|
902
957
|
cameraNameArgv: cameraArgv,
|
|
903
958
|
dimensions: forceCameraResolution,
|
|
904
959
|
gstLaunchArgs: gstLaunchArgsArgv,
|
|
@@ -910,16 +965,20 @@ async function ensureVlmServer(opts) {
|
|
|
910
965
|
preferJpegCaps: experimentalGstPreferJpegArgv,
|
|
911
966
|
gstSource: gstSourceArgv,
|
|
912
967
|
fakeImageCameraPath: fakeCameraArgv,
|
|
968
|
+
skipPrompt: !!agentSocketArgv,
|
|
913
969
|
});
|
|
914
970
|
console.log(RUNNER_PREFIX, `Using camera "${cameraInit.cameraDevice}" (because --enable-camera, run with --clean to select another one)`);
|
|
915
971
|
await cameraInit.start();
|
|
916
|
-
|
|
972
|
+
if (!agentSocketArgv) {
|
|
973
|
+
await configFactory.storeCamera(cameraInit.cameraDevice);
|
|
974
|
+
}
|
|
917
975
|
}
|
|
918
976
|
let audioDeviceName = '';
|
|
919
977
|
try {
|
|
920
978
|
audioDeviceName = await (0, sensors_helper_1.initMicrophone)({
|
|
921
|
-
audioDeviceNameInConfig: await configFactory.getAudio(),
|
|
979
|
+
audioDeviceNameInConfig: agentSocketArgv ? undefined : await configFactory.getAudio(),
|
|
922
980
|
audioNameArgv: microphoneArgv,
|
|
981
|
+
skipPrompt: !!agentSocketArgv,
|
|
923
982
|
});
|
|
924
983
|
}
|
|
925
984
|
catch (ex2) {
|
|
@@ -927,7 +986,9 @@ async function ensureVlmServer(opts) {
|
|
|
927
986
|
console.warn(RUNNER_PREFIX, (ex.message || ex.toString()));
|
|
928
987
|
process.exit(1);
|
|
929
988
|
}
|
|
930
|
-
|
|
989
|
+
if (!agentSocketArgv) {
|
|
990
|
+
await configFactory.storeAudio(audioDeviceName);
|
|
991
|
+
}
|
|
931
992
|
console.log(RUNNER_PREFIX, 'Using microphone ' + audioDeviceName);
|
|
932
993
|
audioClassifier = new audio_classifier_1.AudioClassifier(runner, verboseArgv);
|
|
933
994
|
audioClassifier.on('noAudioError', async () => {
|
|
@@ -978,6 +1039,11 @@ async function ensureVlmServer(opts) {
|
|
|
978
1039
|
}
|
|
979
1040
|
audioClassifier.on('result', async (ev, timeMs, audioAsPcm) => {
|
|
980
1041
|
let count = 0;
|
|
1042
|
+
// Agent reporting owns its error handling and must not delay local result processing.
|
|
1043
|
+
void reportAgentInference(ev, {
|
|
1044
|
+
type: 'wav',
|
|
1045
|
+
buffer: (0, audio_utils_1.buildMonoPcm16WavFile)(audioAsPcm, model.modelParameters.frequency),
|
|
1046
|
+
});
|
|
981
1047
|
if (!ev.result.classification)
|
|
982
1048
|
return;
|
|
983
1049
|
if (modelMonitor) {
|
|
@@ -1038,7 +1104,8 @@ async function ensureVlmServer(opts) {
|
|
|
1038
1104
|
(0, runner_utils_1.imageClassifierHelloMsg)(model);
|
|
1039
1105
|
const cameraInit = await (0, sensors_helper_1.initCamera)({
|
|
1040
1106
|
cameraType: cameraType,
|
|
1041
|
-
cameraDeviceNameInConfig: cleanArgv ?
|
|
1107
|
+
cameraDeviceNameInConfig: agentSocketArgv || cleanArgv ?
|
|
1108
|
+
undefined : await configFactory.getCamera(),
|
|
1042
1109
|
cameraNameArgv: cameraArgv,
|
|
1043
1110
|
dimensions: forceCameraResolution,
|
|
1044
1111
|
gstLaunchArgs: gstLaunchArgsArgv,
|
|
@@ -1054,8 +1121,11 @@ async function ensureVlmServer(opts) {
|
|
|
1054
1121
|
preferJpegCaps: experimentalGstPreferJpegArgv,
|
|
1055
1122
|
gstSource: gstSourceArgv,
|
|
1056
1123
|
fakeImageCameraPath: fakeCameraArgv,
|
|
1124
|
+
skipPrompt: !!agentSocketArgv,
|
|
1057
1125
|
});
|
|
1058
|
-
|
|
1126
|
+
if (!agentSocketArgv) {
|
|
1127
|
+
await configFactory.storeCamera(cameraInit.cameraDevice);
|
|
1128
|
+
}
|
|
1059
1129
|
imageClassifier = new image_classifier_1.ImageClassifier(runner, cameraInit.camera, {
|
|
1060
1130
|
verbose: verboseArgv,
|
|
1061
1131
|
});
|
|
@@ -1133,6 +1203,8 @@ async function ensureVlmServer(opts) {
|
|
|
1133
1203
|
let awsResult;
|
|
1134
1204
|
let awsResultKey;
|
|
1135
1205
|
let count = 0;
|
|
1206
|
+
// Agent reporting owns its error handling and must not delay local result processing.
|
|
1207
|
+
void reportAgentInference(ev, { type: 'jpg', buffer: imgAsJpg });
|
|
1136
1208
|
if (ev.result.classification) {
|
|
1137
1209
|
// print the raw predicted values for this frame
|
|
1138
1210
|
const c = structuredClone(ev.result.classification);
|
|
@@ -1252,6 +1324,10 @@ async function ensureVlmServer(opts) {
|
|
|
1252
1324
|
}
|
|
1253
1325
|
}
|
|
1254
1326
|
catch (ex2) {
|
|
1327
|
+
// The signal handler owns cleanup and the successful exit code once shutdown has started.
|
|
1328
|
+
if (isExiting) {
|
|
1329
|
+
return;
|
|
1330
|
+
}
|
|
1255
1331
|
let ex = ex2;
|
|
1256
1332
|
console.warn(RUNNER_PREFIX, 'Failed to run impulse', ex.message || ex.toString());
|
|
1257
1333
|
if ((ex.message || ex.toString()).indexOf('libtensorflowlite_flex') > -1) {
|
|
@@ -1276,6 +1352,99 @@ async function ensureVlmServer(opts) {
|
|
|
1276
1352
|
process.exit(1);
|
|
1277
1353
|
}
|
|
1278
1354
|
})();
|
|
1355
|
+
/**
|
|
1356
|
+
* Loads the experimental workload API client only after agent-managed mode is selected, so ordinary
|
|
1357
|
+
* runner modes do not depend on a module that is intentionally absent from some builds.
|
|
1358
|
+
*/
|
|
1359
|
+
async function loadAgentClient() {
|
|
1360
|
+
try {
|
|
1361
|
+
return (await Promise.resolve().then(() => __importStar(require('../../cli-common/agent-client')))).AgentClient;
|
|
1362
|
+
}
|
|
1363
|
+
catch (ex2) {
|
|
1364
|
+
const ex = ex2;
|
|
1365
|
+
if (ex.code === 'MODULE_NOT_FOUND') {
|
|
1366
|
+
throw new Error('--agent requires the device protocol validators, which are not included in this build');
|
|
1367
|
+
}
|
|
1368
|
+
throw ex;
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
/**
|
|
1372
|
+
* Builds the runner state sent to the device agent. The runner first calls this without a model so
|
|
1373
|
+
* the agent knows the workload is alive, then calls it again with the metadata reported by the
|
|
1374
|
+
* loaded `.eim` so the agent knows which model this runner currently serves.
|
|
1375
|
+
*
|
|
1376
|
+
* @param model Metadata reported by the loaded `.eim`, or undefined for the initial registration.
|
|
1377
|
+
* @param impulseId Studio impulse ID supplied separately because the `.eim` does not report it.
|
|
1378
|
+
*/
|
|
1379
|
+
function createAgentRegistration(model, impulseId) {
|
|
1380
|
+
const imageReference = process.env.EI_RUNNER_IMAGE || `edge-impulse-linux-runner:${packageVersion}`;
|
|
1381
|
+
const imageDigest = process.env.EI_RUNNER_IMAGE_DIGEST;
|
|
1382
|
+
const mode = (0, agent_runner_metadata_1.agentRunnerMode)(runHttpServerPort, cameraArgv, microphoneArgv, model);
|
|
1383
|
+
let modelRegistrations = [];
|
|
1384
|
+
if (model) {
|
|
1385
|
+
if (!impulseId) {
|
|
1386
|
+
throw new Error('Cannot register a loaded model with the agent without an impulse ID');
|
|
1387
|
+
}
|
|
1388
|
+
const engine = model.modelParameters.inferencing_engine;
|
|
1389
|
+
modelRegistrations = [{
|
|
1390
|
+
// TODO(closed-loop-demo#67): Use the bundle-local model ID from manifest.json.
|
|
1391
|
+
id: `impulse-${impulseId}`,
|
|
1392
|
+
projectId: model.project.id,
|
|
1393
|
+
projectName: model.project.name,
|
|
1394
|
+
projectOwner: model.project.owner,
|
|
1395
|
+
impulseId,
|
|
1396
|
+
deploymentVersion: model.project.deploy_version,
|
|
1397
|
+
engine: typeof engine === 'number' ? (0, agent_runner_metadata_1.agentEngineName)(engine) : 'unknown',
|
|
1398
|
+
modelType: model.modelParameters.model_type,
|
|
1399
|
+
labels: model.modelParameters.labels,
|
|
1400
|
+
thresholds: model.modelParameters.thresholds,
|
|
1401
|
+
}];
|
|
1402
|
+
}
|
|
1403
|
+
return {
|
|
1404
|
+
kind: 'inference_runner',
|
|
1405
|
+
version: packageVersion,
|
|
1406
|
+
contractVersion: 1,
|
|
1407
|
+
capabilities: ['inputPolicy'],
|
|
1408
|
+
artifact: {
|
|
1409
|
+
kind: 'containerImage',
|
|
1410
|
+
reference: imageReference,
|
|
1411
|
+
...(imageDigest ? { digest: imageDigest } : {}),
|
|
1412
|
+
},
|
|
1413
|
+
...(mode ? { mode } : {}),
|
|
1414
|
+
models: modelRegistrations,
|
|
1415
|
+
};
|
|
1416
|
+
}
|
|
1417
|
+
/**
|
|
1418
|
+
* Converts one successful `.eim` response into the event schema and sends it through the local
|
|
1419
|
+
* agent. Reporting failures are logged without stopping inference, because the model remains useful
|
|
1420
|
+
* while the agent reconnects or restarts.
|
|
1421
|
+
*
|
|
1422
|
+
* @param result Successful response returned by the active `.eim`.
|
|
1423
|
+
* @param input Input consumed by the model, when the current inference mode exposes it.
|
|
1424
|
+
*/
|
|
1425
|
+
async function reportAgentInference(result, input) {
|
|
1426
|
+
if (!agentClient || !impulseIdArgv) {
|
|
1427
|
+
return;
|
|
1428
|
+
}
|
|
1429
|
+
const event = {
|
|
1430
|
+
id: (0, uuid_1.v4)(),
|
|
1431
|
+
inferenceTimestamp: Date.now(),
|
|
1432
|
+
results: [{
|
|
1433
|
+
// TODO(closed-loop-demo#67): Use the same bundle-local model ID as registration.
|
|
1434
|
+
modelId: `impulse-${impulseIdArgv}`,
|
|
1435
|
+
result: result.result,
|
|
1436
|
+
timing: result.timing,
|
|
1437
|
+
...(result.info ? { info: result.info } : {}),
|
|
1438
|
+
}],
|
|
1439
|
+
};
|
|
1440
|
+
try {
|
|
1441
|
+
await agentClient.postInference(event, input);
|
|
1442
|
+
}
|
|
1443
|
+
catch (ex2) {
|
|
1444
|
+
const ex = ex2;
|
|
1445
|
+
console.warn(RUNNER_PREFIX, `Failed to report inference to the device agent: ${ex.message || ex.toString()}`);
|
|
1446
|
+
}
|
|
1447
|
+
}
|
|
1279
1448
|
function getFriendlyModelTypeName(modelType) {
|
|
1280
1449
|
switch (modelType) {
|
|
1281
1450
|
case 'int8':
|