Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhanced] method of memory loading model #2029

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ option(MMDEPLOY_BUILD_SDK_CSHARP_API "build SDK C# API support" OFF)
option(MMDEPLOY_BUILD_SDK_JAVA_API "build SDK JAVA API" OFF)
option(MMDEPLOY_BUILD_EXAMPLES "build examples" OFF)
option(MMDEPLOY_SPDLOG_EXTERNAL "use external spdlog" OFF)
option(MMDEPLOY_ZIP_MODEL "support SDK model in zip format" OFF)
option(MMDEPLOY_ZIP_MODEL "support SDK model in zip format" ON)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is recommended to keep MMDEPLOY_ZIP_MODEL OFF as the default value because not all of the users need it

option(MMDEPLOY_COVERAGE "build SDK for coverage" OFF)
option(MMDEPLOY_ELENA_FUSION "use elena to fuse preprocess" OFF)

Expand Down
12 changes: 12 additions & 0 deletions csrc/mmdeploy/apis/c/mmdeploy/classifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ int mmdeploy_classifier_create_by_path(const char* model_path, const char* devic
return ec;
}

int mmdeploy_classifier_create_by_buffer(const void* buffer, int size, const char* device_name,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't suggest creating another API. It's kinda redundant because mmdeploy_model_create and mmdeploy_classifier_create are enough to make up for it

int device_id, mmdeploy_classifier_t* classifier) {
mmdeploy_model_t model{};

if (auto ec = mmdeploy_model_create(buffer, size, &model)) {
return ec;
}
auto ec = mmdeploy_classifier_create(model, device_name, device_id, classifier);
mmdeploy_model_destroy(model);
return ec;
}

