react-native-executorch 0.7.0 → 0.7.1

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.
Files changed (46) hide show
  1. package/common/rnexecutorch/TokenizerModule.cpp +3 -2
  2. package/common/rnexecutorch/TokenizerModule.h +1 -1
  3. package/package.json +2 -1
  4. package/third-party/android/libs/executorch/arm64-v8a/libexecutorch.so +0 -0
  5. package/third-party/android/libs/executorch/x86_64/libexecutorch.so +0 -0
  6. package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/bpe_model.h +84 -0
  7. package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/bpe_tokenizer_base.h +6 -87
  8. package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/hf_tokenizer.h +28 -176
  9. package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/map_utils.h +174 -0
  10. package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/model.h +151 -0
  11. package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/normalizer.h +55 -1
  12. package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/padding.h +112 -0
  13. package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/post_processor.h +101 -42
  14. package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/pre_tokenizer.h +25 -9
  15. package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/token_decoder.h +33 -6
  16. package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/tokenizer.h +2 -2
  17. package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/truncation.h +92 -0
  18. package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/wordpiece_model.h +74 -0
  19. package/third-party/ios/ExecutorchLib.xcframework/ios-arm64/ExecutorchLib.framework/ExecutorchLib +0 -0
  20. package/third-party/ios/ExecutorchLib.xcframework/ios-arm64-simulator/ExecutorchLib.framework/ExecutorchLib +0 -0
  21. package/common/rnexecutorch/tests/CMakeLists.txt +0 -253
  22. package/common/rnexecutorch/tests/README.md +0 -73
  23. package/common/rnexecutorch/tests/integration/BaseModelTest.cpp +0 -207
  24. package/common/rnexecutorch/tests/integration/BaseModelTests.h +0 -120
  25. package/common/rnexecutorch/tests/integration/ClassificationTest.cpp +0 -117
  26. package/common/rnexecutorch/tests/integration/ImageEmbeddingsTest.cpp +0 -122
  27. package/common/rnexecutorch/tests/integration/ImageSegmentationTest.cpp +0 -152
  28. package/common/rnexecutorch/tests/integration/LLMTest.cpp +0 -155
  29. package/common/rnexecutorch/tests/integration/OCRTest.cpp +0 -128
  30. package/common/rnexecutorch/tests/integration/ObjectDetectionTest.cpp +0 -135
  31. package/common/rnexecutorch/tests/integration/SpeechToTextTest.cpp +0 -97
  32. package/common/rnexecutorch/tests/integration/StyleTransferTest.cpp +0 -112
  33. package/common/rnexecutorch/tests/integration/TextEmbeddingsTest.cpp +0 -164
  34. package/common/rnexecutorch/tests/integration/TextToImageTest.cpp +0 -149
  35. package/common/rnexecutorch/tests/integration/TokenizerModuleTest.cpp +0 -98
  36. package/common/rnexecutorch/tests/integration/VerticalOCRTest.cpp +0 -238
  37. package/common/rnexecutorch/tests/integration/VoiceActivityDetectionTest.cpp +0 -99
  38. package/common/rnexecutorch/tests/integration/assets/test_audio_float.raw +0 -0
  39. package/common/rnexecutorch/tests/integration/assets/we_are_software_mansion.jpg +0 -0
  40. package/common/rnexecutorch/tests/integration/libs/libfbjni.so +0 -0
  41. package/common/rnexecutorch/tests/integration/stubs/jsi_stubs.cpp +0 -45
  42. package/common/rnexecutorch/tests/integration/utils/TestUtils.h +0 -36
  43. package/common/rnexecutorch/tests/run_tests.sh +0 -333
  44. package/common/rnexecutorch/tests/unit/FileUtilsTest.cpp +0 -32
  45. package/common/rnexecutorch/tests/unit/LogTest.cpp +0 -529
  46. package/common/rnexecutorch/tests/unit/NumericalTest.cpp +0 -107
