react-native-executorch 0.3.3 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -13
- package/android/build.gradle +1 -1
- package/android/src/main/java/com/swmansion/rnexecutorch/ETModule.kt +1 -2
- package/android/src/main/java/com/swmansion/rnexecutorch/ImageSegmentation.kt +58 -0
- package/android/src/main/java/com/swmansion/rnexecutorch/LLM.kt +13 -49
- package/android/src/main/java/com/swmansion/rnexecutorch/RnExecutorchPackage.kt +37 -0
- package/android/src/main/java/com/swmansion/rnexecutorch/StyleTransfer.kt +1 -1
- package/android/src/main/java/com/swmansion/rnexecutorch/TextEmbeddings.kt +51 -0
- package/android/src/main/java/com/swmansion/rnexecutorch/Tokenizer.kt +86 -0
- package/android/src/main/java/com/swmansion/rnexecutorch/models/BaseModel.kt +3 -4
- package/android/src/main/java/com/swmansion/rnexecutorch/models/TextEmbeddings/TextEmbeddingsModel.kt +48 -0
- package/android/src/main/java/com/swmansion/rnexecutorch/models/TextEmbeddings/TextEmbeddingsUtils.kt +37 -0
- package/android/src/main/java/com/swmansion/rnexecutorch/models/classification/ClassificationModel.kt +1 -0
- package/android/src/main/java/com/swmansion/rnexecutorch/models/imageSegmentation/Constants.kt +26 -0
- package/android/src/main/java/com/swmansion/rnexecutorch/models/imageSegmentation/ImageSegmentationModel.kt +142 -0
- package/android/src/main/java/com/swmansion/rnexecutorch/models/ocr/utils/RecognizerUtils.kt +3 -0
- package/android/src/main/java/com/swmansion/rnexecutorch/models/{StyleTransferModel.kt → styleTransfer/StyleTransferModel.kt} +2 -1
- package/android/src/main/java/com/swmansion/rnexecutorch/utils/ArrayUtils.kt +0 -8
- package/android/src/main/java/com/swmansion/rnexecutorch/{models/classification/Utils.kt → utils/Numerical.kt} +1 -1
- package/ios/ExecutorchLib.xcframework/Info.plist +4 -4
- package/ios/ExecutorchLib.xcframework/ios-arm64/ExecutorchLib.framework/ExecutorchLib +0 -0
- package/ios/ExecutorchLib.xcframework/ios-arm64/ExecutorchLib.framework/Headers/HuggingFaceTokenizer.h +14 -0
- package/ios/ExecutorchLib.xcframework/ios-arm64/ExecutorchLib.framework/Headers/LLaMARunner.h +1 -23
- package/ios/ExecutorchLib.xcframework/ios-arm64/ExecutorchLib.framework/Info.plist +0 -0
- package/ios/ExecutorchLib.xcframework/ios-arm64-simulator/ExecutorchLib.framework/ExecutorchLib +0 -0
- package/ios/ExecutorchLib.xcframework/ios-arm64-simulator/ExecutorchLib.framework/Headers/HuggingFaceTokenizer.h +14 -0
- package/ios/ExecutorchLib.xcframework/ios-arm64-simulator/ExecutorchLib.framework/Headers/LLaMARunner.h +1 -23
- package/ios/ExecutorchLib.xcframework/ios-arm64-simulator/ExecutorchLib.framework/Info.plist +0 -0
- package/ios/RnExecutorch/Classification.mm +15 -18
- package/ios/RnExecutorch/ETModule.mm +6 -5
- package/ios/RnExecutorch/ImageSegmentation.h +5 -0
- package/ios/RnExecutorch/ImageSegmentation.mm +60 -0
- package/ios/RnExecutorch/LLM.mm +12 -53
- package/ios/RnExecutorch/OCR.mm +39 -43
- package/ios/RnExecutorch/ObjectDetection.mm +20 -20
- package/ios/RnExecutorch/SpeechToText.mm +6 -7
- package/ios/RnExecutorch/StyleTransfer.mm +16 -19
- package/ios/RnExecutorch/TextEmbeddings.h +5 -0
- package/ios/RnExecutorch/TextEmbeddings.mm +62 -0
- package/ios/RnExecutorch/Tokenizer.h +5 -0
- package/ios/RnExecutorch/Tokenizer.mm +83 -0
- package/ios/RnExecutorch/VerticalOCR.mm +36 -36
- package/ios/RnExecutorch/models/BaseModel.h +2 -5
- package/ios/RnExecutorch/models/BaseModel.mm +5 -15
- package/ios/RnExecutorch/models/classification/ClassificationModel.mm +2 -3
- package/ios/RnExecutorch/models/classification/Constants.mm +0 -1
- package/ios/RnExecutorch/models/image_segmentation/Constants.h +4 -0
- package/ios/RnExecutorch/models/image_segmentation/Constants.mm +8 -0
- package/ios/RnExecutorch/models/image_segmentation/ImageSegmentationModel.h +10 -0
- package/ios/RnExecutorch/models/image_segmentation/ImageSegmentationModel.mm +146 -0
- package/ios/RnExecutorch/models/object_detection/SSDLiteLargeModel.mm +1 -2
- package/ios/RnExecutorch/models/ocr/Detector.h +0 -2
- package/ios/RnExecutorch/models/ocr/Detector.mm +2 -1
- package/ios/RnExecutorch/models/ocr/RecognitionHandler.h +5 -4
- package/ios/RnExecutorch/models/ocr/RecognitionHandler.mm +9 -26
- package/ios/RnExecutorch/models/ocr/Recognizer.mm +1 -2
- package/ios/RnExecutorch/models/ocr/VerticalDetector.h +0 -2
- package/ios/RnExecutorch/models/ocr/VerticalDetector.mm +2 -1
- package/ios/RnExecutorch/models/ocr/utils/OCRUtils.mm +0 -1
- package/ios/RnExecutorch/models/stt/Moonshine.mm +1 -6
- package/ios/RnExecutorch/models/stt/SpeechToTextBaseModel.mm +7 -11
- package/ios/RnExecutorch/models/stt/Whisper.mm +0 -5
- package/ios/RnExecutorch/models/{StyleTransferModel.h → style_transfer/StyleTransferModel.h} +1 -1
- package/ios/RnExecutorch/models/{StyleTransferModel.mm → style_transfer/StyleTransferModel.mm} +2 -3
- package/ios/RnExecutorch/models/text_embeddings/TextEmbeddingsModel.h +15 -0
- package/ios/RnExecutorch/models/text_embeddings/TextEmbeddingsModel.mm +45 -0
- package/ios/RnExecutorch/models/text_embeddings/TextEmbeddingsUtils.h +8 -0
- package/ios/RnExecutorch/models/text_embeddings/TextEmbeddingsUtils.mm +49 -0
- package/ios/RnExecutorch/utils/Conversions.h +15 -0
- package/ios/RnExecutorch/utils/ImageProcessor.h +0 -1
- package/ios/RnExecutorch/{models/classification/Utils.h → utils/Numerical.h} +0 -2
- package/ios/RnExecutorch/{models/classification/Utils.mm → utils/Numerical.mm} +0 -2
- package/ios/RnExecutorch/utils/ObjectDetectionUtils.mm +0 -2
- package/ios/RnExecutorch/utils/SFFT.mm +1 -1
- package/ios/RnExecutorch/utils/ScalarType.h +0 -2
- package/lib/module/Error.js +16 -2
- package/lib/module/Error.js.map +1 -1
- package/lib/module/constants/{llamaDefaults.js → llmDefaults.js} +7 -3
- package/lib/module/constants/llmDefaults.js.map +1 -0
- package/lib/module/constants/modelUrls.js +88 -27
- package/lib/module/constants/modelUrls.js.map +1 -1
- package/lib/module/constants/ocr/models.js +290 -0
- package/lib/module/constants/ocr/models.js.map +1 -0
- package/lib/module/constants/ocr/symbols.js +137 -2
- package/lib/module/constants/ocr/symbols.js.map +1 -1
- package/lib/module/constants/sttDefaults.js +50 -25
- package/lib/module/constants/sttDefaults.js.map +1 -1
- package/lib/module/controllers/LLMController.js +205 -0
- package/lib/module/controllers/LLMController.js.map +1 -0
- package/lib/module/controllers/OCRController.js +5 -10
- package/lib/module/controllers/OCRController.js.map +1 -1
- package/lib/module/controllers/SpeechToTextController.js +225 -122
- package/lib/module/controllers/SpeechToTextController.js.map +1 -1
- package/lib/module/controllers/VerticalOCRController.js +6 -10
- package/lib/module/controllers/VerticalOCRController.js.map +1 -1
- package/lib/module/hooks/computer_vision/useClassification.js +8 -23
- package/lib/module/hooks/computer_vision/useClassification.js.map +1 -1
- package/lib/module/hooks/computer_vision/useImageSegmentation.js +13 -0
- package/lib/module/hooks/computer_vision/useImageSegmentation.js.map +1 -0
- package/lib/module/hooks/computer_vision/useOCR.js +11 -6
- package/lib/module/hooks/computer_vision/useOCR.js.map +1 -1
- package/lib/module/hooks/computer_vision/useObjectDetection.js +8 -23
- package/lib/module/hooks/computer_vision/useObjectDetection.js.map +1 -1
- package/lib/module/hooks/computer_vision/useStyleTransfer.js +8 -23
- package/lib/module/hooks/computer_vision/useStyleTransfer.js.map +1 -1
- package/lib/module/hooks/computer_vision/useVerticalOCR.js +10 -7
- package/lib/module/hooks/computer_vision/useVerticalOCR.js.map +1 -1
- package/lib/module/hooks/general/useExecutorchModule.js +8 -36
- package/lib/module/hooks/general/useExecutorchModule.js.map +1 -1
- package/lib/module/hooks/natural_language_processing/useLLM.js +54 -63
- package/lib/module/hooks/natural_language_processing/useLLM.js.map +1 -1
- package/lib/module/hooks/natural_language_processing/useSpeechToText.js +15 -11
- package/lib/module/hooks/natural_language_processing/useSpeechToText.js.map +1 -1
- package/lib/module/hooks/natural_language_processing/useTextEmbeddings.js +14 -0
- package/lib/module/hooks/natural_language_processing/useTextEmbeddings.js.map +1 -0
- package/lib/module/hooks/natural_language_processing/useTokenizer.js +54 -0
- package/lib/module/hooks/natural_language_processing/useTokenizer.js.map +1 -0
- package/lib/module/hooks/useModule.js +18 -62
- package/lib/module/hooks/useModule.js.map +1 -1
- package/lib/module/index.js +16 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/modules/BaseModule.js +9 -10
- package/lib/module/modules/BaseModule.js.map +1 -1
- package/lib/module/modules/computer_vision/ClassificationModule.js +8 -5
- package/lib/module/modules/computer_vision/ClassificationModule.js.map +1 -1
- package/lib/module/modules/computer_vision/ImageSegmentationModule.js +28 -0
- package/lib/module/modules/computer_vision/ImageSegmentationModule.js.map +1 -0
- package/lib/module/modules/computer_vision/ObjectDetectionModule.js +8 -5
- package/lib/module/modules/computer_vision/ObjectDetectionModule.js.map +1 -1
- package/lib/module/modules/computer_vision/StyleTransferModule.js +8 -5
- package/lib/module/modules/computer_vision/StyleTransferModule.js.map +1 -1
- package/lib/module/modules/general/ExecutorchModule.js +8 -5
- package/lib/module/modules/general/ExecutorchModule.js.map +1 -1
- package/lib/module/modules/natural_language_processing/LLMModule.js +46 -27
- package/lib/module/modules/natural_language_processing/LLMModule.js.map +1 -1
- package/lib/module/modules/natural_language_processing/SpeechToTextModule.js +8 -5
- package/lib/module/modules/natural_language_processing/SpeechToTextModule.js.map +1 -1
- package/lib/module/modules/natural_language_processing/TextEmbeddingsModule.js +14 -0
- package/lib/module/modules/natural_language_processing/TextEmbeddingsModule.js.map +1 -0
- package/lib/module/modules/natural_language_processing/TokenizerModule.js +26 -0
- package/lib/module/modules/natural_language_processing/TokenizerModule.js.map +1 -0
- package/lib/module/native/NativeClassification.js.map +1 -1
- package/lib/module/native/NativeImageSegmentation.js +5 -0
- package/lib/module/native/NativeImageSegmentation.js.map +1 -0
- package/lib/module/native/NativeLLM.js.map +1 -1
- package/lib/module/native/NativeTextEmbeddings.js +5 -0
- package/lib/module/native/NativeTextEmbeddings.js.map +1 -0
- package/lib/module/native/NativeTokenizer.js +5 -0
- package/lib/module/native/NativeTokenizer.js.map +1 -0
- package/lib/module/native/RnExecutorchModules.js +18 -113
- package/lib/module/native/RnExecutorchModules.js.map +1 -1
- package/lib/module/types/common.js.map +1 -1
- package/lib/module/types/imageSegmentation.js +29 -0
- package/lib/module/types/imageSegmentation.js.map +1 -0
- package/lib/module/types/llm.js +7 -0
- package/lib/module/types/llm.js.map +1 -0
- package/lib/module/types/{object_detection.js → objectDetection.js} +1 -1
- package/lib/module/types/objectDetection.js.map +1 -0
- package/lib/module/types/ocr.js +2 -0
- package/lib/module/types/stt.js +82 -0
- package/lib/module/types/stt.js.map +1 -0
- package/lib/module/utils/ResourceFetcher.js +156 -0
- package/lib/module/utils/ResourceFetcher.js.map +1 -0
- package/lib/module/utils/llm.js +25 -0
- package/lib/module/utils/llm.js.map +1 -0
- package/lib/module/utils/stt.js +22 -0
- package/lib/module/utils/stt.js.map +1 -0
- package/lib/typescript/Error.d.ts +4 -1
- package/lib/typescript/Error.d.ts.map +1 -1
- package/lib/typescript/constants/{llamaDefaults.d.ts → llmDefaults.d.ts} +5 -5
- package/lib/typescript/constants/llmDefaults.d.ts.map +1 -0
- package/lib/typescript/constants/modelUrls.d.ts +74 -28
- package/lib/typescript/constants/modelUrls.d.ts.map +1 -1
- package/lib/typescript/constants/ocr/models.d.ts +285 -0
- package/lib/typescript/constants/ocr/models.d.ts.map +1 -0
- package/lib/typescript/constants/ocr/symbols.d.ts +73 -1
- package/lib/typescript/constants/ocr/symbols.d.ts.map +1 -1
- package/lib/typescript/constants/sttDefaults.d.ts +8 -13
- package/lib/typescript/constants/sttDefaults.d.ts.map +1 -1
- package/lib/typescript/controllers/LLMController.d.ts +46 -0
- package/lib/typescript/controllers/LLMController.d.ts.map +1 -0
- package/lib/typescript/controllers/OCRController.d.ts.map +1 -1
- package/lib/typescript/controllers/SpeechToTextController.d.ts +30 -16
- package/lib/typescript/controllers/SpeechToTextController.d.ts.map +1 -1
- package/lib/typescript/controllers/VerticalOCRController.d.ts +1 -1
- package/lib/typescript/controllers/VerticalOCRController.d.ts.map +1 -1
- package/lib/typescript/hooks/computer_vision/useClassification.d.ts +5 -5
- package/lib/typescript/hooks/computer_vision/useClassification.d.ts.map +1 -1
- package/lib/typescript/hooks/computer_vision/useImageSegmentation.d.ts +37 -0
- package/lib/typescript/hooks/computer_vision/useImageSegmentation.d.ts.map +1 -0
- package/lib/typescript/hooks/computer_vision/useOCR.d.ts +2 -1
- package/lib/typescript/hooks/computer_vision/useOCR.d.ts.map +1 -1
- package/lib/typescript/hooks/computer_vision/useObjectDetection.d.ts +5 -4
- package/lib/typescript/hooks/computer_vision/useObjectDetection.d.ts.map +1 -1
- package/lib/typescript/hooks/computer_vision/useStyleTransfer.d.ts +4 -2
- package/lib/typescript/hooks/computer_vision/useStyleTransfer.d.ts.map +1 -1
- package/lib/typescript/hooks/computer_vision/useVerticalOCR.d.ts +2 -1
- package/lib/typescript/hooks/computer_vision/useVerticalOCR.d.ts.map +1 -1
- package/lib/typescript/hooks/general/useExecutorchModule.d.ts +5 -6
- package/lib/typescript/hooks/general/useExecutorchModule.d.ts.map +1 -1
- package/lib/typescript/hooks/natural_language_processing/useLLM.d.ts +6 -6
- package/lib/typescript/hooks/natural_language_processing/useLLM.d.ts.map +1 -1
- package/lib/typescript/hooks/natural_language_processing/useSpeechToText.d.ts +7 -3
- package/lib/typescript/hooks/natural_language_processing/useSpeechToText.d.ts.map +1 -1
- package/lib/typescript/hooks/natural_language_processing/useTextEmbeddings.d.ts +13 -0
- package/lib/typescript/hooks/natural_language_processing/useTextEmbeddings.d.ts.map +1 -0
- package/lib/typescript/hooks/natural_language_processing/useTokenizer.d.ts +16 -0
- package/lib/typescript/hooks/natural_language_processing/useTokenizer.d.ts.map +1 -0
- package/lib/typescript/hooks/useModule.d.ts +11 -10
- package/lib/typescript/hooks/useModule.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +15 -2
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/modules/BaseModule.d.ts +4 -5
- package/lib/typescript/modules/BaseModule.d.ts.map +1 -1
- package/lib/typescript/modules/computer_vision/ClassificationModule.d.ts +7 -7
- package/lib/typescript/modules/computer_vision/ClassificationModule.d.ts.map +1 -1
- package/lib/typescript/modules/computer_vision/ImageSegmentationModule.d.ts +32 -0
- package/lib/typescript/modules/computer_vision/ImageSegmentationModule.d.ts.map +1 -0
- package/lib/typescript/modules/computer_vision/ObjectDetectionModule.d.ts +6 -5
- package/lib/typescript/modules/computer_vision/ObjectDetectionModule.d.ts.map +1 -1
- package/lib/typescript/modules/computer_vision/StyleTransferModule.d.ts +6 -5
- package/lib/typescript/modules/computer_vision/StyleTransferModule.d.ts.map +1 -1
- package/lib/typescript/modules/general/ExecutorchModule.d.ts +4 -3
- package/lib/typescript/modules/general/ExecutorchModule.d.ts.map +1 -1
- package/lib/typescript/modules/natural_language_processing/LLMModule.d.ts +19 -5
- package/lib/typescript/modules/natural_language_processing/LLMModule.d.ts.map +1 -1
- package/lib/typescript/modules/natural_language_processing/SpeechToTextModule.d.ts +7 -4
- package/lib/typescript/modules/natural_language_processing/SpeechToTextModule.d.ts.map +1 -1
- package/lib/typescript/modules/natural_language_processing/TextEmbeddingsModule.d.ts +8 -0
- package/lib/typescript/modules/natural_language_processing/TextEmbeddingsModule.d.ts.map +1 -0
- package/lib/typescript/modules/natural_language_processing/TokenizerModule.d.ts +12 -0
- package/lib/typescript/modules/natural_language_processing/TokenizerModule.d.ts.map +1 -0
- package/lib/typescript/native/NativeClassification.d.ts.map +1 -1
- package/lib/typescript/native/NativeImageSegmentation.d.ts +10 -0
- package/lib/typescript/native/NativeImageSegmentation.d.ts.map +1 -0
- package/lib/typescript/native/NativeLLM.d.ts +3 -4
- package/lib/typescript/native/NativeLLM.d.ts.map +1 -1
- package/lib/typescript/native/NativeObjectDetection.d.ts +1 -1
- package/lib/typescript/native/NativeObjectDetection.d.ts.map +1 -1
- package/lib/typescript/native/NativeSpeechToText.d.ts +2 -2
- package/lib/typescript/native/NativeSpeechToText.d.ts.map +1 -1
- package/lib/typescript/native/NativeTextEmbeddings.d.ts +8 -0
- package/lib/typescript/native/NativeTextEmbeddings.d.ts.map +1 -0
- package/lib/typescript/native/NativeTokenizer.d.ts +12 -0
- package/lib/typescript/native/NativeTokenizer.d.ts.map +1 -0
- package/lib/typescript/native/RnExecutorchModules.d.ts +18 -41
- package/lib/typescript/native/RnExecutorchModules.d.ts.map +1 -1
- package/lib/typescript/types/common.d.ts +1 -26
- package/lib/typescript/types/common.d.ts.map +1 -1
- package/lib/typescript/types/imageSegmentation.d.ts +25 -0
- package/lib/typescript/types/imageSegmentation.d.ts.map +1 -0
- package/lib/typescript/types/llm.d.ts +38 -0
- package/lib/typescript/types/llm.d.ts.map +1 -0
- package/lib/typescript/types/{object_detection.d.ts → objectDetection.d.ts} +1 -1
- package/lib/typescript/types/objectDetection.d.ts.map +1 -0
- package/lib/typescript/types/ocr.d.ts +2 -1
- package/lib/typescript/types/ocr.d.ts.map +1 -1
- package/lib/typescript/types/stt.d.ts +91 -0
- package/lib/typescript/types/stt.d.ts.map +1 -0
- package/lib/typescript/utils/ResourceFetcher.d.ts +17 -0
- package/lib/typescript/utils/ResourceFetcher.d.ts.map +1 -0
- package/lib/typescript/utils/llm.d.ts +3 -0
- package/lib/typescript/utils/llm.d.ts.map +1 -0
- package/lib/typescript/utils/stt.d.ts +2 -0
- package/lib/typescript/utils/stt.d.ts.map +1 -0
- package/package.json +13 -49
- package/react-native-executorch.podspec +1 -1
- package/src/Error.ts +16 -3
- package/src/constants/llmDefaults.ts +14 -0
- package/src/constants/modelUrls.ts +146 -39
- package/src/constants/ocr/models.ts +453 -0
- package/src/constants/ocr/symbols.ts +147 -3
- package/src/constants/sttDefaults.ts +55 -37
- package/src/controllers/LLMController.ts +286 -0
- package/src/controllers/OCRController.ts +14 -28
- package/src/controllers/SpeechToTextController.ts +318 -180
- package/src/controllers/VerticalOCRController.ts +17 -32
- package/src/hooks/computer_vision/useClassification.ts +11 -26
- package/src/hooks/computer_vision/useImageSegmentation.ts +18 -0
- package/src/hooks/computer_vision/useOCR.ts +17 -5
- package/src/hooks/computer_vision/useObjectDetection.ts +10 -24
- package/src/hooks/computer_vision/useStyleTransfer.ts +9 -25
- package/src/hooks/computer_vision/useVerticalOCR.ts +11 -4
- package/src/hooks/general/useExecutorchModule.ts +10 -50
- package/src/hooks/natural_language_processing/useLLM.ts +80 -97
- package/src/hooks/natural_language_processing/useSpeechToText.ts +39 -12
- package/src/hooks/natural_language_processing/useTextEmbeddings.ts +18 -0
- package/src/hooks/natural_language_processing/useTokenizer.ts +61 -0
- package/src/hooks/useModule.ts +32 -92
- package/src/index.tsx +16 -2
- package/src/modules/BaseModule.ts +16 -26
- package/src/modules/computer_vision/ClassificationModule.ts +13 -8
- package/src/modules/computer_vision/ImageSegmentationModule.ts +39 -0
- package/src/modules/computer_vision/ObjectDetectionModule.ts +13 -8
- package/src/modules/computer_vision/StyleTransferModule.ts +13 -8
- package/src/modules/general/ExecutorchModule.ts +11 -6
- package/src/modules/natural_language_processing/LLMModule.ts +64 -51
- package/src/modules/natural_language_processing/SpeechToTextModule.ts +25 -10
- package/src/modules/natural_language_processing/TextEmbeddingsModule.ts +18 -0
- package/src/modules/natural_language_processing/TokenizerModule.ts +34 -0
- package/src/native/NativeClassification.ts +0 -1
- package/src/native/NativeImageSegmentation.ts +14 -0
- package/src/native/NativeLLM.ts +3 -10
- package/src/native/NativeObjectDetection.ts +1 -1
- package/src/native/NativeSpeechToText.ts +2 -2
- package/src/native/NativeTextEmbeddings.ts +9 -0
- package/src/native/NativeTokenizer.ts +13 -0
- package/src/native/RnExecutorchModules.ts +54 -234
- package/src/types/common.ts +1 -44
- package/src/types/imageSegmentation.ts +25 -0
- package/src/types/llm.ts +57 -0
- package/src/types/ocr.ts +3 -1
- package/src/types/stt.ts +93 -0
- package/src/utils/ResourceFetcher.ts +196 -0
- package/src/utils/llm.ts +34 -0
- package/src/utils/stt.ts +28 -0
- package/android/src/main/java/com/swmansion/rnexecutorch/utils/llms/ConversationManager.kt +0 -68
- package/ios/ExecutorchLib.xcframework/ios-arm64-simulator/ExecutorchLib.framework/_CodeSignature/CodeResources +0 -124
- package/ios/RnExecutorch/utils/llms/Constants.h +0 -6
- package/ios/RnExecutorch/utils/llms/Constants.mm +0 -23
- package/ios/RnExecutorch/utils/llms/ConversationManager.h +0 -26
- package/ios/RnExecutorch/utils/llms/ConversationManager.mm +0 -71
- package/lib/module/constants/llamaDefaults.js.map +0 -1
- package/lib/module/modules/computer_vision/BaseCVModule.js +0 -14
- package/lib/module/modules/computer_vision/BaseCVModule.js.map +0 -1
- package/lib/module/types/object_detection.js.map +0 -1
- package/lib/module/utils/fetchResource.js +0 -93
- package/lib/module/utils/fetchResource.js.map +0 -1
- package/lib/module/utils/listDownloadedResources.js +0 -13
- package/lib/module/utils/listDownloadedResources.js.map +0 -1
- package/lib/typescript/constants/llamaDefaults.d.ts.map +0 -1
- package/lib/typescript/modules/computer_vision/BaseCVModule.d.ts +0 -9
- package/lib/typescript/modules/computer_vision/BaseCVModule.d.ts.map +0 -1
- package/lib/typescript/types/object_detection.d.ts.map +0 -1
- package/lib/typescript/utils/fetchResource.d.ts +0 -3
- package/lib/typescript/utils/fetchResource.d.ts.map +0 -1
- package/lib/typescript/utils/listDownloadedResources.d.ts +0 -3
- package/lib/typescript/utils/listDownloadedResources.d.ts.map +0 -1
- package/src/constants/llamaDefaults.ts +0 -9
- package/src/modules/computer_vision/BaseCVModule.ts +0 -22
- package/src/utils/fetchResource.ts +0 -106
- package/src/utils/listDownloadedResources.ts +0 -12
- /package/src/types/{object_detection.ts → objectDetection.ts} +0 -0
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react';
|
|
1
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
2
2
|
import { SpeechToTextController } from '../../controllers/SpeechToTextController';
|
|
3
3
|
import { ResourceSource } from '../../types/common';
|
|
4
|
+
import { STREAMING_ACTION } from '../../constants/sttDefaults';
|
|
5
|
+
import { AvailableModels, SpeechToTextLanguage } from '../../types/stt';
|
|
4
6
|
|
|
5
7
|
interface SpeechToTextModule {
|
|
6
8
|
isReady: boolean;
|
|
@@ -10,8 +12,14 @@ interface SpeechToTextModule {
|
|
|
10
12
|
configureStreaming: SpeechToTextController['configureStreaming'];
|
|
11
13
|
error: Error | undefined;
|
|
12
14
|
transcribe: (
|
|
13
|
-
input: number[]
|
|
15
|
+
input: number[],
|
|
16
|
+
audioLanguage?: SpeechToTextLanguage
|
|
14
17
|
) => ReturnType<SpeechToTextController['transcribe']>;
|
|
18
|
+
streamingTranscribe: (
|
|
19
|
+
streamAction: STREAMING_ACTION,
|
|
20
|
+
input?: number[],
|
|
21
|
+
audioLanguage?: SpeechToTextLanguage
|
|
22
|
+
) => ReturnType<SpeechToTextController['streamingTranscribe']>;
|
|
15
23
|
}
|
|
16
24
|
|
|
17
25
|
export const useSpeechToText = ({
|
|
@@ -22,8 +30,9 @@ export const useSpeechToText = ({
|
|
|
22
30
|
overlapSeconds,
|
|
23
31
|
windowSize,
|
|
24
32
|
streamingConfig,
|
|
33
|
+
preventLoad = false,
|
|
25
34
|
}: {
|
|
26
|
-
modelName:
|
|
35
|
+
modelName: AvailableModels;
|
|
27
36
|
encoderSource?: ResourceSource;
|
|
28
37
|
decoderSource?: ResourceSource;
|
|
29
38
|
tokenizerSource?: ResourceSource;
|
|
@@ -36,6 +45,7 @@ export const useSpeechToText = ({
|
|
|
36
45
|
streamingConfig?: ConstructorParameters<
|
|
37
46
|
typeof SpeechToTextController
|
|
38
47
|
>['0']['streamingConfig'];
|
|
48
|
+
preventLoad?: boolean;
|
|
39
49
|
}): SpeechToTextModule => {
|
|
40
50
|
const [sequence, setSequence] = useState<string>('');
|
|
41
51
|
const [isReady, setIsReady] = useState(false);
|
|
@@ -43,20 +53,22 @@ export const useSpeechToText = ({
|
|
|
43
53
|
const [isGenerating, setIsGenerating] = useState(false);
|
|
44
54
|
const [error, setError] = useState<Error | undefined>();
|
|
45
55
|
|
|
46
|
-
const
|
|
56
|
+
const model = useMemo(
|
|
47
57
|
() =>
|
|
48
58
|
new SpeechToTextController({
|
|
49
59
|
transcribeCallback: setSequence,
|
|
50
60
|
isReadyCallback: setIsReady,
|
|
51
61
|
isGeneratingCallback: setIsGenerating,
|
|
52
62
|
onErrorCallback: setError,
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
streamingConfig: streamingConfig,
|
|
57
|
-
})
|
|
63
|
+
modelDownloadProgressCallback: setDownloadProgress,
|
|
64
|
+
}),
|
|
65
|
+
[]
|
|
58
66
|
);
|
|
59
67
|
|
|
68
|
+
useEffect(() => {
|
|
69
|
+
model.configureStreaming(overlapSeconds, windowSize, streamingConfig);
|
|
70
|
+
}, [model, overlapSeconds, windowSize, streamingConfig]);
|
|
71
|
+
|
|
60
72
|
useEffect(() => {
|
|
61
73
|
const loadModel = async () => {
|
|
62
74
|
await model.loadModel(
|
|
@@ -66,8 +78,17 @@ export const useSpeechToText = ({
|
|
|
66
78
|
tokenizerSource
|
|
67
79
|
);
|
|
68
80
|
};
|
|
69
|
-
|
|
70
|
-
|
|
81
|
+
if (!preventLoad) {
|
|
82
|
+
loadModel();
|
|
83
|
+
}
|
|
84
|
+
}, [
|
|
85
|
+
model,
|
|
86
|
+
modelName,
|
|
87
|
+
encoderSource,
|
|
88
|
+
decoderSource,
|
|
89
|
+
tokenizerSource,
|
|
90
|
+
preventLoad,
|
|
91
|
+
]);
|
|
71
92
|
|
|
72
93
|
return {
|
|
73
94
|
isReady,
|
|
@@ -76,6 +97,12 @@ export const useSpeechToText = ({
|
|
|
76
97
|
configureStreaming: model.configureStreaming,
|
|
77
98
|
sequence,
|
|
78
99
|
error,
|
|
79
|
-
transcribe: (waveform: number[]) =>
|
|
100
|
+
transcribe: (waveform: number[], audioLanguage?: SpeechToTextLanguage) =>
|
|
101
|
+
model.transcribe(waveform, audioLanguage),
|
|
102
|
+
streamingTranscribe: (
|
|
103
|
+
streamAction: STREAMING_ACTION,
|
|
104
|
+
waveform?: number[],
|
|
105
|
+
audioLanguage?: SpeechToTextLanguage
|
|
106
|
+
) => model.streamingTranscribe(streamAction, waveform, audioLanguage),
|
|
80
107
|
};
|
|
81
108
|
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { TextEmbeddingsModule } from '../../modules/natural_language_processing/TextEmbeddingsModule';
|
|
2
|
+
import { ResourceSource } from '../../types/common';
|
|
3
|
+
import { useModule } from '../useModule';
|
|
4
|
+
|
|
5
|
+
export const useTextEmbeddings = ({
|
|
6
|
+
modelSource,
|
|
7
|
+
tokenizerSource,
|
|
8
|
+
preventLoad = false,
|
|
9
|
+
}: {
|
|
10
|
+
modelSource: ResourceSource;
|
|
11
|
+
tokenizerSource: ResourceSource;
|
|
12
|
+
preventLoad?: boolean;
|
|
13
|
+
}) =>
|
|
14
|
+
useModule({
|
|
15
|
+
module: TextEmbeddingsModule,
|
|
16
|
+
loadArgs: [modelSource, tokenizerSource],
|
|
17
|
+
preventLoad,
|
|
18
|
+
});
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import { TokenizerModule } from '../../modules/natural_language_processing/TokenizerModule';
|
|
3
|
+
import { ResourceSource } from '../../types/common';
|
|
4
|
+
import { ETError, getError } from '../../Error';
|
|
5
|
+
|
|
6
|
+
export const useTokenizer = ({
|
|
7
|
+
tokenizerSource,
|
|
8
|
+
preventLoad = false,
|
|
9
|
+
}: {
|
|
10
|
+
tokenizerSource: ResourceSource;
|
|
11
|
+
preventLoad?: boolean;
|
|
12
|
+
}) => {
|
|
13
|
+
const [error, setError] = useState<null | string>(null);
|
|
14
|
+
const [isReady, setIsReady] = useState(false);
|
|
15
|
+
const [isGenerating, setIsGenerating] = useState(false);
|
|
16
|
+
const [downloadProgress, setDownloadProgress] = useState(0);
|
|
17
|
+
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
const loadModule = async () => {
|
|
20
|
+
try {
|
|
21
|
+
setIsReady(false);
|
|
22
|
+
TokenizerModule.onDownloadProgress(setDownloadProgress);
|
|
23
|
+
await TokenizerModule.load(tokenizerSource);
|
|
24
|
+
setIsReady(true);
|
|
25
|
+
} catch (err) {
|
|
26
|
+
setError((err as Error).message);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
if (!preventLoad) {
|
|
30
|
+
loadModule();
|
|
31
|
+
}
|
|
32
|
+
}, [tokenizerSource, preventLoad]);
|
|
33
|
+
|
|
34
|
+
const stateWrapper = <T extends (...args: any[]) => Promise<any>>(fn: T) => {
|
|
35
|
+
const boundFn = fn.bind(TokenizerModule);
|
|
36
|
+
|
|
37
|
+
return async (...args: Parameters<T>): Promise<ReturnType<T>> => {
|
|
38
|
+
if (!isReady) throw new Error(getError(ETError.ModuleNotLoaded));
|
|
39
|
+
if (isGenerating) throw new Error(getError(ETError.ModelGenerating));
|
|
40
|
+
|
|
41
|
+
setIsGenerating(true);
|
|
42
|
+
try {
|
|
43
|
+
return await boundFn(...args);
|
|
44
|
+
} finally {
|
|
45
|
+
setIsGenerating(false);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
error,
|
|
52
|
+
isReady,
|
|
53
|
+
isGenerating,
|
|
54
|
+
downloadProgress,
|
|
55
|
+
decode: stateWrapper(TokenizerModule.decode),
|
|
56
|
+
encode: stateWrapper(TokenizerModule.encode),
|
|
57
|
+
getVocabSize: stateWrapper(TokenizerModule.getVocabSize),
|
|
58
|
+
idToToken: stateWrapper(TokenizerModule.idToToken),
|
|
59
|
+
tokenToId: stateWrapper(TokenizerModule.tokenToId),
|
|
60
|
+
};
|
|
61
|
+
};
|
package/src/hooks/useModule.ts
CHANGED
|
@@ -1,124 +1,64 @@
|
|
|
1
1
|
import { useEffect, useState } from 'react';
|
|
2
|
-
import { fetchResource } from '../utils/fetchResource';
|
|
3
2
|
import { ETError, getError } from '../Error';
|
|
4
|
-
import { ETInput, Module } from '../types/common';
|
|
5
|
-
import { _ETModule } from '../native/RnExecutorchModules';
|
|
6
|
-
import { getTypeIdentifier } from '../types/common';
|
|
7
3
|
|
|
8
|
-
interface
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
interface Module {
|
|
5
|
+
load: (...args: any[]) => Promise<void>;
|
|
6
|
+
forward: (...input: any[]) => Promise<any>;
|
|
7
|
+
onDownloadProgress: (cb: (progress: number) => void) => void;
|
|
11
8
|
}
|
|
12
9
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
10
|
+
export const useModule = <
|
|
11
|
+
M extends Module,
|
|
12
|
+
LoadArgs extends Parameters<M['load']>,
|
|
13
|
+
ForwardArgs extends Parameters<M['forward']>,
|
|
14
|
+
ForwardReturn extends Awaited<ReturnType<M['forward']>>,
|
|
15
|
+
>({
|
|
16
|
+
module,
|
|
17
|
+
loadArgs,
|
|
18
|
+
preventLoad = false,
|
|
19
|
+
}: {
|
|
20
|
+
module: M;
|
|
21
|
+
loadArgs: LoadArgs;
|
|
22
|
+
preventLoad?: boolean;
|
|
23
|
+
}) => {
|
|
26
24
|
const [error, setError] = useState<null | string>(null);
|
|
27
25
|
const [isReady, setIsReady] = useState(false);
|
|
28
26
|
const [isGenerating, setIsGenerating] = useState(false);
|
|
29
27
|
const [downloadProgress, setDownloadProgress] = useState(0);
|
|
30
28
|
|
|
31
29
|
useEffect(() => {
|
|
32
|
-
const
|
|
33
|
-
if (!modelSource) return;
|
|
34
|
-
|
|
30
|
+
const loadModule = async () => {
|
|
35
31
|
try {
|
|
36
32
|
setIsReady(false);
|
|
37
|
-
|
|
38
|
-
await module.
|
|
33
|
+
module.onDownloadProgress(setDownloadProgress);
|
|
34
|
+
await module.load(...loadArgs);
|
|
39
35
|
setIsReady(true);
|
|
40
|
-
} catch (
|
|
41
|
-
setError(
|
|
36
|
+
} catch (err) {
|
|
37
|
+
setError((err as Error).message);
|
|
42
38
|
}
|
|
43
39
|
};
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}, [modelSource, module]);
|
|
47
|
-
|
|
48
|
-
const forwardImage = async (input: string) => {
|
|
49
|
-
if (!isReady) {
|
|
50
|
-
throw new Error(getError(ETError.ModuleNotLoaded));
|
|
51
|
-
}
|
|
52
|
-
if (isGenerating) {
|
|
53
|
-
throw new Error(getError(ETError.ModelGenerating));
|
|
40
|
+
if (!preventLoad) {
|
|
41
|
+
loadModule();
|
|
54
42
|
}
|
|
43
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
44
|
+
}, [...loadArgs, preventLoad]);
|
|
55
45
|
|
|
46
|
+
const forward = async (...input: ForwardArgs): Promise<ForwardReturn> => {
|
|
47
|
+
if (!isReady) throw new Error(getError(ETError.ModuleNotLoaded));
|
|
48
|
+
if (isGenerating) throw new Error(getError(ETError.ModelGenerating));
|
|
56
49
|
try {
|
|
57
50
|
setIsGenerating(true);
|
|
58
|
-
|
|
59
|
-
return output;
|
|
60
|
-
} catch (e) {
|
|
61
|
-
throw new Error(getError(e));
|
|
51
|
+
return await module.forward(...input);
|
|
62
52
|
} finally {
|
|
63
53
|
setIsGenerating(false);
|
|
64
54
|
}
|
|
65
55
|
};
|
|
66
56
|
|
|
67
|
-
const forwardETInput = async (
|
|
68
|
-
input: ETInput[] | ETInput,
|
|
69
|
-
shape: number[][] | number[]
|
|
70
|
-
) => {
|
|
71
|
-
if (!isReady) {
|
|
72
|
-
throw new Error(getError(ETError.ModuleNotLoaded));
|
|
73
|
-
}
|
|
74
|
-
if (isGenerating) {
|
|
75
|
-
throw new Error(getError(ETError.ModelGenerating));
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// Since the native module expects an array of inputs and an array of shapes,
|
|
79
|
-
// if the user provides a single ETInput, we want to "unsqueeze" the array so
|
|
80
|
-
// the data is properly processed on the native side
|
|
81
|
-
if (!Array.isArray(input)) {
|
|
82
|
-
input = [input];
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
if (!Array.isArray(shape[0])) {
|
|
86
|
-
shape = [shape] as number[][];
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
let inputTypeIdentifiers: any[] = [];
|
|
90
|
-
let modelInputs: any[] = [];
|
|
91
|
-
|
|
92
|
-
for (let idx = 0; idx < input.length; idx++) {
|
|
93
|
-
let currentInputTypeIdentifier = getTypeIdentifier(input[idx] as ETInput);
|
|
94
|
-
if (currentInputTypeIdentifier === -1) {
|
|
95
|
-
throw new Error(getError(ETError.InvalidArgument));
|
|
96
|
-
}
|
|
97
|
-
inputTypeIdentifiers.push(currentInputTypeIdentifier);
|
|
98
|
-
modelInputs.push([...(input[idx] as ETInput)]);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
try {
|
|
102
|
-
setIsGenerating(true);
|
|
103
|
-
const output = await module.forward(
|
|
104
|
-
modelInputs,
|
|
105
|
-
shape,
|
|
106
|
-
inputTypeIdentifiers
|
|
107
|
-
);
|
|
108
|
-
setIsGenerating(false);
|
|
109
|
-
return output;
|
|
110
|
-
} catch (e) {
|
|
111
|
-
setIsGenerating(false);
|
|
112
|
-
throw new Error(getError(e));
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
|
|
116
57
|
return {
|
|
117
58
|
error,
|
|
118
59
|
isReady,
|
|
119
60
|
isGenerating,
|
|
120
61
|
downloadProgress,
|
|
121
|
-
|
|
122
|
-
forwardImage,
|
|
62
|
+
forward,
|
|
123
63
|
};
|
|
124
64
|
};
|
package/src/index.tsx
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
|
+
import { SpeechToTextLanguage } from './types/stt';
|
|
2
|
+
|
|
1
3
|
// hooks
|
|
2
4
|
export * from './hooks/computer_vision/useClassification';
|
|
3
5
|
export * from './hooks/computer_vision/useObjectDetection';
|
|
4
6
|
export * from './hooks/computer_vision/useStyleTransfer';
|
|
7
|
+
export * from './hooks/computer_vision/useImageSegmentation';
|
|
5
8
|
export * from './hooks/computer_vision/useOCR';
|
|
6
9
|
export * from './hooks/computer_vision/useVerticalOCR';
|
|
7
10
|
|
|
8
11
|
export * from './hooks/natural_language_processing/useLLM';
|
|
9
12
|
export * from './hooks/natural_language_processing/useSpeechToText';
|
|
13
|
+
export * from './hooks/natural_language_processing/useTextEmbeddings';
|
|
14
|
+
export * from './hooks/natural_language_processing/useTokenizer';
|
|
10
15
|
|
|
11
16
|
export * from './hooks/general/useExecutorchModule';
|
|
12
17
|
|
|
@@ -14,20 +19,29 @@ export * from './hooks/general/useExecutorchModule';
|
|
|
14
19
|
export * from './modules/computer_vision/ClassificationModule';
|
|
15
20
|
export * from './modules/computer_vision/ObjectDetectionModule';
|
|
16
21
|
export * from './modules/computer_vision/StyleTransferModule';
|
|
22
|
+
export * from './modules/computer_vision/ImageSegmentationModule';
|
|
17
23
|
export * from './modules/computer_vision/OCRModule';
|
|
18
24
|
export * from './modules/computer_vision/VerticalOCRModule';
|
|
19
25
|
|
|
20
26
|
export * from './modules/natural_language_processing/LLMModule';
|
|
21
27
|
export * from './modules/natural_language_processing/SpeechToTextModule';
|
|
28
|
+
export * from './modules/natural_language_processing/TextEmbeddingsModule';
|
|
29
|
+
export * from './modules/natural_language_processing/TokenizerModule';
|
|
22
30
|
|
|
23
31
|
export * from './modules/general/ExecutorchModule';
|
|
24
32
|
|
|
25
33
|
// utils
|
|
26
|
-
export * from './utils/
|
|
34
|
+
export * from './utils/ResourceFetcher';
|
|
27
35
|
|
|
28
36
|
// types
|
|
29
|
-
export * from './types/
|
|
37
|
+
export * from './types/objectDetection';
|
|
30
38
|
export * from './types/ocr';
|
|
39
|
+
export * from './types/imageSegmentation';
|
|
40
|
+
export * from './types/llm';
|
|
41
|
+
export { SpeechToTextLanguage };
|
|
31
42
|
|
|
32
43
|
// constants
|
|
33
44
|
export * from './constants/modelUrls';
|
|
45
|
+
export * from './constants/ocr/models';
|
|
46
|
+
export * from './constants/llmDefaults';
|
|
47
|
+
export { STREAMING_ACTION, MODES } from './constants/sttDefaults';
|
|
@@ -1,38 +1,28 @@
|
|
|
1
|
-
import {
|
|
2
|
-
_StyleTransferModule,
|
|
3
|
-
_ObjectDetectionModule,
|
|
4
|
-
_ClassificationModule,
|
|
5
|
-
_ETModule,
|
|
6
|
-
} from '../native/RnExecutorchModules';
|
|
7
|
-
import { fetchResource } from '../utils/fetchResource';
|
|
8
|
-
import { ResourceSource } from '../types/common';
|
|
1
|
+
import { ResourceFetcher } from '../utils/ResourceFetcher';
|
|
9
2
|
import { getError } from '../Error';
|
|
3
|
+
import { ResourceSource } from '../types/common';
|
|
10
4
|
|
|
11
5
|
export class BaseModule {
|
|
12
|
-
static
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
| _ClassificationModule
|
|
16
|
-
| _ETModule;
|
|
17
|
-
|
|
18
|
-
static onDownloadProgressCallback = (_downloadProgress: number) => {};
|
|
19
|
-
|
|
20
|
-
static async load(modelSource: ResourceSource) {
|
|
21
|
-
if (!modelSource) return;
|
|
6
|
+
protected static nativeModule: any;
|
|
7
|
+
static onDownloadProgressCallback: (downloadProgress: number) => void =
|
|
8
|
+
() => {};
|
|
22
9
|
|
|
10
|
+
static async load(...sources: ResourceSource[]): Promise<void> {
|
|
23
11
|
try {
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
12
|
+
const paths = await ResourceFetcher.fetchMultipleResources(
|
|
13
|
+
this.onDownloadProgressCallback,
|
|
14
|
+
...sources
|
|
27
15
|
);
|
|
28
|
-
await this.
|
|
29
|
-
} catch (
|
|
30
|
-
throw new Error(getError(
|
|
16
|
+
await this.nativeModule.loadModule(...paths);
|
|
17
|
+
} catch (error) {
|
|
18
|
+
throw new Error(getError(error));
|
|
31
19
|
}
|
|
32
20
|
}
|
|
33
21
|
|
|
34
|
-
static async forward(...
|
|
35
|
-
throw new Error(
|
|
22
|
+
protected static async forward(..._args: any[]): Promise<any> {
|
|
23
|
+
throw new Error(
|
|
24
|
+
'forward method is not implemented in the BaseModule class. Please implement it in the derived class.'
|
|
25
|
+
);
|
|
36
26
|
}
|
|
37
27
|
|
|
38
28
|
static onDownloadProgress(callback: (downloadProgress: number) => void) {
|
|
@@ -1,12 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { ClassificationNativeModule } from '../../native/RnExecutorchModules';
|
|
2
|
+
import { ResourceSource } from '../../types/common';
|
|
3
|
+
import { BaseModule } from '../BaseModule';
|
|
3
4
|
|
|
4
|
-
export class ClassificationModule extends
|
|
5
|
-
static
|
|
5
|
+
export class ClassificationModule extends BaseModule {
|
|
6
|
+
protected static override nativeModule = ClassificationNativeModule;
|
|
6
7
|
|
|
7
|
-
static async
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
static override async load(modelSource: ResourceSource) {
|
|
9
|
+
await super.load(modelSource);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
static override async forward(
|
|
13
|
+
input: string
|
|
14
|
+
): ReturnType<typeof ClassificationNativeModule.forward> {
|
|
15
|
+
return await this.nativeModule.forward(input);
|
|
11
16
|
}
|
|
12
17
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { BaseModule } from '../BaseModule';
|
|
2
|
+
import { getError } from '../../Error';
|
|
3
|
+
import { DeeplabLabel } from '../../types/imageSegmentation';
|
|
4
|
+
import { ResourceSource } from '../../types/common';
|
|
5
|
+
import { ImageSegmentationNativeModule } from '../../native/RnExecutorchModules';
|
|
6
|
+
|
|
7
|
+
export class ImageSegmentationModule extends BaseModule {
|
|
8
|
+
protected static override nativeModule = ImageSegmentationNativeModule;
|
|
9
|
+
|
|
10
|
+
static override async load(modelSource: ResourceSource) {
|
|
11
|
+
return await super.load(modelSource);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
static override async forward(
|
|
15
|
+
input: string,
|
|
16
|
+
classesOfInterest?: DeeplabLabel[],
|
|
17
|
+
resize?: boolean
|
|
18
|
+
) {
|
|
19
|
+
try {
|
|
20
|
+
const stringDict = await (this.nativeModule.forward(
|
|
21
|
+
input,
|
|
22
|
+
(classesOfInterest || []).map((label) => DeeplabLabel[label]),
|
|
23
|
+
resize || false
|
|
24
|
+
) as ReturnType<(typeof this.nativeModule)['forward']>);
|
|
25
|
+
|
|
26
|
+
let enumDict: { [key in DeeplabLabel]?: number[] } = {};
|
|
27
|
+
|
|
28
|
+
for (const key in stringDict) {
|
|
29
|
+
if (key in DeeplabLabel) {
|
|
30
|
+
const enumKey = DeeplabLabel[key as keyof typeof DeeplabLabel];
|
|
31
|
+
enumDict[enumKey] = stringDict[key];
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return enumDict;
|
|
35
|
+
} catch (e) {
|
|
36
|
+
throw new Error(getError(e));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -1,12 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { ObjectDetectionNativeModule } from '../../native/RnExecutorchModules';
|
|
2
|
+
import { ResourceSource } from '../../types/common';
|
|
3
|
+
import { BaseModule } from '../BaseModule';
|
|
3
4
|
|
|
4
|
-
export class ObjectDetectionModule extends
|
|
5
|
-
static
|
|
5
|
+
export class ObjectDetectionModule extends BaseModule {
|
|
6
|
+
protected static override nativeModule = ObjectDetectionNativeModule;
|
|
6
7
|
|
|
7
|
-
static async
|
|
8
|
-
return await
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
static override async load(modelSource: ResourceSource) {
|
|
9
|
+
return await super.load(modelSource);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
static override async forward(
|
|
13
|
+
input: string
|
|
14
|
+
): ReturnType<typeof this.nativeModule.forward> {
|
|
15
|
+
return await this.nativeModule.forward(input);
|
|
11
16
|
}
|
|
12
17
|
}
|
|
@@ -1,12 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { StyleTransferNativeModule } from '../../native/RnExecutorchModules';
|
|
2
|
+
import { ResourceSource } from '../../types/common';
|
|
3
|
+
import { BaseModule } from '../BaseModule';
|
|
3
4
|
|
|
4
|
-
export class StyleTransferModule extends
|
|
5
|
-
static
|
|
5
|
+
export class StyleTransferModule extends BaseModule {
|
|
6
|
+
protected static override nativeModule = StyleTransferNativeModule;
|
|
6
7
|
|
|
7
|
-
static async
|
|
8
|
-
return await
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
static override async load(modelSource: ResourceSource) {
|
|
9
|
+
return await super.load(modelSource);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
static override async forward(
|
|
13
|
+
input: string
|
|
14
|
+
): ReturnType<typeof this.nativeModule.forward> {
|
|
15
|
+
return await this.nativeModule.forward(input);
|
|
11
16
|
}
|
|
12
17
|
}
|
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
import { BaseModule } from '../BaseModule';
|
|
2
1
|
import { ETError, getError } from '../../Error';
|
|
3
|
-
import {
|
|
2
|
+
import { ETModuleNativeModule } from '../../native/RnExecutorchModules';
|
|
3
|
+
import { ResourceSource } from '../../types/common';
|
|
4
4
|
import { ETInput } from '../../types/common';
|
|
5
5
|
import { getTypeIdentifier } from '../../types/common';
|
|
6
|
+
import { BaseModule } from '../BaseModule';
|
|
6
7
|
|
|
7
8
|
export class ExecutorchModule extends BaseModule {
|
|
8
|
-
static
|
|
9
|
+
protected static override nativeModule = ETModuleNativeModule;
|
|
10
|
+
|
|
11
|
+
static override async load(modelSource: ResourceSource) {
|
|
12
|
+
return await super.load(modelSource);
|
|
13
|
+
}
|
|
9
14
|
|
|
10
|
-
static async forward(input: ETInput[] | ETInput, shape: number[][]) {
|
|
15
|
+
static override async forward(input: ETInput[] | ETInput, shape: number[][]) {
|
|
11
16
|
if (!Array.isArray(input)) {
|
|
12
17
|
input = [input];
|
|
13
18
|
}
|
|
@@ -25,7 +30,7 @@ export class ExecutorchModule extends BaseModule {
|
|
|
25
30
|
}
|
|
26
31
|
|
|
27
32
|
try {
|
|
28
|
-
return await this.
|
|
33
|
+
return await this.nativeModule.forward(
|
|
29
34
|
modelInputs,
|
|
30
35
|
shape,
|
|
31
36
|
inputTypeIdentifiers
|
|
@@ -37,7 +42,7 @@ export class ExecutorchModule extends BaseModule {
|
|
|
37
42
|
|
|
38
43
|
static async loadMethod(methodName: string) {
|
|
39
44
|
try {
|
|
40
|
-
await this.
|
|
45
|
+
await this.nativeModule.loadMethod(methodName);
|
|
41
46
|
} catch (e) {
|
|
42
47
|
throw new Error(getError(e));
|
|
43
48
|
}
|