Skip to content

Commit

Permalink
添加修改wrapper,指定模型尺寸的方法
Browse files Browse the repository at this point in the history
  • Loading branch information
oldma3095 committed Dec 28, 2023
1 parent cfebd24 commit 0ae2909
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion c_api/fastdeploy_capi/core/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
#endif

#ifndef ENABLE_TEXT
/* #undef ENABLE_TEXT */
#define ENABLE_TEXT
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,17 @@ FD_C_Destroy##model_type##Wrapper(__fd_take FD_C_##model_type##Wrapper* wrapper_
FD_C_DetectionResult* fd_c_detection_result, float conf_threshold, \
float nms_threshold)

#define YOLO_DECLARE_SETPRESIZE_FUNCTION(model_type, wrapper_var_name) \
FASTDEPLOY_CAPI_EXPORT extern void FD_C_##model_type##WrapperSetPreSize( \
__fd_take FD_C_##model_type##Wrapper* wrapper_var_name, \
int iWidth, int iHeight)

#define YOLO_DECLARE_INITIALIZED_FUNCTION(model_type, wrapper_var_name) FASTDEPLOY_CAPI_EXPORT extern FD_C_Bool FD_C_##model_type##WrapperInitialized( \
__fd_keep FD_C_##model_type##Wrapper* wrapper_var_name)


#define YOLO_DECLARE_SET_PRESIZE_FUNCTION(model_type, wrapper_var_name) FASTDEPLOY_CAPI_EXPORT extern void FD_C_##model_type##WrapperSetPreSize( \
__fd_keep FD_C_##model_type##Wrapper* wrapper_var_name, \
int iWidth, int iHeight)
#define YOLO_DECLARE_BATCH_PREDICT_FUNCTION(model_type, wrapper_var_name) FASTDEPLOY_CAPI_EXPORT extern FD_C_Bool FD_C_##model_type##WrapperBatchPredict( \
__fd_keep FD_C_##model_type##Wrapper* wrapper_var_name, \
FD_C_OneDimMat imgs, \
Expand Down Expand Up @@ -137,3 +144,12 @@ FD_C_Destroy##model_type##Wrapper(__fd_take FD_C_##model_type##Wrapper* wrapper_
}\
return successful; \
}

#define YOLO_DECLARE_AND_IMPLEMENT_SETPRESIZE_FUNCTION(model_type, wrapper_var_name) void FD_C_##model_type##WrapperSetPreSize( \
FD_C_##model_type##Wrapper* wrapper_var_name, int iWidth, int iHeight) { \
if (iWidth > 0 && iHeight > 0) { \
auto& model = \
CHECK_AND_CONVERT_FD_TYPE(model_type##Wrapper, wrapper_var_name); \
model->SetPreSize(iWidth, iHeight); \
} \
}
4 changes: 2 additions & 2 deletions c_api/fastdeploy_capi/vision/detection/contrib/yolo/model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ YOLO_DECLARE_AND_IMPLEMENT_DESTROY_WRAPPER_FUNCTION(YOLOv5, fd_yolov5_wrapper)
YOLO_DECLARE_AND_IMPLEMENT_PREDICT_FUNCTION(YOLOv5, fd_yolov5_wrapper)
YOLO_DECLARE_AND_IMPLEMENT_INITIALIZED_FUNCTION(YOLOv5, fd_yolov5_wrapper)
YOLO_DECLARE_AND_IMPLEMENT_BATCH_PREDICT_FUNCTION(YOLOv5, fd_yolov5_wrapper)

YOLO_DECLARE_AND_IMPLEMENT_SETPRESIZE_FUNCTION(YOLOv5, fd_yolov5_wrapper)
// YOLOv7
YOLO_DECLARE_AND_IMPLEMENT_CREATE_WRAPPER_FUNCTION(YOLOv7, yolov7_model)
YOLO_DECLARE_AND_IMPLEMENT_DESTROY_WRAPPER_FUNCTION(YOLOv7, fd_yolov7_wrapper)
Expand Down Expand Up @@ -65,4 +65,4 @@ YOLO_DECLARE_AND_IMPLEMENT_INITIALIZED_FUNCTION(YOLOX, fd_yolox_wrapper)

#ifdef __cplusplus
}
#endif
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ YOLO_DECLARE_PREDICT_FUNCTION(YOLOv5, fd_c_yolov5_wrapper);

YOLO_DECLARE_INITIALIZED_FUNCTION(YOLOv5, fd_c_yolov5_wrapper);

YOLO_DECLARE_SETPRESIZE_FUNCTION(YOLOv5, fd_c_yolov5_wrapper);
/** \brief Predict the detection results for a batch of input images
*
* \param[in] fd_c_yolov5_wrapper pointer to FD_C_YOLOv5Wrapper object
Expand Down
4 changes: 4 additions & 0 deletions fastdeploy/vision/detection/contrib/yolov5/yolov5.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ class FASTDEPLOY_DECL YOLOv5 : public FastDeployModel {

std::string ModelName() const { return "yolov5"; }

void SetPreSize(int iWidth, int iHeight){
std::vector<int> vecPreSize = {iWidth, iHeight};
preprocessor_.SetSize(vecPreSize);
}
/** \brief DEPRECATED Predict the detection result for an input image, remove at 1.0 version
*
* \param[in] im The input image data, comes from cv::imread(), is a 3-D array with layout HWC, BGR format
Expand Down

0 comments on commit 0ae2909

Please sign in to comment.