Class: CloudServerModel

CloudServerModel(options, additionalParamsopt)

This class handles interactions with a cloud server for running inference.
It uses socket.io for communication with the server uses internal queues to provide results in order.
Use this class to send image data to the server, retrieve predictions, and manage model parameters.
Internally, it connects through socketio as soon as the model instance is created. It only disconnects when the `cleanup` method is called.

Constructor

new CloudServerModel(options, additionalParamsopt)

Do not call the constructor directly. Use the `loadModel` method of an AIServerZoo instance to create an AIServerModel.
Parameters:
Name Type Attributes Default Description
options Object Options for initializing the model.
Properties
Name Type Attributes Default Description
modelName string The name of the model to load.
serverUrl string The URL of the server to connect to.
modelParams Object The parameters for the model.
token string The authentication token for the model.
max_q_len number <optional>
80 The maximum length of the internal queues.
callback function <optional>
null The callback function to call when results are available.
labels Array.<string> <optional>
null The labels for the model.
additionalParams Object <optional>
null Additional parameters for the model.
Source:
Example

Usage:

let model = zoo.loadModel('model_name', {});
- Use the `predict` method for inference with individual data items or `predict_batch` for multiple items.
let result = await model.predict(someImage);
for await (let result of model.predict_batch(someDataGeneratorFn)) { ... }

Methods

(async) cleanup()

Cleanup the model and release all resources. Internally, it does the following: - Sets the poison flag to stop further inferences - Disconnects the socket - Clears the async queues - Nullifies references - Resets internal states and flags Call this method when you are done using the model to free up resources
Source:

(async) displayResultToCanvas(combinedResult, outputCanvasName, justResultsopt)

Overlay the result onto the image frame and display it on the canvas.
Parameters:
Name Type Attributes Default Description
combinedResult Object The result object combined with the original image frame. This is directly received from `predict` or `predict_batch`
outputCanvasName string | HTMLCanvasElement The canvas to draw the image onto. Either the canvas element or the ID of the canvas element.
justResults boolean <optional>
false Whether to show only the result overlay without the image frame.
Source:

(async) predict(imageFile, infoopt, bypassPreprocessingopt) → {Promise.<Object>}

Predicts the result for a given image.
Parameters:
Name Type Attributes Default Description
imageFile Blob | File | string | HTMLImageElement | HTMLVideoElement | HTMLCanvasElement | ArrayBuffer | TypedArray | ImageBitmap
info string <optional>
performance.now() Unique frame information provided by user (such as frame num). Used for matching results back to input images within callback.
bypassPreprocessing boolean <optional>
false Whether to bypass preprocessing. Used to send Blob data directly to the socket without any preprocessing.
Source:
Returns:
The prediction result.
Type
Promise.<Object>
Examples
If callback is provided:
Onresult handler will invoke the callback directly when the result arrives.
If callback is not provided:
The function waits for the resultQ to get a result, then returns it.
let result = await model.predict(someImage);

(async, generator) predict_batch(data_source, bypassPreprocessingopt) → {Object}

Predicts results for a batch of data. Will yield results if a callback is not provided.
Parameters:
Name Type Attributes Default Description
data_source AsyncIterable An async iterable data source.
bypassPreprocessing boolean <optional>
false Whether to bypass preprocessing.
Source:
Yields:
The prediction result.
Type
Object
Example
The function asynchronously processes results. If a callback is not provided, it will yield results.
for await (let result of model.predict_batch(data_source)) { console.log(result); }