From d75793f0532011db0e43b386cc43e30405eaad63 Mon Sep 17 00:00:00 2001 From: DefTruth Date: Tue, 26 Oct 2021 23:38:52 +0800 Subject: [PATCH 1/2] fixed Ubuntu+gcc build error for std::xxxf (#81) --- lite/mnn/cv/mnn_nanodet.cpp | 10 ++-- lite/mnn/cv/mnn_nanodet_efficientnet_lite.cpp | 10 ++-- lite/mnn/cv/mnn_yolop.cpp | 2 +- lite/mnn/cv/mnn_yolox.cpp | 4 +- lite/ncnn/cv/ncnn_nanodet.cpp | 10 ++-- lite/ncnn/cv/ncnn_nanodet_depreciated.cpp | 10 ++-- .../cv/ncnn_nanodet_efficientnet_lite.cpp | 10 ++-- ..._nanodet_efficientnet_lite_depreciated.cpp | 10 ++-- lite/ort/cv/efficientdet.cpp | 4 +- lite/ort/cv/efficientdet_d7.cpp | 4 +- lite/ort/cv/efficientdet_d8.cpp | 4 +- lite/ort/cv/face_landmarks_1000.cpp | 4 +- lite/ort/cv/faceboxes.cpp | 8 +-- lite/ort/cv/mobilenetv2_68.cpp | 4 +- lite/ort/cv/mobilenetv2_se_68.cpp | 4 +- lite/ort/cv/nanodet.cpp | 10 ++-- lite/ort/cv/nanodet_efficientnet_lite.cpp | 10 ++-- lite/ort/cv/pfld.cpp | 4 +- lite/ort/cv/pfld68.cpp | 4 +- lite/ort/cv/pfld98.cpp | 4 +- lite/ort/cv/retinaface.cpp | 8 +-- lite/ort/cv/tiny_yolov3.cpp | 2 +- lite/ort/cv/yolop.cpp | 2 +- lite/ort/cv/yolov3.cpp | 2 +- lite/ort/cv/yolox.cpp | 4 +- lite/tnn/cv/tnn_nanodet.cpp | 10 ++-- lite/tnn/cv/tnn_nanodet_efficientnet_lite.cpp | 10 ++-- lite/tnn/cv/tnn_yolop.cpp | 2 +- lite/tnn/cv/tnn_yolox.cpp | 4 +- lite/utils.cpp | 50 +++++++++---------- lite/utils.h | 32 ++++++------ 31 files changed, 128 insertions(+), 128 deletions(-) diff --git a/lite/mnn/cv/mnn_nanodet.cpp b/lite/mnn/cv/mnn_nanodet.cpp index f8a308bb..39f30eec 100644 --- a/lite/mnn/cv/mnn_nanodet.cpp +++ b/lite/mnn/cv/mnn_nanodet.cpp @@ -44,7 +44,7 @@ void MNNNanoDet::resize_unscale(const cv::Mat &mat, cv::Mat &mat_rs, // scale ratio (new / old) new_shape(h,w) float w_r = (float) target_width / (float) img_width; float h_r = (float) target_height / (float) img_height; - float r = std::fmin(w_r, h_r); + float r = std::min(w_r, h_r); // compute padding int new_unpad_w = static_cast((float) img_width * r); // floor int new_unpad_h = static_cast((float) img_height * r); // floor @@ -213,10 +213,10 @@ void MNNNanoDet::generate_bboxes_single_stride(const NanoScaleParams &scale_para float y1 = ((cy - t) * s - (float) dh) / ratio; // cy - t y1 float x2 = ((cx + r) * s - (float) dw) / ratio; // cx + r x2 float y2 = ((cy + b) * s - (float) dh) / ratio; // cy + b y2 - box.x1 = std::fmax(0.f, x1); - box.y1 = std::fmax(0.f, y1); - box.x2 = std::fmin(img_width, x2); - box.y2 = std::fmin(img_height, y2); + box.x1 = std::max(0.f, x1); + box.y1 = std::max(0.f, y1); + box.x2 = std::min(img_width, x2); + box.y2 = std::min(img_height, y2); box.score = cls_conf; box.label = label; box.label_text = class_names[label]; diff --git a/lite/mnn/cv/mnn_nanodet_efficientnet_lite.cpp b/lite/mnn/cv/mnn_nanodet_efficientnet_lite.cpp index 9dc124ab..c5806e74 100644 --- a/lite/mnn/cv/mnn_nanodet_efficientnet_lite.cpp +++ b/lite/mnn/cv/mnn_nanodet_efficientnet_lite.cpp @@ -45,7 +45,7 @@ void MNNNanoDetEfficientNetLite::resize_unscale(const cv::Mat &mat, cv::Mat &mat // scale ratio (new / old) new_shape(h,w) float w_r = (float) target_width / (float) img_width; float h_r = (float) target_height / (float) img_height; - float r = std::fmin(w_r, h_r); + float r = std::min(w_r, h_r); // compute padding int new_unpad_w = static_cast((float) img_width * r); // floor int new_unpad_h = static_cast((float) img_height * r); // floor @@ -214,10 +214,10 @@ void MNNNanoDetEfficientNetLite::generate_bboxes_single_stride(const NanoLiteSca float y1 = ((cy - t) * s - (float) dh) / ratio; // cy - t y1 float x2 = ((cx + r) * s - (float) dw) / ratio; // cx + r x2 float y2 = ((cy + b) * s - (float) dh) / ratio; // cy + b y2 - box.x1 = std::fmax(0.f, x1); - box.y1 = std::fmax(0.f, y1); - box.x2 = std::fmin(img_width, x2); - box.y2 = std::fmin(img_height, y2); + box.x1 = std::max(0.f, x1); + box.y1 = std::max(0.f, y1); + box.x2 = std::min(img_width, x2); + box.y2 = std::min(img_height, y2); box.score = cls_conf; box.label = label; box.label_text = class_names[label]; diff --git a/lite/mnn/cv/mnn_yolop.cpp b/lite/mnn/cv/mnn_yolop.cpp index 94664150..c5f13838 100644 --- a/lite/mnn/cv/mnn_yolop.cpp +++ b/lite/mnn/cv/mnn_yolop.cpp @@ -43,7 +43,7 @@ void MNNYOLOP::resize_unscale(const cv::Mat &mat, cv::Mat &mat_rs, // scale ratio (new / old) new_shape(h,w) float w_r = (float) target_width / (float) img_width; float h_r = (float) target_height / (float) img_height; - float r = std::fmin(w_r, h_r); + float r = std::min(w_r, h_r); // compute padding int new_unpad_w = static_cast((float) img_width * r); // floor int new_unpad_h = static_cast((float) img_height * r); // floor diff --git a/lite/mnn/cv/mnn_yolox.cpp b/lite/mnn/cv/mnn_yolox.cpp index d2a39980..a161643e 100644 --- a/lite/mnn/cv/mnn_yolox.cpp +++ b/lite/mnn/cv/mnn_yolox.cpp @@ -136,8 +136,8 @@ void MNNYoloX::generate_bboxes(std::vector &bbox_collection, float cx = (dx + (float) grid0) * (float) stride; float cy = (dy + (float) grid1) * (float) stride; - float w = std::expf(dw) * (float) stride; - float h = std::expf(dh) * (float) stride; + float w = std::exp(dw) * (float) stride; + float h = std::exp(dh) * (float) stride; types::Boxf box; box.x1 = (cx - w / 2.f) * scale_width; diff --git a/lite/ncnn/cv/ncnn_nanodet.cpp b/lite/ncnn/cv/ncnn_nanodet.cpp index 9ebae110..81066f90 100644 --- a/lite/ncnn/cv/ncnn_nanodet.cpp +++ b/lite/ncnn/cv/ncnn_nanodet.cpp @@ -30,7 +30,7 @@ void NCNNNanoDet::resize_unscale(const cv::Mat &mat, cv::Mat &mat_rs, // scale ratio (new / old) new_shape(h,w) float w_r = (float) target_width / (float) img_width; float h_r = (float) target_height / (float) img_height; - float r = std::fmin(w_r, h_r); + float r = std::min(w_r, h_r); // compute padding int new_unpad_w = static_cast((float) img_width * r); // floor int new_unpad_h = static_cast((float) img_height * r); // floor @@ -206,10 +206,10 @@ void NCNNNanoDet::generate_bboxes_single_stride(const NanoScaleParams &scale_par float y1 = ((cy - t) * s - (float) dh) / ratio; // cy - t y1 float x2 = ((cx + r) * s - (float) dw) / ratio; // cx + r x2 float y2 = ((cy + b) * s - (float) dh) / ratio; // cy + b y2 - box.x1 = std::fmax(0.f, x1); - box.y1 = std::fmax(0.f, y1); - box.x2 = std::fmin(img_width, x2); - box.y2 = std::fmin(img_height, y2); + box.x1 = std::max(0.f, x1); + box.y1 = std::max(0.f, y1); + box.x2 = std::min(img_width, x2); + box.y2 = std::min(img_height, y2); box.score = cls_conf; box.label = label; box.label_text = class_names[label]; diff --git a/lite/ncnn/cv/ncnn_nanodet_depreciated.cpp b/lite/ncnn/cv/ncnn_nanodet_depreciated.cpp index e758d56f..fa0e25fe 100644 --- a/lite/ncnn/cv/ncnn_nanodet_depreciated.cpp +++ b/lite/ncnn/cv/ncnn_nanodet_depreciated.cpp @@ -30,7 +30,7 @@ void NCNNNanoDetDepreciated::resize_unscale(const cv::Mat &mat, cv::Mat &mat_rs, // scale ratio (new / old) new_shape(h,w) float w_r = (float) target_width / (float) img_width; float h_r = (float) target_height / (float) img_height; - float r = std::fmin(w_r, h_r); + float r = std::min(w_r, h_r); // compute padding int new_unpad_w = static_cast((float) img_width * r); // floor int new_unpad_h = static_cast((float) img_height * r); // floor @@ -220,10 +220,10 @@ void NCNNNanoDetDepreciated::generate_bboxes_single_stride(const NanoDepreciated float y1 = ((cy - t) * s - (float) dh) / ratio; // cy - t y1 float x2 = ((cx + r) * s - (float) dw) / ratio; // cx + r x2 float y2 = ((cy + b) * s - (float) dh) / ratio; // cy + b y2 - box.x1 = std::fmax(0.f, x1); - box.y1 = std::fmax(0.f, y1); - box.x2 = std::fmin(img_width, x2); - box.y2 = std::fmin(img_height, y2); + box.x1 = std::max(0.f, x1); + box.y1 = std::max(0.f, y1); + box.x2 = std::min(img_width, x2); + box.y2 = std::min(img_height, y2); box.score = cls_conf; box.label = label; box.label_text = class_names[label]; diff --git a/lite/ncnn/cv/ncnn_nanodet_efficientnet_lite.cpp b/lite/ncnn/cv/ncnn_nanodet_efficientnet_lite.cpp index cd38e473..34f2552c 100644 --- a/lite/ncnn/cv/ncnn_nanodet_efficientnet_lite.cpp +++ b/lite/ncnn/cv/ncnn_nanodet_efficientnet_lite.cpp @@ -30,7 +30,7 @@ void NCNNNanoDetEfficientNetLite::resize_unscale(const cv::Mat &mat, cv::Mat &ma // scale ratio (new / old) new_shape(h,w) float w_r = (float) target_width / (float) img_width; float h_r = (float) target_height / (float) img_height; - float r = std::fmin(w_r, h_r); + float r = std::min(w_r, h_r); // compute padding int new_unpad_w = static_cast((float) img_width * r); // floor int new_unpad_h = static_cast((float) img_height * r); // floor @@ -206,10 +206,10 @@ void NCNNNanoDetEfficientNetLite::generate_bboxes_single_stride(const NanoLiteSc float y1 = ((cy - t) * s - (float) dh) / ratio; // cy - t y1 float x2 = ((cx + r) * s - (float) dw) / ratio; // cx + r x2 float y2 = ((cy + b) * s - (float) dh) / ratio; // cy + b y2 - box.x1 = std::fmax(0.f, x1); - box.y1 = std::fmax(0.f, y1); - box.x2 = std::fmin(img_width, x2); - box.y2 = std::fmin(img_height, y2); + box.x1 = std::max(0.f, x1); + box.y1 = std::max(0.f, y1); + box.x2 = std::min(img_width, x2); + box.y2 = std::min(img_height, y2); box.score = cls_conf; box.label = label; box.label_text = class_names[label]; diff --git a/lite/ncnn/cv/ncnn_nanodet_efficientnet_lite_depreciated.cpp b/lite/ncnn/cv/ncnn_nanodet_efficientnet_lite_depreciated.cpp index 88840892..c7f8f471 100644 --- a/lite/ncnn/cv/ncnn_nanodet_efficientnet_lite_depreciated.cpp +++ b/lite/ncnn/cv/ncnn_nanodet_efficientnet_lite_depreciated.cpp @@ -32,7 +32,7 @@ void NCNNNanoDetEfficientNetLiteDepreciated::resize_unscale( // scale ratio (new / old) new_shape(h,w) float w_r = (float) target_width / (float) img_width; float h_r = (float) target_height / (float) img_height; - float r = std::fmin(w_r, h_r); + float r = std::min(w_r, h_r); // compute padding int new_unpad_w = static_cast((float) img_width * r); // floor int new_unpad_h = static_cast((float) img_height * r); // floor @@ -226,10 +226,10 @@ void NCNNNanoDetEfficientNetLiteDepreciated::generate_bboxes_single_stride( float y1 = ((cy - t) * s - (float) dh) / ratio; // cy - t y1 float x2 = ((cx + r) * s - (float) dw) / ratio; // cx + r x2 float y2 = ((cy + b) * s - (float) dh) / ratio; // cy + b y2 - box.x1 = std::fmax(0.f, x1); - box.y1 = std::fmax(0.f, y1); - box.x2 = std::fmin(img_width, x2); - box.y2 = std::fmin(img_height, y2); + box.x1 = std::max(0.f, x1); + box.y1 = std::max(0.f, y1); + box.x2 = std::min(img_width, x2); + box.y2 = std::min(img_height, y2); box.score = cls_conf; box.label = label; box.label_text = class_names[label]; diff --git a/lite/ort/cv/efficientdet.cpp b/lite/ort/cv/efficientdet.cpp index c83cab63..25961994 100644 --- a/lite/ort/cv/efficientdet.cpp +++ b/lite/ort/cv/efficientdet.cpp @@ -143,8 +143,8 @@ void EfficientDet::generate_bboxes(std::vector &bbox_collection, float cx = dx * wa + cxa; float cy = dy * ha + cya; - float w = std::expf(dw) * wa; - float h = std::expf(dh) * ha; + float w = std::exp(dw) * wa; + float h = std::exp(dh) * ha; types::Boxf box; box.x1 = (cx - w / 2.f) * scale_width; diff --git a/lite/ort/cv/efficientdet_d7.cpp b/lite/ort/cv/efficientdet_d7.cpp index 8824cbc2..2b71b7ad 100644 --- a/lite/ort/cv/efficientdet_d7.cpp +++ b/lite/ort/cv/efficientdet_d7.cpp @@ -143,8 +143,8 @@ void EfficientDetD7::generate_bboxes(std::vector &bbox_collection, float cx = dx * wa + cxa; float cy = dy * ha + cya; - float w = std::expf(dw) * wa; - float h = std::expf(dh) * ha; + float w = std::exp(dw) * wa; + float h = std::exp(dh) * ha; types::Boxf box; box.x1 = (cx - w / 2.f) * scale_width; diff --git a/lite/ort/cv/efficientdet_d8.cpp b/lite/ort/cv/efficientdet_d8.cpp index 5531baa8..da246dc0 100644 --- a/lite/ort/cv/efficientdet_d8.cpp +++ b/lite/ort/cv/efficientdet_d8.cpp @@ -143,8 +143,8 @@ void EfficientDetD8::generate_bboxes(std::vector &bbox_collection, float cx = dx * wa + cxa; float cy = dy * ha + cya; - float w = std::expf(dw) * wa; - float h = std::expf(dh) * ha; + float w = std::exp(dw) * wa; + float h = std::exp(dh) * ha; types::Boxf box; box.x1 = (cx - w / 2.f) * scale_width; diff --git a/lite/ort/cv/face_landmarks_1000.cpp b/lite/ort/cv/face_landmarks_1000.cpp index 99d6a454..d74c6181 100644 --- a/lite/ort/cv/face_landmarks_1000.cpp +++ b/lite/ort/cv/face_landmarks_1000.cpp @@ -43,8 +43,8 @@ void FaceLandmark1000::detect(const cv::Mat &mat, types::Landmarks &landmarks) float x = landmarks_norm.At({0, i}); float y = landmarks_norm.At({0, i + 1}); - x = std::fmin(std::fmax(0., x), 1.0f); - y = std::fmin(std::fmax(0., y), 1.0f); + x = std::min(std::max(0.f, x), 1.0f); + y = std::min(std::max(0.f, y), 1.0f); landmarks.points.push_back(cv::Point2f(x * img_width, y * img_height)); } diff --git a/lite/ort/cv/faceboxes.cpp b/lite/ort/cv/faceboxes.cpp index 463cea14..04fdf2cc 100644 --- a/lite/ort/cv/faceboxes.cpp +++ b/lite/ort/cv/faceboxes.cpp @@ -52,8 +52,8 @@ void FaceBoxes::generate_anchors(const int target_height, { feature_maps.push_back( { - (int) std::ceilf((float) target_height / (float) step), - (int) std::ceilf((float) target_width / (float) step) + (int) std::ceil((float) target_height / (float) step), + (int) std::ceil((float) target_width / (float) step) } // ceil ); } @@ -166,8 +166,8 @@ void FaceBoxes::generate_bboxes(std::vector &bbox_collection, // ref: https://github.com/zisianw/FaceBoxes.PyTorch/blob/master/utils/box_utils.py float cx = prior_cx + dx * variance[0] * prior_s_kx; float cy = prior_cy + dy * variance[0] * prior_s_ky; - float w = prior_s_kx * std::expf(dw * variance[1]); - float h = prior_s_ky * std::expf(dh * variance[1]); // norm coor (0.,1.) + float w = prior_s_kx * std::exp(dw * variance[1]); + float h = prior_s_ky * std::exp(dh * variance[1]); // norm coor (0.,1.) types::Boxf box; box.x1 = (cx - w / 2.f) * img_width; diff --git a/lite/ort/cv/mobilenetv2_68.cpp b/lite/ort/cv/mobilenetv2_68.cpp index 2a5fe869..27818267 100644 --- a/lite/ort/cv/mobilenetv2_68.cpp +++ b/lite/ort/cv/mobilenetv2_68.cpp @@ -45,8 +45,8 @@ void MobileNetV268::detect(const cv::Mat &mat, types::Landmarks &landmarks) float x = landmarks_norm.At({0, i}); float y = landmarks_norm.At({0, i + 1}); - x = std::fmin(std::fmax(0., x), 1.0f); - y = std::fmin(std::fmax(0., y), 1.0f); + x = std::min(std::max(0.f, x), 1.0f); + y = std::min(std::max(0.f, y), 1.0f); landmarks.points.push_back(cv::Point2f(x * img_width, y * img_height)); } diff --git a/lite/ort/cv/mobilenetv2_se_68.cpp b/lite/ort/cv/mobilenetv2_se_68.cpp index 27753eb7..12af644e 100644 --- a/lite/ort/cv/mobilenetv2_se_68.cpp +++ b/lite/ort/cv/mobilenetv2_se_68.cpp @@ -45,8 +45,8 @@ void MobileNetV2SE68::detect(const cv::Mat &mat, types::Landmarks &landmarks) float x = landmarks_norm.At({0, i}); float y = landmarks_norm.At({0, i + 1}); - x = std::fmin(std::fmax(0., x), 1.0f); - y = std::fmin(std::fmax(0., y), 1.0f); + x = std::min(std::max(0.f, x), 1.0f); + y = std::min(std::max(0.f, y), 1.0f); landmarks.points.push_back(cv::Point2f(x * img_width, y * img_height)); } diff --git a/lite/ort/cv/nanodet.cpp b/lite/ort/cv/nanodet.cpp index 4951b6cd..3e50ccbf 100644 --- a/lite/ort/cv/nanodet.cpp +++ b/lite/ort/cv/nanodet.cpp @@ -21,7 +21,7 @@ void NanoDet::resize_unscale(const cv::Mat &mat, cv::Mat &mat_rs, // scale ratio (new / old) new_shape(h,w) float w_r = (float) target_width / (float) img_width; float h_r = (float) target_height / (float) img_height; - float r = std::fmin(w_r, h_r); + float r = std::min(w_r, h_r); // compute padding int new_unpad_w = static_cast((float) img_width * r); // floor int new_unpad_h = static_cast((float) img_height * r); // floor @@ -197,10 +197,10 @@ void NanoDet::generate_bboxes_single_stride(const NanoScaleParams &scale_params, float y1 = ((cy - t) * s - (float) dh) / ratio; // cy - t y1 float x2 = ((cx + r) * s - (float) dw) / ratio; // cx + r x2 float y2 = ((cy + b) * s - (float) dh) / ratio; // cy + b y2 - box.x1 = std::fmax(0.f, x1); - box.y1 = std::fmax(0.f, y1); - box.x2 = std::fmin(img_width, x2); - box.y2 = std::fmin(img_height, y2); + box.x1 = std::max(0.f, x1); + box.y1 = std::max(0.f, y1); + box.x2 = std::min(img_width, x2); + box.y2 = std::min(img_height, y2); box.score = cls_conf; box.label = label; box.label_text = class_names[label]; diff --git a/lite/ort/cv/nanodet_efficientnet_lite.cpp b/lite/ort/cv/nanodet_efficientnet_lite.cpp index 2883fe16..605f61f9 100644 --- a/lite/ort/cv/nanodet_efficientnet_lite.cpp +++ b/lite/ort/cv/nanodet_efficientnet_lite.cpp @@ -20,7 +20,7 @@ void NanoDetEfficientNetLite::resize_unscale(const cv::Mat &mat, cv::Mat &mat_rs // scale ratio (new / old) new_shape(h,w) float w_r = (float) target_width / (float) img_width; float h_r = (float) target_height / (float) img_height; - float r = std::fmin(w_r, h_r); + float r = std::min(w_r, h_r); // compute padding int new_unpad_w = static_cast((float) img_width * r); // floor int new_unpad_h = static_cast((float) img_height * r); // floor @@ -197,10 +197,10 @@ void NanoDetEfficientNetLite::generate_bboxes_single_stride(const NanoLiteScaleP float y1 = ((cy - t) * s - (float) dh) / ratio; // cy - t y1 float x2 = ((cx + r) * s - (float) dw) / ratio; // cx + r x2 float y2 = ((cy + b) * s - (float) dh) / ratio; // cy + b y2 - box.x1 = std::fmax(0.f, x1); - box.y1 = std::fmax(0.f, y1); - box.x2 = std::fmin(img_width, x2); - box.y2 = std::fmin(img_height, y2); + box.x1 = std::max(0.f, x1); + box.y1 = std::max(0.f, y1); + box.x2 = std::min(img_width, x2); + box.y2 = std::min(img_height, y2); box.score = cls_conf; box.label = label; box.label_text = class_names[label]; diff --git a/lite/ort/cv/pfld.cpp b/lite/ort/cv/pfld.cpp index 99c5cd09..b63c6ff6 100644 --- a/lite/ort/cv/pfld.cpp +++ b/lite/ort/cv/pfld.cpp @@ -44,8 +44,8 @@ void PFLD::detect(const cv::Mat &mat, types::Landmarks &landmarks) float x = landmarks_norm.At({0, i}); float y = landmarks_norm.At({0, i + 1}); - x = std::fmin(std::fmax(0., x), 1.0f); - y = std::fmin(std::fmax(0., y), 1.0f); + x = std::min(std::max(0.f, x), 1.0f); + y = std::min(std::max(0.f, y), 1.0f); landmarks.points.push_back(cv::Point2f(x * img_width, y * img_height)); } diff --git a/lite/ort/cv/pfld68.cpp b/lite/ort/cv/pfld68.cpp index 22c643ea..cae36fe7 100644 --- a/lite/ort/cv/pfld68.cpp +++ b/lite/ort/cv/pfld68.cpp @@ -45,8 +45,8 @@ void PFLD68::detect(const cv::Mat &mat, types::Landmarks &landmarks) float x = landmarks_norm.At({0, i}); float y = landmarks_norm.At({0, i + 1}); - x = std::fmin(std::fmax(0., x), 1.0f); - y = std::fmin(std::fmax(0., y), 1.0f); + x = std::min(std::max(0.f, x), 1.0f); + y = std::min(std::max(0.f, y), 1.0f); landmarks.points.push_back(cv::Point2f(x * img_width, y * img_height)); } diff --git a/lite/ort/cv/pfld98.cpp b/lite/ort/cv/pfld98.cpp index b17304d5..af642523 100644 --- a/lite/ort/cv/pfld98.cpp +++ b/lite/ort/cv/pfld98.cpp @@ -44,8 +44,8 @@ void PFLD98::detect(const cv::Mat &mat, types::Landmarks &landmarks) float x = landmarks_norm.At({0, i}); float y = landmarks_norm.At({0, i + 1}); - x = std::fmin(std::fmax(0., x), 1.0f); - y = std::fmin(std::fmax(0., y), 1.0f); + x = std::min(std::max(0.f, x), 1.0f); + y = std::min(std::max(0.f, y), 1.0f); landmarks.points.push_back(cv::Point2f(x * img_width, y * img_height)); } diff --git a/lite/ort/cv/retinaface.cpp b/lite/ort/cv/retinaface.cpp index 401974ae..86235791 100644 --- a/lite/ort/cv/retinaface.cpp +++ b/lite/ort/cv/retinaface.cpp @@ -54,8 +54,8 @@ void RetinaFace::generate_anchors(const int target_height, { feature_maps.push_back( { - (int) std::ceilf((float) target_height / (float) step), - (int) std::ceilf((float) target_width / (float) step) + (int) std::ceil((float) target_height / (float) step), + (int) std::ceil((float) target_width / (float) step) } // ceil ); } @@ -131,8 +131,8 @@ void RetinaFace::generate_bboxes(std::vector &bbox_collection, // ref: https://github.com/biubug6/Pytorch_Retinaface/blob/master/utils/box_utils.py float cx = prior_cx + dx * variance[0] * prior_s_kx; float cy = prior_cy + dy * variance[0] * prior_s_ky; - float w = prior_s_kx * std::expf(dw * variance[1]); - float h = prior_s_ky * std::expf(dh * variance[1]); // norm coor (0.,1.) + float w = prior_s_kx * std::exp(dw * variance[1]); + float h = prior_s_ky * std::exp(dh * variance[1]); // norm coor (0.,1.) types::Boxf box; box.x1 = (cx - w / 2.f) * img_width; diff --git a/lite/ort/cv/tiny_yolov3.cpp b/lite/ort/cv/tiny_yolov3.cpp index 611e5325..b7a9088a 100644 --- a/lite/ort/cv/tiny_yolov3.cpp +++ b/lite/ort/cv/tiny_yolov3.cpp @@ -88,7 +88,7 @@ std::vector TinyYoloV3::transform(const std::vector &mats) const unsigned int image_height = canvas.rows; const unsigned int image_width = canvas.cols; - const float scale = std::fmin( + const float scale = std::min( (float) input_width / (float) image_width, (float) input_height / (float) image_height ); diff --git a/lite/ort/cv/yolop.cpp b/lite/ort/cv/yolop.cpp index 42169897..c2c14c47 100644 --- a/lite/ort/cv/yolop.cpp +++ b/lite/ort/cv/yolop.cpp @@ -20,7 +20,7 @@ void YOLOP::resize_unscale(const cv::Mat &mat, cv::Mat &mat_rs, // scale ratio (new / old) new_shape(h,w) float w_r = (float) target_width / (float) img_width; float h_r = (float) target_height / (float) img_height; - float r = std::fmin(w_r, h_r); + float r = std::min(w_r, h_r); // compute padding int new_unpad_w = static_cast((float) img_width * r); // floor int new_unpad_h = static_cast((float) img_height * r); // floor diff --git a/lite/ort/cv/yolov3.cpp b/lite/ort/cv/yolov3.cpp index fc4630bc..4326c446 100644 --- a/lite/ort/cv/yolov3.cpp +++ b/lite/ort/cv/yolov3.cpp @@ -88,7 +88,7 @@ std::vector YoloV3::transform(const std::vector &mats) const unsigned int image_height = canvas.rows; const unsigned int image_width = canvas.cols; - const float scale = std::fmin( + const float scale = std::min( (float) input_width / (float) image_width, (float) input_height / (float) image_height ); diff --git a/lite/ort/cv/yolox.cpp b/lite/ort/cv/yolox.cpp index 6b3ea839..a506be00 100644 --- a/lite/ort/cv/yolox.cpp +++ b/lite/ort/cv/yolox.cpp @@ -153,8 +153,8 @@ void YoloX::generate_bboxes(std::vector &bbox_collection, float cx = (dx + (float) grid0) * (float) stride; float cy = (dy + (float) grid1) * (float) stride; - float w = std::expf(dw) * (float) stride; - float h = std::expf(dh) * (float) stride; + float w = std::exp(dw) * (float) stride; + float h = std::exp(dh) * (float) stride; types::Boxf box; box.x1 = (cx - w / 2.f) * scale_width; diff --git a/lite/tnn/cv/tnn_nanodet.cpp b/lite/tnn/cv/tnn_nanodet.cpp index 6a1eca23..bf3e354b 100644 --- a/lite/tnn/cv/tnn_nanodet.cpp +++ b/lite/tnn/cv/tnn_nanodet.cpp @@ -27,7 +27,7 @@ void TNNNanoDet::resize_unscale(const cv::Mat &mat, cv::Mat &mat_rs, // scale ratio (new / old) new_shape(h,w) float w_r = (float) target_width / (float) img_width; float h_r = (float) target_height / (float) img_height; - float r = std::fmin(w_r, h_r); + float r = std::min(w_r, h_r); // compute padding int new_unpad_w = static_cast((float) img_width * r); // floor int new_unpad_h = static_cast((float) img_height * r); // floor @@ -257,10 +257,10 @@ void TNNNanoDet::generate_bboxes_single_stride(const NanoScaleParams &scale_para float y1 = ((cy - t) * s - (float) dh) / ratio; // cy - t y1 float x2 = ((cx + r) * s - (float) dw) / ratio; // cx + r x2 float y2 = ((cy + b) * s - (float) dh) / ratio; // cy + b y2 - box.x1 = std::fmax(0.f, x1); - box.y1 = std::fmax(0.f, y1); - box.x2 = std::fmin(img_width, x2); - box.y2 = std::fmin(img_height, y2); + box.x1 = std::max(0.f, x1); + box.y1 = std::max(0.f, y1); + box.x2 = std::min(img_width, x2); + box.y2 = std::min(img_height, y2); box.score = cls_conf; box.label = label; box.label_text = class_names[label]; diff --git a/lite/tnn/cv/tnn_nanodet_efficientnet_lite.cpp b/lite/tnn/cv/tnn_nanodet_efficientnet_lite.cpp index 34d9d4f2..770423ee 100644 --- a/lite/tnn/cv/tnn_nanodet_efficientnet_lite.cpp +++ b/lite/tnn/cv/tnn_nanodet_efficientnet_lite.cpp @@ -27,7 +27,7 @@ void TNNNanoDetEfficientNetLite::resize_unscale(const cv::Mat &mat, cv::Mat &mat // scale ratio (new / old) new_shape(h,w) float w_r = (float) target_width / (float) img_width; float h_r = (float) target_height / (float) img_height; - float r = std::fmin(w_r, h_r); + float r = std::min(w_r, h_r); // compute padding int new_unpad_w = static_cast((float) img_width * r); // floor int new_unpad_h = static_cast((float) img_height * r); // floor @@ -256,10 +256,10 @@ void TNNNanoDetEfficientNetLite::generate_bboxes_single_stride(const NanoLiteSca float y1 = ((cy - t) * s - (float) dh) / ratio; // cy - t y1 float x2 = ((cx + r) * s - (float) dw) / ratio; // cx + r x2 float y2 = ((cy + b) * s - (float) dh) / ratio; // cy + b y2 - box.x1 = std::fmax(0.f, x1); - box.y1 = std::fmax(0.f, y1); - box.x2 = std::fmin(img_width, x2); - box.y2 = std::fmin(img_height, y2); + box.x1 = std::max(0.f, x1); + box.y1 = std::max(0.f, y1); + box.x2 = std::min(img_width, x2); + box.y2 = std::min(img_height, y2); box.score = cls_conf; box.label = label; box.label_text = class_names[label]; diff --git a/lite/tnn/cv/tnn_yolop.cpp b/lite/tnn/cv/tnn_yolop.cpp index a050d74a..11e01cae 100644 --- a/lite/tnn/cv/tnn_yolop.cpp +++ b/lite/tnn/cv/tnn_yolop.cpp @@ -27,7 +27,7 @@ void TNNYOLOP::resize_unscale(const cv::Mat &mat, cv::Mat &mat_rs, // scale ratio (new / old) new_shape(h,w) float w_r = (float) target_width / (float) img_width; float h_r = (float) target_height / (float) img_height; - float r = std::fmin(w_r, h_r); + float r = std::min(w_r, h_r); // compute padding int new_unpad_w = static_cast((float) img_width * r); // floor int new_unpad_h = static_cast((float) img_height * r); // floor diff --git a/lite/tnn/cv/tnn_yolox.cpp b/lite/tnn/cv/tnn_yolox.cpp index 86da72ea..32625e48 100644 --- a/lite/tnn/cv/tnn_yolox.cpp +++ b/lite/tnn/cv/tnn_yolox.cpp @@ -164,8 +164,8 @@ void TNNYoloX::generate_bboxes(std::vector &bbox_collection, float cx = (dx + (float) grid0) * (float) stride; float cy = (dy + (float) grid1) * (float) stride; - float w = std::expf(dw) * (float) stride; - float h = std::expf(dh) * (float) stride; + float w = std::exp(dw) * (float) stride; + float h = std::exp(dh) * (float) stride; types::Boxf box; box.x1 = (cx - w / 2.f) * scale_width; diff --git a/lite/utils.cpp b/lite/utils.cpp index 2437984e..805bd6a2 100644 --- a/lite/utils.cpp +++ b/lite/utils.cpp @@ -29,8 +29,8 @@ std::wstring lite::utils::to_wstring(const std::string &str) // reference: https://github.com/DefTruth/headpose-fsanet-pytorch/blob/master/src/utils.py void lite::utils::draw_axis_inplace(cv::Mat &mat_inplace, - const types::EulerAngles &euler_angles, - float size, int thickness) + const types::EulerAngles &euler_angles, + float size, int thickness) { if (!euler_angles.flag) return; @@ -45,20 +45,20 @@ void lite::utils::draw_axis_inplace(cv::Mat &mat_inplace, const int tdy = static_cast(height / 2.0f); // X-Axis pointing to right. drawn in red - const int x1 = static_cast(size * std::cosf(yaw) * std::cosf(roll)) + tdx; + const int x1 = static_cast(size * std::cos(yaw) * std::cos(roll)) + tdx; const int y1 = static_cast( - size * (std::cosf(pitch) * std::sinf(roll) - + std::cosf(roll) * std::sinf(pitch) * std::sinf(yaw)) + size * (std::cos(pitch) * std::sin(roll) + + std::cos(roll) * std::sin(pitch) * std::sin(yaw)) ) + tdy; // Y-Axis | drawn in green - const int x2 = static_cast(-size * std::cosf(yaw) * std::sinf(roll)) + tdx; + const int x2 = static_cast(-size * std::cos(yaw) * std::sin(roll)) + tdx; const int y2 = static_cast( - size * (std::cosf(pitch) * std::cosf(roll) - - std::sinf(pitch) * std::sinf(yaw) * std::sinf(roll)) + size * (std::cos(pitch) * std::cos(roll) + - std::sin(pitch) * std::sin(yaw) * std::sin(roll)) ) + tdy; // Z-Axis (out of the screen) drawn in blue - const int x3 = static_cast(size * std::sinf(yaw)) + tdx; - const int y3 = static_cast(-size * std::cosf(yaw) * std::sinf(pitch)) + tdy; + const int x3 = static_cast(size * std::sin(yaw)) + tdx; + const int y3 = static_cast(-size * std::cos(yaw) * std::sin(pitch)) + tdy; cv::line(mat_inplace, cv::Point2i(tdx, tdy), cv::Point2i(x1, y1), cv::Scalar(0, 0, 255), thickness); cv::line(mat_inplace, cv::Point2i(tdx, tdy), cv::Point2i(x2, y2), cv::Scalar(0, 255, 0), thickness); @@ -66,8 +66,8 @@ void lite::utils::draw_axis_inplace(cv::Mat &mat_inplace, } cv::Mat lite::utils::draw_axis(const cv::Mat &mat, - const types::EulerAngles &euler_angles, - float size, int thickness) + const types::EulerAngles &euler_angles, + float size, int thickness) { if (!euler_angles.flag) return mat; @@ -83,20 +83,20 @@ cv::Mat lite::utils::draw_axis(const cv::Mat &mat, const int tdy = static_cast(height / 2.0f); // X-Axis pointing to right. drawn in red - const int x1 = static_cast(size * std::cosf(yaw) * std::cosf(roll)) + tdx; + const int x1 = static_cast(size * std::cos(yaw) * std::cos(roll)) + tdx; const int y1 = static_cast( - size * (std::cosf(pitch) * std::sinf(roll) - + std::cosf(roll) * std::sinf(pitch) * std::sinf(yaw)) + size * (std::cos(pitch) * std::sin(roll) + + std::cos(roll) * std::sin(pitch) * std::sin(yaw)) ) + tdy; // Y-Axis | drawn in green - const int x2 = static_cast(-size * std::cosf(yaw) * std::sinf(roll)) + tdx; + const int x2 = static_cast(-size * std::cos(yaw) * std::sin(roll)) + tdx; const int y2 = static_cast( - size * (std::cosf(pitch) * std::cosf(roll) - - std::sinf(pitch) * std::sinf(yaw) * std::sinf(roll)) + size * (std::cos(pitch) * std::cos(roll) + - std::sin(pitch) * std::sin(yaw) * std::sin(roll)) ) + tdy; // Z-Axis (out of the screen) drawn in blue - const int x3 = static_cast(size * std::sinf(yaw)) + tdx; - const int y3 = static_cast(-size * std::cosf(yaw) * std::sinf(pitch)) + tdy; + const int x3 = static_cast(size * std::sin(yaw)) + tdx; + const int y3 = static_cast(-size * std::cos(yaw) * std::sin(pitch)) + tdy; cv::line(mat_copy, cv::Point2i(tdx, tdy), cv::Point2i(x1, y1), cv::Scalar(0, 0, 255), thickness); cv::line(mat_copy, cv::Point2i(tdx, tdy), cv::Point2i(x2, y2), cv::Scalar(0, 255, 0), thickness); @@ -250,7 +250,7 @@ void lite::utils::draw_emotion_inplace(cv::Mat &mat_inplace, types::Emotions &em // reference: https://github.com/Linzaer/Ultra-Light-Fast-Generic-Face-Detector-1MB/ // blob/master/ncnn/src/UltraFace.cpp void lite::utils::hard_nms(std::vector &input, std::vector &output, - float iou_threshold, unsigned int topk) + float iou_threshold, unsigned int topk) { if (input.empty()) return; std::sort(input.begin(), input.end(), @@ -291,7 +291,7 @@ void lite::utils::hard_nms(std::vector &input, std::vector &input, std::vector &output, - float iou_threshold, unsigned int topk) + float iou_threshold, unsigned int topk) { if (input.empty()) return; std::sort(input.begin(), input.end(), @@ -324,12 +324,12 @@ void lite::utils::blending_nms(std::vector &input, std::vector &input, std::vector &input, std::vector &output, - float iou_threshold, unsigned int topk) + float iou_threshold, unsigned int topk) { if (input.empty()) return; std::sort(input.begin(), input.end(), diff --git a/lite/utils.h b/lite/utils.h index e118d3b0..c61798f7 100644 --- a/lite/utils.h +++ b/lite/utils.h @@ -54,12 +54,12 @@ namespace lite namespace math { template - std::vector softmax(const std::vector &logits, unsigned int &max_id); + std::vector softmax(const std::vector &logits, unsigned int &max_id); template LITE_EXPORTS std::vector softmax(const std::vector &logits, unsigned int &max_id); template - std::vector softmax(const T *logits, unsigned int _size, unsigned int &max_id); + std::vector softmax(const T *logits, unsigned int _size, unsigned int &max_id); template LITE_EXPORTS std::vector softmax(const float *logits, unsigned int _size, unsigned int &max_id); @@ -74,7 +74,7 @@ namespace lite template LITE_EXPORTS std::vector argsort(const float *arr, unsigned int _size); template - T cosine_similarity(const std::vector &a, const std::vector &b); + float cosine_similarity(const std::vector &a, const std::vector &b); template LITE_EXPORTS float cosine_similarity(const std::vector &a, const std::vector &b); } @@ -83,15 +83,15 @@ namespace lite } template -std::vector lite::utils::math::softmax(const T *logits, unsigned int _size, unsigned int &max_id) +std::vector lite::utils::math::softmax(const T *logits, unsigned int _size, unsigned int &max_id) { types::__assert_type(); if (_size == 0 || logits == nullptr) return {}; - T max_prob = static_cast(0), total_exp = static_cast(0); + float max_prob = 0.f, total_exp = 0.f; std::vector softmax_probs(_size); for (unsigned int i = 0; i < _size; ++i) { - softmax_probs[i] = std::expf(logits[i]); + softmax_probs[i] = std::exp((float) logits[i]); total_exp += softmax_probs[i]; } for (unsigned int i = 0; i < _size; ++i) @@ -107,16 +107,16 @@ std::vector lite::utils::math::softmax(const T *logits, unsigned int _size, u } template -std::vector lite::utils::math::softmax(const std::vector &logits, unsigned int &max_id) +std::vector lite::utils::math::softmax(const std::vector &logits, unsigned int &max_id) { types::__assert_type(); if (logits.empty()) return {}; const unsigned int _size = logits.size(); - T max_prob = static_cast(0), total_exp = static_cast(0); + float max_prob = 0.f, total_exp = 0.f; std::vector softmax_probs(_size); for (unsigned int i = 0; i < _size; ++i) { - softmax_probs[i] = std::expf(logits[i]); + softmax_probs[i] = std::exp((float) logits[i]); total_exp += softmax_probs[i]; } for (unsigned int i = 0; i < _size; ++i) @@ -159,21 +159,21 @@ std::vector lite::utils::math::argsort(const T *arr, unsigned int } template -T lite::utils::math::cosine_similarity(const std::vector &a, const std::vector &b) +float lite::utils::math::cosine_similarity(const std::vector &a, const std::vector &b) { types::__assert_type(); - T zero_vale = static_cast(0); + float zero_vale = 0.f; if (a.empty() || b.empty() || (a.size() != b.size())) return zero_vale; const unsigned int _size = a.size(); - T mul_a = zero_vale, mul_b = zero_vale, mul_ab = zero_vale; + float mul_a = zero_vale, mul_b = zero_vale, mul_ab = zero_vale; for (unsigned int i = 0; i < _size; ++i) { - mul_a += a[i] * a[i]; - mul_b += b[i] * b[i]; - mul_ab += a[i] * b[i]; + mul_a += (float) a[i] * (float) a[i]; + mul_b += (float) b[i] * (float) b[i]; + mul_ab += (float) a[i] * (float) b[i]; } if (mul_a == zero_vale || mul_b == zero_vale) return zero_vale; - return static_cast(mul_ab / (std::sqrt(mul_a) * std::sqrt(mul_b))); + return (mul_ab / (std::sqrt(mul_a) * std::sqrt(mul_b))); } #endif //LITE_AI_TOOLKIT_UTILS_H From 11df38615bd94977750fdec60c67bfb1c24324d0 Mon Sep 17 00:00:00 2001 From: DefTruth Date: Tue, 26 Oct 2021 23:40:46 +0800 Subject: [PATCH 2/2] fixed Ubuntu+gcc build error for std::xxxf (#81) --- lite/mnn/cv/mnn_rvm.h | 2 +- lite/ncnn/cv/ncnn_rvm.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lite/mnn/cv/mnn_rvm.h b/lite/mnn/cv/mnn_rvm.h index 15de56b5..f30b53cf 100644 --- a/lite/mnn/cv/mnn_rvm.h +++ b/lite/mnn/cv/mnn_rvm.h @@ -14,7 +14,7 @@ namespace mnncv public: explicit MNNRobustVideoMatting(const std::string &_mnn_path, unsigned int _num_threads = 1, - unsigned int _variant_type = VARIANT::MOBILENETV3); // + unsigned int _variant_type = 0); // ~MNNRobustVideoMatting(); private: diff --git a/lite/ncnn/cv/ncnn_rvm.h b/lite/ncnn/cv/ncnn_rvm.h index 470cfd52..c60e36ff 100644 --- a/lite/ncnn/cv/ncnn_rvm.h +++ b/lite/ncnn/cv/ncnn_rvm.h @@ -17,7 +17,7 @@ namespace ncnncv unsigned int _num_threads = 1, int _input_height = 480, int _input_width = 640, - unsigned int _variant_type = VARIANT::MOBILENETV3); // + unsigned int _variant_type = 0); // ~NCNNRobustVideoMatting() override = default; private: