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
|
||||||||||||||||||||||||||||||||||||||||||
additionalParams |
Object |
<optional> |
null | Additional parameters for the model. |
- Source:
Example
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:
getTimeStats()
Returns the stats dict to the user
- 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); }
resetTimeStats()
Resets the stats dict to an empty dict
- Source: