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
Models can be loaded using `require()` for bundled assets:
53
+
Models can be loaded using `require()` for bundled assets. The library automatically copies the model from your app bundle to the device's file system and caches it:
**Note:** When using `require()` or `{ url }`, the model is automatically copied to the app's files directory and cached. Subsequent loads will use the cached file for faster initialization.
Sessions are automatically cleaned up by Nitro Modules when they go out of scope. However, you can manually dispose of a session to free memory immediately:
218
+
150
219
```typescript
151
-
// Dispose of session when done
220
+
//Optional: Dispose of session early to free memory immediately
152
221
session.dispose();
153
222
```
154
223
224
+
**When to call `dispose()`:**
225
+
- Loading multiple models and want to free memory between loads
226
+
- Memory-constrained environments
227
+
- Want immediate cleanup instead of waiting for garbage collection
228
+
229
+
**Note:** You don't need to call `dispose()` in most cases - Nitro Modules will automatically clean up when the session is no longer referenced.
230
+
155
231
## API Reference
156
232
157
233
### `ort.getVersion()`
@@ -163,16 +239,31 @@ const version = ort.getVersion();
163
239
console.log('ONNX Runtime version:', version);
164
240
```
165
241
166
-
### `ort.loadModel(path, options?)`
242
+
### `ort.loadModel(source, options?)`
167
243
168
-
Load an ONNX model from a file path or `require()` asset.
244
+
Load an ONNX model from various sources.
169
245
170
246
**Parameters:**
171
-
-`path`: `string` | `number` (from `require()`) - Path to the model file
@@ -211,7 +343,9 @@ Run inference with the given inputs.
211
343
212
344
#### `session.dispose()`
213
345
214
-
Free the session and release resources.
346
+
Manually free the session and release resources immediately.
347
+
348
+
**Note:** This is optional - sessions are automatically cleaned up by Nitro Modules when they go out of scope. Only call this if you need immediate memory cleanup.
215
349
216
350
### `SessionOptions`
217
351
@@ -267,25 +401,30 @@ type ProviderOptions = {
267
401
4.**Reuse Sessions**: Create the session once and reuse it for multiple inferences
268
402
5.**Use FP16**: Enable `useFP16` on NNAPI for faster inference with acceptable accuracy loss
269
403
270
-
## Troubleshooting
404
+
## Exports
271
405
272
-
### Android Build Issues
406
+
The library exports the following:
273
407
274
-
If you encounter duplicate library errors, ensure your `android/app/build.gradle` has:
0 commit comments