@@ -1,152 +0,0 @@
1
- #include <gtest/gtest.h>
2
- #include <rnexecutorch/Error.h>
3
- #include <rnexecutorch/models/image_segmentation/Constants.h>
4
- #include <rnexecutorch/models/image_segmentation/ImageSegmentation.h>
5
- #include <string>
6
- #include <vector>
7
-
8
- #include <executorch/extension/tensor/tensor.h>
9
-
10
- using namespace rnexecutorch;
11
- using namespace rnexecutorch::models::image_segmentation;
12
- using executorch::extension::make_tensor_ptr;
13
- using executorch::extension::TensorPtr;
14
- using executorch::runtime::EValue;
15
-
16
- constexpr auto kValidImageSegmentationModelPath = "deeplabV3_xnnpack_fp32.pte";
17
-
18
- // Test fixture for tests that need dummy input data
19
- class ImageSegmentationForwardTest : public ::testing::Test {
20
- protected:
21
- void SetUp() override {
22
- model = std::make_unique<ImageSegmentation>(
23
- kValidImageSegmentationModelPath, nullptr);
24
- auto shapes = model->getAllInputShapes("forward");
25
- ASSERT_FALSE(shapes.empty());
26
- shape = shapes[0];
27
-
28
- size_t numElements = 1;
29
- for (auto dim : shape) {
30
- numElements *= dim;
31
- }
32
- dummyData = std::vector<float>(numElements, 0.5f);
33
-
34
- sizes = std::vector<int32_t>(shape.begin(), shape.end());
35
- inputTensor =
36
- make_tensor_ptr(sizes, dummyData.data(), exec_aten::ScalarType::Float);
37
- }
38
-
39
- std::unique_ptr<ImageSegmentation> model;
40
- std::vector<int32_t> shape;
41
- std::vector<float> dummyData;
42
- std::vector<int32_t> sizes;
43
- TensorPtr inputTensor;
44
- };
45
-
46
- TEST(ImageSegmentationCtorTests, InvalidPathThrows) {
47
- EXPECT_THROW(ImageSegmentation("this_file_does_not_exist.pte", nullptr),
48
- RnExecutorchError);
49
- }
50
-
51
- TEST(ImageSegmentationCtorTests, ValidPathDoesntThrow) {
52
- EXPECT_NO_THROW(ImageSegmentation(kValidImageSegmentationModelPath, nullptr));
53
- }
54
-
55
- TEST_F(ImageSegmentationForwardTest, ForwardWithValidTensorSucceeds) {
56
- auto result = model->forward(EValue(inputTensor));
57
- EXPECT_TRUE(result.ok());
58
- }
59
-
60
- TEST_F(ImageSegmentationForwardTest, ForwardOutputHasCorrectDimensions) {
61
- auto result = model->forward(EValue(inputTensor));
62
- ASSERT_TRUE(result.ok());
63
-
64
- auto &outputs = result.get();
65
- ASSERT_FALSE(outputs.empty());
66
-
67
- auto outputTensor = outputs[0].toTensor();
68
- EXPECT_EQ(outputTensor.dim(), 4); // NCHW format
69
- }
70
-
71
- TEST_F(ImageSegmentationForwardTest, ForwardOutputHas21Classes) {
72
- auto result = model->forward(EValue(inputTensor));
73
- ASSERT_TRUE(result.ok());
74
-
75
- auto &outputs = result.get();
76
- ASSERT_FALSE(outputs.empty());
77
-
78
- auto outputTensor = outputs[0].toTensor();
79
- EXPECT_EQ(outputTensor.size(1), 21); // DeepLabV3 has 21 classes
80
- }
81
-
82
- TEST_F(ImageSegmentationForwardTest, MultipleForwardsWork) {
83
- auto result1 = model->forward(EValue(inputTensor));
84
- EXPECT_TRUE(result1.ok());
85
-
86
- auto result2 = model->forward(EValue(inputTensor));
87
- EXPECT_TRUE(result2.ok());
88
- }
89
-
90
- TEST_F(ImageSegmentationForwardTest, ForwardAfterUnloadThrows) {
91
- model->unload();
92
- EXPECT_THROW((void)model->forward(EValue(inputTensor)), RnExecutorchError);
93
- }
94
-
95
- TEST(ImageSegmentationInheritedTests, GetInputShapeWorks) {
96
- ImageSegmentation model(kValidImageSegmentationModelPath, nullptr);
97
- auto shape = model.getInputShape("forward", 0);
98
- EXPECT_EQ(shape.size(), 4);
99
- EXPECT_EQ(shape[0], 1); // Batch size
100
- EXPECT_EQ(shape[1], 3); // RGB channels
101
- }
102
-
103
- TEST(ImageSegmentationInheritedTests, GetAllInputShapesWorks) {
104
- ImageSegmentation model(kValidImageSegmentationModelPath, nullptr);
105
- auto shapes = model.getAllInputShapes("forward");
106
- EXPECT_FALSE(shapes.empty());
107
- }
108
-
109
- TEST(ImageSegmentationInheritedTests, GetMethodMetaWorks) {
110
- ImageSegmentation model(kValidImageSegmentationModelPath, nullptr);
111
- auto result = model.getMethodMeta("forward");
112
- EXPECT_TRUE(result.ok());
113
- }
114
-
115
- TEST(ImageSegmentationInheritedTests, GetMemoryLowerBoundReturnsPositive) {
116
- ImageSegmentation model(kValidImageSegmentationModelPath, nullptr);
117
- EXPECT_GT(model.getMemoryLowerBound(), 0u);
118
- }
119
-
120
- TEST(ImageSegmentationInheritedTests, InputShapeIsSquare) {
121
- ImageSegmentation model(kValidImageSegmentationModelPath, nullptr);
122
- auto shape = model.getInputShape("forward", 0);
123
- EXPECT_EQ(shape[2], shape[3]); // Height == Width for DeepLabV3
124
- }
125
-
126
- TEST(ImageSegmentationConstantsTests, ClassLabelsHas21Entries) {
127
- EXPECT_EQ(constants::kDeeplabV3Resnet50Labels.size(), 21u);
128
- }
129
-
130
- TEST(ImageSegmentationConstantsTests, ClassLabelsContainExpectedClasses) {
131
- auto &labels = constants::kDeeplabV3Resnet50Labels;
132
- bool hasBackground = false;
133
- bool hasPerson = false;
134
- bool hasCat = false;
135
- bool hasDog = false;
136
-
137
- for (const auto &label : labels) {
138
- if (label == "BACKGROUND")
139
- hasBackground = true;
140
- if (label == "PERSON")
141
- hasPerson = true;
142
- if (label == "CAT")
143
- hasCat = true;
144
- if (label == "DOG")
145
- hasDog = true;
146
- }
147
-
148
- EXPECT_TRUE(hasBackground);
149
- EXPECT_TRUE(hasPerson);
150
- EXPECT_TRUE(hasCat);
151
- EXPECT_TRUE(hasDog);
152
- }
@@ -1,155 +0,0 @@
1
- #include "BaseModelTests.h"
2
- #include <gtest/gtest.h>
3
- #include <memory>
4
- #include <string>
5
-
6
- #include <ReactCommon/CallInvoker.h>
7
- #include <rnexecutorch/Error.h>
8
- #include <rnexecutorch/models/llm/LLM.h>
9
-
10
- using namespace rnexecutorch;
11
- using namespace rnexecutorch::models::llm;
12
- using namespace model_tests;
13
-
14
- constexpr auto kValidModelPath = "smolLm2_135M_8da4w.pte";
15
- constexpr auto kValidTokenizerPath = "smollm_tokenizer.json";
16
- constexpr auto kSystemPrompt = "You are a helpful assistant. Assist the user "
17
- "to the best of your abilities.";
18
-
19
- // Forward declaration from jsi_stubs.cpp
20
- namespace rnexecutorch {
21
- std::shared_ptr<facebook::react::CallInvoker> createMockCallInvoker();
22
- }
23
-
24
- // Helper to format prompt in ChatML format for SmolLM2
25
- std::string formatChatML(const std::string &systemPrompt,
26
- const std::string &userMessage) {
27
- return "<|im_start|>system\n" + systemPrompt + "<|im_end|>\n" +
28
- "<|im_start|>user\n" + userMessage + "<|im_end|>\n" +
29
- "<|im_start|>assistant\n";
30
- }
31
-
32
- // ============================================================================
33
- // Common tests via typed test suite
34
- // ============================================================================
35
- namespace model_tests {
36
- template <> struct ModelTraits<LLM> {
37
- using ModelType = LLM;
38
-
39
- static ModelType createValid() {
40
- return ModelType(kValidModelPath, kValidTokenizerPath,
41
- rnexecutorch::createMockCallInvoker());
42
- }
43
-
44
- static ModelType createInvalid() {
45
- return ModelType("nonexistent.pte", kValidTokenizerPath,
46
- rnexecutorch::createMockCallInvoker());
47
- }
48
-
49
- static void callGenerate(ModelType &model) {
50
- std::string prompt = formatChatML(kSystemPrompt, "Hello");
51
- (void)model.generate(prompt, nullptr);
52
- }
53
- };
54
- } // namespace model_tests
55
-
56
- using LLMTypes = ::testing::Types<LLM>;
57
- INSTANTIATE_TYPED_TEST_SUITE_P(LLM, CommonModelTest, LLMTypes);
58
-
59
- // ============================================================================
60
- // LLM-specific fixture tests
61
- // ============================================================================
62
- class LLMTest : public ::testing::Test {
63
- protected:
64
- std::shared_ptr<facebook::react::CallInvoker> mockInvoker_;
65
-
66
- void SetUp() override { mockInvoker_ = createMockCallInvoker(); }
67
- };
68
-
69
- TEST(LLMCtorTests, InvalidTokenizerPathThrows) {
70
- EXPECT_THROW(LLM(kValidModelPath, "nonexistent_tokenizer.json",
71
- createMockCallInvoker()),
72
- RnExecutorchError);
73
- }
74
-
75
- TEST_F(LLMTest, GetGeneratedTokenCountInitiallyZero) {
76
- LLM model(kValidModelPath, kValidTokenizerPath, mockInvoker_);
77
- EXPECT_EQ(model.getGeneratedTokenCount(), 0);
78
- }
79
-
80
- TEST_F(LLMTest, SetTemperature) {
81
- LLM model(kValidModelPath, kValidTokenizerPath, mockInvoker_);
82
- // Should not throw for valid values
83
- EXPECT_NO_THROW(model.setTemperature(0.5f));
84
- EXPECT_NO_THROW(model.setTemperature(1.0f));
85
- EXPECT_NO_THROW(model.setTemperature(0.0f));
86
- }
87
-
88
- TEST_F(LLMTest, SetTemperatureNegativeThrows) {
89
- LLM model(kValidModelPath, kValidTokenizerPath, mockInvoker_);
90
- EXPECT_THROW(model.setTemperature(-0.1f), RnExecutorchError);
91
- }
92
-
93
- TEST_F(LLMTest, SetTopp) {
94
- LLM model(kValidModelPath, kValidTokenizerPath, mockInvoker_);
95
- EXPECT_NO_THROW(model.setTopp(0.9f));
96
- EXPECT_NO_THROW(model.setTopp(0.5f));
97
- EXPECT_NO_THROW(model.setTopp(1.0f));
98
- }
99
-
100
- TEST_F(LLMTest, SetToppInvalidThrows) {
101
- LLM model(kValidModelPath, kValidTokenizerPath, mockInvoker_);
102
- EXPECT_THROW(model.setTopp(-0.1f), RnExecutorchError);
103
- EXPECT_THROW(model.setTopp(1.1f), RnExecutorchError);
104
- }
105
-
106
- TEST_F(LLMTest, SetCountInterval) {
107
- LLM model(kValidModelPath, kValidTokenizerPath, mockInvoker_);
108
- EXPECT_NO_THROW(model.setCountInterval(5));
109
- EXPECT_NO_THROW(model.setCountInterval(10));
110
- }
111
-
112
- TEST_F(LLMTest, SetTimeInterval) {
113
- LLM model(kValidModelPath, kValidTokenizerPath, mockInvoker_);
114
- EXPECT_NO_THROW(model.setTimeInterval(100));
115
- EXPECT_NO_THROW(model.setTimeInterval(500));
116
- }
117
-
118
- TEST_F(LLMTest, InterruptThrowsWhenUnloaded) {
119
- LLM model(kValidModelPath, kValidTokenizerPath, mockInvoker_);
120
- model.unload();
121
- EXPECT_THROW(model.interrupt(), RnExecutorchError);
122
- }
123
-
124
- TEST_F(LLMTest, SettersThrowWhenUnloaded) {
125
- LLM model(kValidModelPath, kValidTokenizerPath, mockInvoker_);
126
- model.unload();
127
- // All setters should throw when model is unloaded
128
- EXPECT_THROW(model.setTemperature(0.5f), RnExecutorchError);
129
- EXPECT_THROW(model.setTopp(0.9f), RnExecutorchError);
130
- EXPECT_THROW(model.setCountInterval(5), RnExecutorchError);
131
- EXPECT_THROW(model.setTimeInterval(100), RnExecutorchError);
132
- }
133
-
134
- TEST_F(LLMTest, GenerateProducesValidOutput) {
135
- LLM model(kValidModelPath, kValidTokenizerPath, mockInvoker_);
136
- model.setTemperature(0.0f);
137
- std::string prompt =
138
- formatChatML(kSystemPrompt, "Repeat exactly this: `naszponcilem testy`");
139
- std::string output = model.generate(prompt, nullptr);
140
- EXPECT_EQ(output, "`naszponcilem testy`<|im_end|>");
141
- }
142
-
143
- TEST_F(LLMTest, GenerateUpdatesTokenCount) {
144
- LLM model(kValidModelPath, kValidTokenizerPath, mockInvoker_);
145
- EXPECT_EQ(model.getGeneratedTokenCount(), 0);
146
- std::string prompt =
147
- formatChatML(kSystemPrompt, "Repeat exactly this: 'naszponcilem testy'");
148
- model.generate(prompt, nullptr);
149
- EXPECT_GT(model.getGeneratedTokenCount(), 0);
150
- }
151
-
152
- TEST_F(LLMTest, EmptyPromptThrows) {
153
- LLM model(kValidModelPath, kValidTokenizerPath, mockInvoker_);
154
- EXPECT_THROW((void)model.generate("", nullptr), RnExecutorchError);
155
- }
@@ -1,128 +0,0 @@
1
- #include "BaseModelTests.h"
2
- #include <gtest/gtest.h>
3
- #include <rnexecutorch/Error.h>
4
- #include <rnexecutorch/models/ocr/OCR.h>
5
- #include <string>
6
-
7
- using namespace rnexecutorch;
8
- using namespace rnexecutorch::models::ocr;
9
- using namespace model_tests;
10
-
11
- namespace rnexecutorch {
12
- std::shared_ptr<facebook::react::CallInvoker> createMockCallInvoker();
13
- }
14
-
15
- constexpr auto kValidDetectorPath = "xnnpack_craft_quantized.pte";
16
- constexpr auto kValidRecognizerPath = "xnnpack_crnn_english.pte";
17
- constexpr auto kValidTestImagePath =
18
- "file:///data/local/tmp/rnexecutorch_tests/we_are_software_mansion.jpg";
19
-
20
- // English alphabet symbols (must match alphabets.english from symbols.ts)
21
- const std::string ENGLISH_SYMBOLS =
22
- "0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ "
23
- "\xE2\x82\xAC" // Euro sign (€)
24
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
25
-
26
- // ============================================================================
27
- // Common tests via typed test suite
28
- // ============================================================================
29
- namespace model_tests {
30
- template <> struct ModelTraits<OCR> {
31
- using ModelType = OCR;
32
-
33
- static ModelType createValid() {
34
- return ModelType(kValidDetectorPath, kValidRecognizerPath, ENGLISH_SYMBOLS,
35
- rnexecutorch::createMockCallInvoker());
36
- }
37
-
38
- static ModelType createInvalid() {
39
- return ModelType("nonexistent.pte", kValidRecognizerPath, ENGLISH_SYMBOLS,
40
- rnexecutorch::createMockCallInvoker());
41
- }
42
-
43
- static void callGenerate(ModelType &model) {
44
- (void)model.generate(kValidTestImagePath);
45
- }
46
- };
47
- } // namespace model_tests
48
-
49
- using OCRTypes = ::testing::Types<OCR>;
50
- INSTANTIATE_TYPED_TEST_SUITE_P(OCR, CommonModelTest, OCRTypes);
51
-
52
- // ============================================================================
53
- // Model-specific tests
54
- // ============================================================================
55
- TEST(OCRCtorTests, InvalidRecognizerPathThrows) {
56
- EXPECT_THROW(OCR(kValidDetectorPath, "nonexistent.pte", ENGLISH_SYMBOLS,
57
- createMockCallInvoker()),
58
- RnExecutorchError);
59
- }
60
-
61
- TEST(OCRCtorTests, EmptySymbolsThrows) {
62
- EXPECT_THROW(OCR(kValidDetectorPath, kValidRecognizerPath, "",
63
- createMockCallInvoker()),
64
- RnExecutorchError);
65
- }
66
-
67
- TEST(OCRGenerateTests, InvalidImagePathThrows) {
68
- OCR model(kValidDetectorPath, kValidRecognizerPath, ENGLISH_SYMBOLS,
69
- createMockCallInvoker());
70
- EXPECT_THROW((void)model.generate("nonexistent_image.jpg"),
71
- RnExecutorchError);
72
- }
73
-
74
- TEST(OCRGenerateTests, EmptyImagePathThrows) {
75
- OCR model(kValidDetectorPath, kValidRecognizerPath, ENGLISH_SYMBOLS,
76
- createMockCallInvoker());
77
- EXPECT_THROW((void)model.generate(""), RnExecutorchError);
78
- }
79
-
80
- TEST(OCRGenerateTests, MalformedURIThrows) {
81
- OCR model(kValidDetectorPath, kValidRecognizerPath, ENGLISH_SYMBOLS,
82
- createMockCallInvoker());
83
- EXPECT_THROW((void)model.generate("not_a_valid_uri://bad"),
84
- RnExecutorchError);
85
- }
86
-
87
- TEST(OCRGenerateTests, ValidImageReturnsResults) {
88
- OCR model(kValidDetectorPath, kValidRecognizerPath, ENGLISH_SYMBOLS,
89
- createMockCallInvoker());
90
- auto results = model.generate(kValidTestImagePath);
91
- // May or may not have detections depending on image content
92
- EXPECT_GE(results.size(), 0u);
93
- }
94
-
95
- TEST(OCRGenerateTests, DetectionsHaveValidBoundingBoxes) {
96
- OCR model(kValidDetectorPath, kValidRecognizerPath, ENGLISH_SYMBOLS,
97
- createMockCallInvoker());
98
- auto results = model.generate(kValidTestImagePath);
99
-
100
- for (const auto &detection : results) {
101
- // Each bbox should have 4 points
102
- EXPECT_EQ(detection.bbox.size(), 4u);
103
- for (const auto &point : detection.bbox) {
104
- EXPECT_GE(point.x, 0.0f);
105
- EXPECT_GE(point.y, 0.0f);
106
- }
107
- }
108
- }
109
-
110
- TEST(OCRGenerateTests, DetectionsHaveValidScores) {
111
- OCR model(kValidDetectorPath, kValidRecognizerPath, ENGLISH_SYMBOLS,
112
- createMockCallInvoker());
113
- auto results = model.generate(kValidTestImagePath);
114
-
115
- for (const auto &detection : results) {
116
- EXPECT_GE(detection.score, 0.0f);
117
- EXPECT_LE(detection.score, 1.0f);
118
- }
119
- }
120
-
121
- TEST(OCRGenerateTests, DetectionsHaveNonEmptyText) {
122
- OCR model(kValidDetectorPath, kValidRecognizerPath, ENGLISH_SYMBOLS,
123
- createMockCallInvoker());
124
- auto results = model.generate(kValidTestImagePath);
125
- for (const auto &detection : results) {
126
- EXPECT_FALSE(detection.text.empty());
127
- }
128
- }
@@ -1,135 +0,0 @@
1
- #include "BaseModelTests.h"
2
- #include <gtest/gtest.h>
3
- #include <rnexecutorch/Error.h>
4
- #include <rnexecutorch/models/object_detection/Constants.h>
5
- #include <rnexecutorch/models/object_detection/ObjectDetection.h>
6
-
7
- using namespace rnexecutorch;
8
- using namespace rnexecutorch::models::object_detection;
9
- using namespace model_tests;
10
-
11
- constexpr auto kValidObjectDetectionModelPath =
12
- "ssdlite320-mobilenetv3-large.pte";
13
- constexpr auto kValidTestImagePath =
14
- "file:///data/local/tmp/rnexecutorch_tests/test_image.jpg";
15
-
16
- // ============================================================================
17
- // Common tests via typed test suite
18
- // ============================================================================
19
- namespace model_tests {
20
- template <> struct ModelTraits<ObjectDetection> {
21
- using ModelType = ObjectDetection;
22
-
23
- static ModelType createValid() {
24
- return ModelType(kValidObjectDetectionModelPath, nullptr);
25
- }
26
-
27
- static ModelType createInvalid() {
28
- return ModelType("nonexistent.pte", nullptr);
29
- }
30
-
31
- static void callGenerate(ModelType &model) {
32
- (void)model.generate(kValidTestImagePath, 0.5);
33
- }
34
- };
35
- } // namespace model_tests
36
-
37
- using ObjectDetectionTypes = ::testing::Types<ObjectDetection>;
38
- INSTANTIATE_TYPED_TEST_SUITE_P(ObjectDetection, CommonModelTest,
39
- ObjectDetectionTypes);
40
-
41
- // ============================================================================
42
- // Model-specific tests
43
- // ============================================================================
44
- TEST(ObjectDetectionGenerateTests, InvalidImagePathThrows) {
45
- ObjectDetection model(kValidObjectDetectionModelPath, nullptr);
46
- EXPECT_THROW((void)model.generate("nonexistent_image.jpg", 0.5),
47
- RnExecutorchError);
48
- }
49
-
50
- TEST(ObjectDetectionGenerateTests, EmptyImagePathThrows) {
51
- ObjectDetection model(kValidObjectDetectionModelPath, nullptr);
52
- EXPECT_THROW((void)model.generate("", 0.5), RnExecutorchError);
53
- }
54
-
55
- TEST(ObjectDetectionGenerateTests, MalformedURIThrows) {
56
- ObjectDetection model(kValidObjectDetectionModelPath, nullptr);
57
- EXPECT_THROW((void)model.generate("not_a_valid_uri://bad", 0.5),
58
- RnExecutorchError);
59
- }
60
-
61
- TEST(ObjectDetectionGenerateTests, NegativeThresholdThrows) {
62
- ObjectDetection model(kValidObjectDetectionModelPath, nullptr);
63
- EXPECT_THROW((void)model.generate(kValidTestImagePath, -0.1),
64
- RnExecutorchError);
65
- }
66
-
67
- TEST(ObjectDetectionGenerateTests, ThresholdAboveOneThrows) {
68
- ObjectDetection model(kValidObjectDetectionModelPath, nullptr);
69
- EXPECT_THROW((void)model.generate(kValidTestImagePath, 1.1),
70
- RnExecutorchError);
71
- }
72
-
73
- TEST(ObjectDetectionGenerateTests, ValidImageReturnsResults) {
74
- ObjectDetection model(kValidObjectDetectionModelPath, nullptr);
75
- auto results = model.generate(kValidTestImagePath, 0.3);
76
- EXPECT_GE(results.size(), 0u);
77
- }
78
-
79
- TEST(ObjectDetectionGenerateTests, HighThresholdReturnsFewerResults) {
80
- ObjectDetection model(kValidObjectDetectionModelPath, nullptr);
81
- auto lowThresholdResults = model.generate(kValidTestImagePath, 0.1);
82
- auto highThresholdResults = model.generate(kValidTestImagePath, 0.9);
83
- EXPECT_GE(lowThresholdResults.size(), highThresholdResults.size());
84
- }
85
-
86
- TEST(ObjectDetectionGenerateTests, DetectionsHaveValidBoundingBoxes) {
87
- ObjectDetection model(kValidObjectDetectionModelPath, nullptr);
88
- auto results = model.generate(kValidTestImagePath, 0.3);
89
-
90
- for (const auto &detection : results) {
91
- EXPECT_LE(detection.x1, detection.x2);
92
- EXPECT_LE(detection.y1, detection.y2);
93
- EXPECT_GE(detection.x1, 0.0f);
94
- EXPECT_GE(detection.y1, 0.0f);
95
- }
96
- }
97
-
98
- TEST(ObjectDetectionGenerateTests, DetectionsHaveValidScores) {
99
- ObjectDetection model(kValidObjectDetectionModelPath, nullptr);
100
- auto results = model.generate(kValidTestImagePath, 0.3);
101
-
102
- for (const auto &detection : results) {
103
- EXPECT_GE(detection.score, 0.0f);
104
- EXPECT_LE(detection.score, 1.0f);
105
- }
106
- }
107
-
108
- TEST(ObjectDetectionGenerateTests, DetectionsHaveValidLabels) {
109
- ObjectDetection model(kValidObjectDetectionModelPath, nullptr);
110
- auto results = model.generate(kValidTestImagePath, 0.3);
111
-
112
- for (const auto &detection : results) {
113
- EXPECT_GE(detection.label, 0);
114
- }
115
- }
116
-
117
- TEST(ObjectDetectionInheritedTests, GetInputShapeWorks) {
118
- ObjectDetection model(kValidObjectDetectionModelPath, nullptr);
119
- auto shape = model.getInputShape("forward", 0);
120
- EXPECT_EQ(shape.size(), 4);
121
- EXPECT_EQ(shape[0], 1);
122
- EXPECT_EQ(shape[1], 3);
123
- }
124
-
125
- TEST(ObjectDetectionInheritedTests, GetAllInputShapesWorks) {
126
- ObjectDetection model(kValidObjectDetectionModelPath, nullptr);
127
- auto shapes = model.getAllInputShapes("forward");
128
- EXPECT_FALSE(shapes.empty());
129
- }
130
-
131
- TEST(ObjectDetectionInheritedTests, GetMethodMetaWorks) {
132
- ObjectDetection model(kValidObjectDetectionModelPath, nullptr);
133
- auto result = model.getMethodMeta("forward");
134
- EXPECT_TRUE(result.ok());
135
- }
@@ -1,97 +0,0 @@
1
- #include "BaseModelTests.h"
2
- #include "utils/TestUtils.h"
3
- #include <gtest/gtest.h>
4
- #include <rnexecutorch/Error.h>
5
- #include <rnexecutorch/models/speech_to_text/SpeechToText.h>
6
-
7
- using namespace rnexecutorch;
8
- using namespace rnexecutorch::models::speech_to_text;
9
- using namespace test_utils;
10
- using namespace model_tests;
11
-
12
- constexpr auto kValidEncoderPath = "whisper_tiny_en_encoder_xnnpack.pte";
13
- constexpr auto kValidDecoderPath = "whisper_tiny_en_decoder_xnnpack.pte";
14
- constexpr auto kValidTokenizerPath = "whisper_tokenizer.json";
15
-
16
- // ============================================================================
17
- // Common tests via typed test suite
18
- // ============================================================================
19
- namespace model_tests {
20
- template <> struct ModelTraits<SpeechToText> {
21
- using ModelType = SpeechToText;
22
-
23
- static ModelType createValid() {
24
- return ModelType(kValidEncoderPath, kValidDecoderPath, kValidTokenizerPath,
25
- nullptr);
26
- }
27
-
28
- static ModelType createInvalid() {
29
- return ModelType("nonexistent.pte", kValidDecoderPath, kValidTokenizerPath,
30
- nullptr);
31
- }
32
-
33
- static void callGenerate(ModelType &model) {
34
- auto audio = test_utils::loadAudioFromFile("test_audio_float.raw");
35
- (void)model.transcribe(audio, "en");
36
- }
37
- };
38
- } // namespace model_tests
39
-
40
- using SpeechToTextTypes = ::testing::Types<SpeechToText>;
41
- INSTANTIATE_TYPED_TEST_SUITE_P(SpeechToText, CommonModelTest,
42
- SpeechToTextTypes);
43
-
44
- // ============================================================================
45
- // Model-specific tests
46
- // ============================================================================
47
- TEST(S2TCtorTests, InvalidDecoderPathThrows) {
48
- EXPECT_THROW(SpeechToText(kValidEncoderPath, "nonexistent.pte",
49
- kValidTokenizerPath, nullptr),
50
- RnExecutorchError);
51
- }
52
-
53
- TEST(S2TCtorTests, InvalidTokenizerPathThrows) {
54
- EXPECT_THROW(SpeechToText(kValidEncoderPath, kValidDecoderPath,
55
- "nonexistent.json", nullptr),
56
- RnExecutorchError);
57
- }
58
-
59
- TEST(S2TEncodeTests, EncodeReturnsNonNull) {
60
- SpeechToText model(kValidEncoderPath, kValidDecoderPath, kValidTokenizerPath,
61
- nullptr);
62
- auto audio = loadAudioFromFile("test_audio_float.raw");
63
- ASSERT_FALSE(audio.empty());
64
- auto result = model.encode(audio);
65
- EXPECT_NE(result, nullptr);
66
- EXPECT_GT(result->size(), 0u);
67
- }
68
-
69
- TEST(S2TTranscribeTests, TranscribeReturnsValidChars) {
70
- SpeechToText model(kValidEncoderPath, kValidDecoderPath, kValidTokenizerPath,
71
- nullptr);
72
- auto audio = loadAudioFromFile("test_audio_float.raw");
73
- ASSERT_FALSE(audio.empty());
74
- auto result = model.transcribe(audio, "en");
75
- ASSERT_FALSE(result.empty());
76
- for (char c : result) {
77
- EXPECT_GE(static_cast<unsigned char>(c), 0);
78
- EXPECT_LE(static_cast<unsigned char>(c), 127);
79
- }
80
- }
81
-
82
- TEST(S2TTranscribeTests, EmptyResultOnSilence) {
83
- SpeechToText model(kValidEncoderPath, kValidDecoderPath, kValidTokenizerPath,
84
- nullptr);
85
- auto audio = generateSilence(16000 * 5);
86
- auto result = model.transcribe(audio, "en");
87
- EXPECT_TRUE(result.empty());
88
- }
89
-
90
- TEST(S2TTranscribeTests, InvalidLanguageThrows) {
91
- SpeechToText model(kValidEncoderPath, kValidDecoderPath, kValidTokenizerPath,
92
- nullptr);
93
- auto audio = loadAudioFromFile("test_audio_float.raw");
94
- ASSERT_FALSE(audio.empty());
95
- EXPECT_THROW((void)model.transcribe(audio, "invalid_language_code"),
96
- RnExecutorchError);
97
- }