int mmdeploy_classifier_create_v2(mmdeploy_model_t model, mmdeploy_context_t context,
mmdeploy_classifier_t* classifier) {
return mmdeploy_pipeline_create_from_model(model, context, (mmdeploy_pipeline_t*)classifier);
Expand Down
14 changes: 14 additions & 0 deletions csrc/mmdeploy/apis/c/mmdeploy/classifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@ MMDEPLOY_API int mmdeploy_classifier_create_by_path(const char* model_path, cons
int device_id,
mmdeploy_classifier_t* classifier);

/**
* @brief Create classifier's handle
* @param[in] buffer a linear buffer contains the model information
* @param[in] size size of \p buffer in bytes
* @param[in] device_name name of device, such as "cpu", "cuda", etc.
* @param[in] device_id id of device.
* @param[out] classifier instance of a classifier, which must be destroyed
* by \ref mmdeploy_classifier_destroy
* @return status of creating classifier's handle
*/
MMDEPLOY_API int mmdeploy_classifier_create_by_buffer(const void* buffer, int size, const char* device_name,
int device_id,
mmdeploy_classifier_t* classifier);

/**
* @brief Use classifier created by \ref mmdeploy_classifier_create_by_path to get label
* information of each image in a batch
Expand Down
12 changes: 12 additions & 0 deletions csrc/mmdeploy/apis/c/mmdeploy/detector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ int mmdeploy_detector_create_by_path(const char* model_path, const char* device_
return ec;
}

int mmdeploy_detector_create_by_buffer(const void* buffer, int size, const char* device_name, int device_id,
mmdeploy_detector_t* detector) {
mmdeploy_model_t model{};

if (auto ec = mmdeploy_model_create(buffer, size, &model)) {
return ec;
}
auto ec = mmdeploy_detector_create(model, device_name, device_id, detector);
mmdeploy_model_destroy(model);
return ec;
}

int mmdeploy_detector_create_input(const mmdeploy_mat_t* mats, int mat_count,
mmdeploy_value_t* input) {
return mmdeploy_common_create_input(mats, mat_count, input);
Expand Down
13 changes: 13 additions & 0 deletions csrc/mmdeploy/apis/c/mmdeploy/detector.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ MMDEPLOY_API int mmdeploy_detector_create(mmdeploy_model_t model, const char* de
MMDEPLOY_API int mmdeploy_detector_create_by_path(const char* model_path, const char* device_name,
int device_id, mmdeploy_detector_t* detector);

/**
* @brief Create detector's handle
* @param[in] buffer a linear buffer contains the model information
* @param[in] size size of \p buffer in bytes
* @param[in] device_name name of device, such as "cpu", "cuda", etc.
* @param[in] device_id id of device.
* @param[out] detector instance of a detector
* @return status of creating detector's handle
*/
MMDEPLOY_API int mmdeploy_detector_create_by_buffer(const void* buffer, int size, const char* device_name,
int device_id, mmdeploy_detector_t* detector);


/**
* @brief Apply detector to batch images and get their inference results
* @param[in] detector detector's handle created by \ref mmdeploy_detector_create_by_path
Expand Down
11 changes: 11 additions & 0 deletions csrc/mmdeploy/apis/c/mmdeploy/pose_detector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ int mmdeploy_pose_detector_create_by_path(const char* model_path, const char* de
return ec;
}

int mmdeploy_pose_detector_create_by_buffer(const void* buffer, int size, const char* device_name,
int device_id, mmdeploy_pose_detector_t* detector) {
mmdeploy_model_t model{};
if (auto ec = mmdeploy_model_create(buffer, size, &model)) {
return ec;
}
auto ec = mmdeploy_pose_detector_create(model, device_name, device_id, detector);
mmdeploy_model_destroy(model);
return ec;
}

int mmdeploy_pose_detector_apply(mmdeploy_pose_detector_t detector, const mmdeploy_mat_t* mats,
int mat_count, mmdeploy_pose_detection_t** results) {
return mmdeploy_pose_detector_apply_bbox(detector, mats, mat_count, nullptr, nullptr, results);
Expand Down
14 changes: 14 additions & 0 deletions csrc/mmdeploy/apis/c/mmdeploy/pose_detector.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,20 @@ MMDEPLOY_API int mmdeploy_pose_detector_create_by_path(const char* model_path,
const char* device_name, int device_id,
mmdeploy_pose_detector_t* detector);

/**
* @brief Create a pose detector instance
* @param[in] buffer a linear buffer contains the model information
* @param[in] size size of \p buffer in bytes
* @param[in] device_name name of device, such as "cpu", "cuda", etc.
* @param[in] device_id id of device.
* @param[out] detector handle of the created pose detector, which must be destroyed
* by \ref mmdeploy_pose_detector_destroy
* @return status code of the operation
*/
MMDEPLOY_API int mmdeploy_pose_detector_create_by_buffer(const void* buffer, int size,
const char* device_name, int device_id,
mmdeploy_pose_detector_t* detector);

/**
* @brief Apply pose detector to a batch of images with full image roi
* @param[in] detector pose detector's handle created by \ref
Expand Down
11 changes: 11 additions & 0 deletions csrc/mmdeploy/apis/c/mmdeploy/restorer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ int mmdeploy_restorer_create_by_path(const char* model_path, const char* device_
return ec;
}

int mmdeploy_restorer_create_by_buffer(const void* buffer , int size , const char* device_name, int device_id,
mmdeploy_restorer_t* restorer) {
mmdeploy_model_t model{};
if (auto ec = mmdeploy_model_create(buffer, size, &model)) {
return ec;
}
auto ec = mmdeploy_restorer_create(model, device_name, device_id, restorer);
mmdeploy_model_destroy(model);
return ec;
}

int mmdeploy_restorer_apply(mmdeploy_restorer_t restorer, const mmdeploy_mat_t* images, int count,
mmdeploy_mat_t** results) {
wrapped<mmdeploy_value_t> input;
Expand Down
14 changes: 14 additions & 0 deletions csrc/mmdeploy/apis/c/mmdeploy/restorer.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@ MMDEPLOY_API int mmdeploy_restorer_create(mmdeploy_model_t model, const char* de
MMDEPLOY_API int mmdeploy_restorer_create_by_path(const char* model_path, const char* device_name,
int device_id, mmdeploy_restorer_t* restorer);

/**
* @brief Create a restorer instance
* @param[in] buffer a linear buffer contains the model information
* @param[in] size size of \p buffer in bytes
* @param[in] device_name name of device, such as "cpu", "cuda", etc.
* @param[in] device_id id of device.
* @param[out] restorer handle of the created restorer, which must be destroyed
* by \ref mmdeploy_restorer_destroy
* @return status code of the operation
*/
MMDEPLOY_API int mmdeploy_restorer_create_by_buffer(const void* buffer, int size, const char* device_name,
int device_id, mmdeploy_restorer_t* restorer);


/**
* @brief Apply restorer to a batch of images
* @param[in] restorer restorer's handle created by \ref mmdeploy_restorer_create_by_path
Expand Down
12 changes: 12 additions & 0 deletions csrc/mmdeploy/apis/c/mmdeploy/rotated_detector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ int mmdeploy_rotated_detector_create_by_path(const char* model_path, const char*
return ec;
}

int mmdeploy_rotated_detector_create_by_buffer(const void* buffer, int size, const char* device_name,
int device_id, mmdeploy_rotated_detector_t* detector) {
mmdeploy_model_t model{};

if (auto ec = mmdeploy_model_create(buffer, size, &model)) {
return ec;
}
auto ec = mmdeploy_rotated_detector_create(model, device_name, device_id, detector);
mmdeploy_model_destroy(model);
return ec;
}

int mmdeploy_rotated_detector_apply(mmdeploy_rotated_detector_t detector,
const mmdeploy_mat_t* mats, int mat_count,
mmdeploy_rotated_detection_t** results, int** result_count) {
Expand Down
13 changes: 13 additions & 0 deletions csrc/mmdeploy/apis/c/mmdeploy/rotated_detector.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@ MMDEPLOY_API int mmdeploy_rotated_detector_create_by_path(const char* model_path
const char* device_name, int device_id,
mmdeploy_rotated_detector_t* detector);

/**
* @brief Create rotated detector's handle
* @param[in] buffer a linear buffer contains the model information
* @param[in] size size of \p buffer in bytes
* @param[in] device_name name of device, such as "cpu", "cuda", etc.
* @param[in] device_id id of device.
* @param[out] detector instance of a rotated detector
* @return status of creating rotated detector's handle
*/
MMDEPLOY_API int mmdeploy_rotated_detector_create_by_buffer(const void* buffer, int size,
const char* device_name, int device_id,
mmdeploy_rotated_detector_t* detector);

/**
* @brief Apply rotated detector to batch images and get their inference results
* @param[in] detector rotated detector's handle created by \ref
Expand Down
11 changes: 11 additions & 0 deletions csrc/mmdeploy/apis/c/mmdeploy/segmentor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ int mmdeploy_segmentor_create_by_path(const char* model_path, const char* device
return ec;
}

int mmdeploy_segmentor_create_by_buffer(const void* buffer, int size, const char* device_name,
int device_id, mmdeploy_segmentor_t* segmentor) {
mmdeploy_model_t model{};
if (auto ec = mmdeploy_model_create(buffer, size, &model)) {
return ec;
}
auto ec = mmdeploy_segmentor_create(model, device_name, device_id, segmentor);
mmdeploy_model_destroy(model);
return ec;
}

int mmdeploy_segmentor_apply(mmdeploy_segmentor_t segmentor, const mmdeploy_mat_t* mats,
int mat_count, mmdeploy_segmentation_t** results) {
wrapped<mmdeploy_value_t> input;
Expand Down
14 changes: 14 additions & 0 deletions csrc/mmdeploy/apis/c/mmdeploy/segmentor.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,20 @@ MMDEPLOY_API int mmdeploy_segmentor_create(mmdeploy_model_t model, const char* d
MMDEPLOY_API int mmdeploy_segmentor_create_by_path(const char* model_path, const char* device_name,
int device_id, mmdeploy_segmentor_t* segmentor);

/**
* @brief Create segmentor's handle
* @param[in] buffer a linear buffer contains the model information
* @param[in] size size of \p buffer in bytes
* @param[in] device_name name of device, such as "cpu", "cuda", etc.
* @param[in] device_id id of device.
* @param[out] segmentor instance of a segmentor, which must be destroyed
* by \ref mmdeploy_segmentor_destroy
* @return status of creating segmentor's handle
*/
MMDEPLOY_API int mmdeploy_segmentor_create_by_buffer(const void* buffer, int size, const char* device_name,
int device_id, mmdeploy_segmentor_t* segmentor);


/**
* @brief Apply segmentor to batch images and get their inference results
* @param[in] segmentor segmentor's handle created by \ref mmdeploy_segmentor_create_by_path or \ref
Expand Down
11 changes: 11 additions & 0 deletions csrc/mmdeploy/apis/c/mmdeploy/text_detector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ int mmdeploy_text_detector_create_by_path(const char* model_path, const char* de
return ec;
}

int mmdeploy_text_detector_create_by_buffer(const void* buffer, int size, const char* device_name,
int device_id, mmdeploy_text_detector_t* detector) {
mmdeploy_model_t model{};
if (auto ec = mmdeploy_model_create(buffer, size, &model)) {
return ec;
}
auto ec = mmdeploy_text_detector_create(model, device_name, device_id, detector);
mmdeploy_model_destroy(model);
return ec;
}

int mmdeploy_text_detector_create_input(const mmdeploy_mat_t* mats, int mat_count,
mmdeploy_value_t* input) {
return mmdeploy_common_create_input(mats, mat_count, input);
Expand Down
14 changes: 14 additions & 0 deletions csrc/mmdeploy/apis/c/mmdeploy/text_detector.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@ MMDEPLOY_API int mmdeploy_text_detector_create_by_path(const char* model_path,
const char* device_name, int device_id,
mmdeploy_text_detector_t* detector);

/**
* @brief Create text-detector's handle
* @param[in] buffer a linear buffer contains the model information
* @param[in] size size of \p buffer in bytes
* @param[in] device_name name of device, such as "cpu", "cuda", etc.
* @param[in] device_id id of device
* @param[out] detector instance of a text-detector, which must be destroyed
* by \ref mmdeploy_text_detector_destroy
* @return status of creating text-detector's handle
*/
MMDEPLOY_API int mmdeploy_text_detector_create_by_buffer(const void* buffer, int size,
const char* device_name, int device_id,
mmdeploy_text_detector_t* detector);

/**
* @brief Apply text-detector to batch images and get their inference results
* @param[in] detector text-detector's handle created by \ref mmdeploy_text_detector_create_by_path
Expand Down
11 changes: 11 additions & 0 deletions csrc/mmdeploy/apis/c/mmdeploy/text_recognizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,17 @@ int mmdeploy_text_recognizer_create_by_path(const char* model_path, const char*
return ec;
}

int mmdeploy_text_recognizer_create_by_buffer(const void* buffer, int size, const char* device_name,
int device_id, mmdeploy_text_recognizer_t* recognizer) {
mmdeploy_model_t model{};
if (auto ec = mmdeploy_model_create(buffer, size, &model)) {
return ec;
}
auto ec = mmdeploy_text_recognizer_create(model, device_name, device_id, recognizer);
mmdeploy_model_destroy(model);
return ec;
}

int mmdeploy_text_recognizer_apply(mmdeploy_text_recognizer_t recognizer,
const mmdeploy_mat_t* images, int count,
mmdeploy_text_recognition_t** results) {
Expand Down
14 changes: 14 additions & 0 deletions csrc/mmdeploy/apis/c/mmdeploy/text_recognizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,20 @@ MMDEPLOY_API int mmdeploy_text_recognizer_create_by_path(const char* model_path,
const char* device_name, int device_id,
mmdeploy_text_recognizer_t* recognizer);

/**
* @brief Create a text recognizer instance
* @param[in] buffer a linear buffer contains the model information
* @param[in] size size of \p buffer in bytes
* @param[in] device_name name of device, such as "cpu", "cuda", etc.
* @param[in] device_id id of device.
* @param[out] recognizer handle of the created text recognizer, which must be destroyed
* by \ref mmdeploy_text_recognizer_destroy
* @return status code of the operation
*/
MMDEPLOY_API int mmdeploy_text_recognizer_create_by_buffer(const void* buffer, int size,
const char* device_name, int device_id,
mmdeploy_text_recognizer_t* recognizer);

/**
* @brief Apply text recognizer to a batch of text images
* @param[in] recognizer text recognizer's handle created by \ref
Expand Down
14 changes: 14 additions & 0 deletions csrc/mmdeploy/apis/c/mmdeploy/video_recognizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@ int mmdeploy_video_recognizer_create_by_path(const char* model_path, const char*
mmdeploy_model_destroy(model);
return ec;
}

int mmdeploy_video_recognizer_create_by_buffer(const void* buffer, int size, const char* device_name,
int device_id,
mmdeploy_video_recognizer_t* recognizer) {
mmdeploy_model_t model{};

if (auto ec = mmdeploy_model_create(buffer, size, &model)) {
return ec;
}
auto ec = mmdeploy_video_recognizer_create(model, device_name, device_id, recognizer);
mmdeploy_model_destroy(model);
return ec;
}

int mmdeploy_video_recognizer_apply(mmdeploy_video_recognizer_t recognizer,
const mmdeploy_mat_t* images,
const mmdeploy_video_sample_info_t* video_info, int video_count,
Expand Down
14 changes: 14 additions & 0 deletions csrc/mmdeploy/apis/c/mmdeploy/video_recognizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,20 @@ MMDEPLOY_API int mmdeploy_video_recognizer_create_by_path(const char* model_path
const char* device_name, int device_id,
mmdeploy_video_recognizer_t* recognizer);

/**
* @brief Create a video recognizer instance
* @param[in] buffer a linear buffer contains the model information
* @param[in] size size of \p buffer in bytes
* @param[in] device_name name of device, such as "cpu", "cuda", etc.
* @param[in] device_id id of device.
* @param[out] recognizer handle of the created video recognizer, which must be destroyed
* by \ref mmdeploy_video_recognizer_destroy
* @return status code of the operation
*/
MMDEPLOY_API int mmdeploy_video_recognizer_create_by_buffer(const void* buffer, int size,
const char* device_name, int device_id,
mmdeploy_video_recognizer_t* recognizer);

/**
* @brief Apply video recognizer to a batch of videos
* @param[in] recognizer video recognizer's handle created by \ref
Expand Down