Documentation Index
Fetch the complete documentation index at: https://mintlify.com/software-mansion/react-native-executorch/llms.txt
Use this file to discover all available pages before exploring further.
Overview
ClassificationModule provides a class-based interface for image classification tasks. It loads classification models and performs inference on images to predict categories with confidence scores.
When to Use
UseClassificationModule when:
- You need to manage the model lifecycle manually
- You’re working outside React components
- You need multiple classification model instances
- You want direct control over loading and inference
useClassification hook when:
- Building React components
- You want automatic lifecycle management and cleanup
- You prefer declarative state management with loading states
- You need React state integration
Extends
ClassificationModule extends BaseModule, inheriting core functionality like generateFromFrame() for real-time camera frame processing.
Constructor
Example
Methods
load()
Parameters
Resource location of the model binary. Can be a URL, file path, or require statement.
Optional callback to monitor download progress (value between 0 and 1).
Example
forward()
Parameters
The image source to classify. Can be:
- A file path (e.g.,
'/path/to/image.jpg') - A URI (e.g.,
'file:///path/to/image.jpg'or'https://example.com/image.jpg') - A Base64-encoded string (e.g.,
'data:image/jpeg;base64,...')
Returns
An object mapping category names to confidence scores (0-1).Example
delete()
Example
generateFromFrame()
load(), making it worklet-compatible and safe to call from VisionCamera’s frame processor thread.
Parameters
Frame data object with either
nativeBuffer (zero-copy) or data (ArrayBuffer). Include width and height.Additional model-specific arguments.
Returns
Classification results in the same format asforward().
Example
Complete Example
Performance Considerations
- For real-time camera processing, use
generateFromFrame()with VisionCamera’s zero-copy path - For single images, use
forward()with appropriate image sources - Always call
delete()when done to free memory - Consider using the
useClassificationhook for React components to get automatic cleanup
See Also
- BaseModule - Base class with shared functionality
- useClassification Hook - React hook alternative
- ResourceSource Type
- Frame Type