Skip to content

Commit 836c7a2

Browse files
refactor: follow declaration order in VisionModel class
1 parent c5bf1fd commit 836c7a2

File tree

2 files changed

+24
-23
lines changed

2 files changed

+24
-23
lines changed

packages/react-native-executorch/common/rnexecutorch/models/VisionModel.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,23 @@ namespace rnexecutorch::models {
77

88
using namespace facebook;
99

10+
VisionModel::VisionModel(const std::string &modelSource,
11+
std::shared_ptr<react::CallInvoker> callInvoker)
12+
: BaseModel(modelSource, callInvoker) {}
13+
14+
void VisionModel::unload() noexcept {
15+
std::scoped_lock lock(inference_mutex_);
16+
BaseModel::unload();
17+
}
18+
19+
cv::Size VisionModel::modelInputSize() const {
20+
if (modelInputShape_.size() < 2) {
21+
return {0, 0};
22+
}
23+
return cv::Size(modelInputShape_[modelInputShape_.size() - 1],
24+
modelInputShape_[modelInputShape_.size() - 2]);
25+
}
26+
1027
cv::Mat VisionModel::extractFromFrame(jsi::Runtime &runtime,
1128
const jsi::Value &frameData) const {
1229
cv::Mat frame = ::rnexecutorch::utils::frameToMat(runtime, frameData);

packages/react-native-executorch/common/rnexecutorch/models/VisionModel.h

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,8 @@ namespace models {
4141
*/
4242
class VisionModel : public BaseModel {
4343
public:
44-
/**
45-
* @brief Construct a VisionModel with the same parameters as BaseModel
46-
*
47-
* VisionModel uses the same construction pattern as BaseModel, just adding
48-
* thread-safety on top.
49-
*/
5044
VisionModel(const std::string &modelSource,
51-
std::shared_ptr<react::CallInvoker> callInvoker)
52-
: BaseModel(modelSource, callInvoker) {}
45+
std::shared_ptr<react::CallInvoker> callInvoker);
5346

5447
virtual ~VisionModel() = default;
5548

@@ -62,12 +55,13 @@ class VisionModel : public BaseModel {
6255
* destroys module_ while generateFromFrame() is still executing on the
6356
* VisionCamera worklet thread.
6457
*/
65-
void unload() noexcept {
66-
std::scoped_lock lock(inference_mutex_);
67-
BaseModel::unload();
68-
}
58+
void unload() noexcept;
6959

7060
protected:
61+
/// Cached input tensor shape (getAllInputShapes()[0]).
62+
/// Set once by each subclass constructor to avoid per-frame metadata lookups.
63+
std::vector<int32_t> modelInputShape_;
64+
7165
/**
7266
* @brief Mutex to ensure thread-safe inference
7367
*
@@ -96,18 +90,8 @@ class VisionModel : public BaseModel {
9690
*/
9791
virtual cv::Mat preprocess(const cv::Mat &image) const;
9892

99-
/// Cached input tensor shape (getAllInputShapes()[0]).
100-
/// Set once by each subclass constructor to avoid per-frame metadata lookups.
101-
std::vector<int32_t> modelInputShape_;
102-
10393
/// Convenience accessor: spatial dimensions of the model input.
104-
cv::Size modelInputSize() const {
105-
if (modelInputShape_.size() < 2) {
106-
return {0, 0};
107-
}
108-
return cv::Size(modelInputShape_[modelInputShape_.size() - 1],
109-
modelInputShape_[modelInputShape_.size() - 2]);
110-
}
94+
cv::Size modelInputSize() const;
11195

11296
/**
11397
* @brief Extract an RGB cv::Mat from a VisionCamera frame

0 commit comments

Comments
 (0)