You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## Description
Change documentation that is influenced by C++ ports
### Type of change
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [x] Documentation update (improves or adds clarity to existing
documentation)
### Related issues
#255
|`forward`|`(input: string, detectionThreshold: number = 0.7) => Promise<Detection[]>`| A function that accepts an image (url, b64) and returns an array of `Detection` objects. `detectionThreshold` can be supplied to alter the sensitivity of the detection. |
66
+
|`error`| <code>string | null</code> | Contains the error message if the model loading failed.|
67
+
|`isGenerating`|`boolean`| Indicates whether the model is currently processing an inference.|
68
+
|`isReady`|`boolean`| Indicates whether the model has successfully loaded and is ready for inference.|
69
+
|`downloadProgress`|`number`| Represents the download progress as a value between 0 and 1.|
|`load`|`(modelSource: ResourceSource): Promise<void>`| Loads the model, where `modelSource` is a string that specifies the location of the model binary. |
29
-
|`forward`|`(input: string): Promise<{ [category: string]: number }>`| Executes the model's forward pass, where `input` can be a fetchable resource or a Base64-encoded string. |
30
-
|`onDownloadProgress`|`(callback: (downloadProgress: number) => void): any`| Subscribe to the download progress event.|
|`load`|`(modelSource: ResourceSource, onDownloadProgressCallback: (_: number) => void () => {}): Promise<void>`| Loads the model, where `modelSource` is a string that specifies the location of the model binary. To track the download progress, supply a callback function `onDownloadProgressCallback`.|
31
+
|`forward`|`(input: string): Promise<{ [category: string]: number }>`| Executes the model's forward pass, where `input` can be a fetchable resource or a Base64-encoded string.|
32
+
|`delete`|`(): void`| Release the memory held by the module. Calling `forward` afterwards is invalid. |
31
33
32
34
<details>
33
35
<summary>Type definitions</summary>
@@ -40,8 +42,12 @@ type ResourceSource = string | number | object;
40
42
41
43
## Loading the model
42
44
43
-
To load the model, use the `load` method. It accepts the `modelSource` which is a string that specifies the location of the model binary. For more information, take a look at [loading models](../fundamentals/loading-models.md) page. This method returns a promise, which can resolve to an error or void.
45
+
To load the model, create a new instance of the module and use the `load` method on it. It accepts the `modelSource` which is a string that specifies the location of the model binary. For more information, take a look at [loading models](../fundamentals/loading-models.md) page. This method returns a promise, which can resolve to an error or void.
44
46
45
47
## Running the model
46
48
47
-
To run the model, you can use the `forward` method. It accepts one argument, which is the image. The image can be a remote URL, a local file URI, or a base64-encoded image. The method returns a promise, which can resolve either to an error or an object containing categories with their probabilities.
49
+
To run the model, you can use the `forward` method on the module object. It accepts one argument, which is the image. The image can be a remote URL, a local file URI, or a base64-encoded image. The method returns a promise, which can resolve either to an error or an object containing categories with their probabilities.
50
+
51
+
## Managing memory
52
+
53
+
The module is a regular JavaScript object, and as such its lifespan will be managed by the garbage collector. In most cases this should be enough, and you should not worry about freeing the memory of the module yourself, but in some cases you may want to release the memory occupied by the module before the garbage collector steps in. In this case use the method `delete()` on the module object you will no longer use, and want to remove from the memory. Note that you cannot use `forward` after `delete` unless you load the module again.
0 commit comments