From 195a4dd960e75262a4baa175c5af54cc74b0a01d Mon Sep 17 00:00:00 2001 From: fawdlstty Date: Tue, 13 Oct 2020 15:47:26 +0800 Subject: [PATCH] Fixed compile warning due to default cast --- benchmark/benchncnn.cpp | 6 +++++- src/layer/roialign.cpp | 16 ++++++++-------- src/layer/x86/roialign_x86.cpp | 26 +++++++++++++------------- src/mat_pixel_affine.cpp | 24 ++++++++++++------------ tools/mxnet/mxnet2ncnn.cpp | 12 ++++++------ 5 files changed, 44 insertions(+), 40 deletions(-) diff --git a/benchmark/benchncnn.cpp b/benchmark/benchncnn.cpp index 865326bfd48..ea68ea7340c 100644 --- a/benchmark/benchncnn.cpp +++ b/benchmark/benchncnn.cpp @@ -1,4 +1,4 @@ -// Tencent is pleased to support the open source community by making ncnn available. +// Tencent is pleased to support the open source community by making ncnn available. // // Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. // @@ -12,6 +12,10 @@ // CONDITIONS OF ANY KIND, either express or implied. See the License for the // specific language governing permissions and limitations under the License. +#ifdef _WIN32 +#define _CRT_SECURE_NO_WARNINGS +#endif + #include #include #include diff --git a/src/layer/roialign.cpp b/src/layer/roialign.cpp index 6f8822095c4..30555c433f9 100644 --- a/src/layer/roialign.cpp +++ b/src/layer/roialign.cpp @@ -1,4 +1,4 @@ -// Tencent is pleased to support the open source community by making ncnn available. +// Tencent is pleased to support the open source community by making ncnn available. // // Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. // @@ -44,9 +44,9 @@ int ROIAlign::load_param(const ParamDict& pd) static inline float bilinear_interpolate(const float* ptr, int w, int h, float x, float y) { - int x0 = x; + int x0 = (int)x; int x1 = x0 + 1; - int y0 = y; + int y0 = (int)y; int y1 = y0 + 1; float a0 = x1 - x; @@ -143,8 +143,8 @@ int ROIAlign::forward(const std::vector& bottom_blobs, std::vector& to hend = std::min(std::max(hend, 0.f), (float)h); wend = std::min(std::max(wend, 0.f), (float)w); - int bin_grid_h = sampling_ratio > 0 ? sampling_ratio : ceil(hend - hstart); - int bin_grid_w = sampling_ratio > 0 ? sampling_ratio : ceil(wend - wstart); + int bin_grid_h = (int)(sampling_ratio > 0 ? sampling_ratio : ceil(hend - hstart)); + int bin_grid_w = (int)(sampling_ratio > 0 ? sampling_ratio : ceil(wend - wstart)); bool is_empty = (hend <= hstart) || (wend <= wstart); int area = bin_grid_h * bin_grid_w; @@ -175,10 +175,10 @@ int ROIAlign::forward(const std::vector& bottom_blobs, std::vector& to else if (version == 1) { // the version in detectron 2 - int roi_bin_grid_h = sampling_ratio > 0 ? sampling_ratio : ceil(roi_h / pooled_height); - int roi_bin_grid_w = sampling_ratio > 0 ? sampling_ratio : ceil(roi_w / pooled_width); + int roi_bin_grid_h = (int)(sampling_ratio > 0 ? sampling_ratio : ceil(roi_h / pooled_height)); + int roi_bin_grid_w = (int)(sampling_ratio > 0 ? sampling_ratio : ceil(roi_w / pooled_width)); - const float count = std::max(roi_bin_grid_h * roi_bin_grid_w, 1); + const float count = (float)std::max(roi_bin_grid_h * roi_bin_grid_w, 1); #pragma omp parallel for num_threads(opt.num_threads) for (int q = 0; q < channels; q++) diff --git a/src/layer/x86/roialign_x86.cpp b/src/layer/x86/roialign_x86.cpp index db558ae4843..746757f13b4 100644 --- a/src/layer/x86/roialign_x86.cpp +++ b/src/layer/x86/roialign_x86.cpp @@ -1,4 +1,4 @@ -// Tencent is pleased to support the open source community by making ncnn available. +// Tencent is pleased to support the open source community by making ncnn available. // // Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. // @@ -116,7 +116,7 @@ void detectron2_pre_calc_for_bilinear_interpolate( T ly = y - y_low; T lx = x - x_low; - T hy = 1. - ly, hx = 1. - lx; + T hy = (T)(1. - ly), hx = (T)(1. - lx); T w1 = hy * hx, w2 = hy * lx, w3 = ly * hx, w4 = ly * lx; // save weights and indices @@ -163,8 +163,8 @@ void original_pre_calc_for_bilinear_interpolate( hend = std::min(std::max(hend, 0.f), (float)height); wend = std::min(std::max(wend, 0.f), (float)width); - int bin_grid_h = sampling_ratio > 0 ? sampling_ratio : ceil(hend - hstart); - int bin_grid_w = sampling_ratio > 0 ? sampling_ratio : ceil(wend - wstart); + int bin_grid_h = (int)(sampling_ratio > 0 ? sampling_ratio : ceil(hend - hstart)); + int bin_grid_w = (int)(sampling_ratio > 0 ? sampling_ratio : ceil(wend - wstart)); for (int by = 0; by < bin_grid_h; by++) { @@ -173,9 +173,9 @@ void original_pre_calc_for_bilinear_interpolate( for (int bx = 0; bx < bin_grid_w; bx++) { float x = wstart + (bx + 0.5f) * bin_size_w / (float)bin_grid_w; - int x0 = x; + int x0 = (int)x; int x1 = x0 + 1; - int y0 = y; + int y0 = (int)y; int y1 = y0 + 1; float a0 = x1 - x; @@ -261,8 +261,8 @@ int ROIAlign_x86::forward(const std::vector& bottom_blobs, std::vector if (version == 0) { // original version - int roi_bin_grid_h = sampling_ratio > 0 ? sampling_ratio : ceil(roi_height / pooled_height); - int roi_bin_grid_w = sampling_ratio > 0 ? sampling_ratio : ceil(roi_width / pooled_width); + int roi_bin_grid_h = (int)(sampling_ratio > 0 ? sampling_ratio : ceil(roi_height / pooled_height)); + int roi_bin_grid_w = (int)(sampling_ratio > 0 ? sampling_ratio : ceil(roi_width / pooled_width)); std::vector > pre_calc( roi_bin_grid_h * roi_bin_grid_w * pooled_width * pooled_height); original_pre_calc_for_bilinear_interpolate( @@ -301,8 +301,8 @@ int ROIAlign_x86::forward(const std::vector& bottom_blobs, std::vector hend = std::min(std::max(hend, 0.f), (float)height); wend = std::min(std::max(wend, 0.f), (float)width); - int bin_grid_h = sampling_ratio > 0 ? sampling_ratio : ceil(hend - hstart); - int bin_grid_w = sampling_ratio > 0 ? sampling_ratio : ceil(wend - wstart); + int bin_grid_h = (int)(sampling_ratio > 0 ? sampling_ratio : ceil(hend - hstart)); + int bin_grid_w = (int)(sampling_ratio > 0 ? sampling_ratio : ceil(wend - wstart)); bool is_empty = (hend <= hstart) || (wend <= wstart); int area = bin_grid_h * bin_grid_w; @@ -327,10 +327,10 @@ int ROIAlign_x86::forward(const std::vector& bottom_blobs, std::vector else if (version == 1) { // the version in detectron 2 - int roi_bin_grid_h = sampling_ratio > 0 ? sampling_ratio : ceil(roi_height / pooled_height); - int roi_bin_grid_w = sampling_ratio > 0 ? sampling_ratio : ceil(roi_width / pooled_width); + int roi_bin_grid_h = (int)(sampling_ratio > 0 ? sampling_ratio : ceil(roi_height / pooled_height)); + int roi_bin_grid_w = (int)(sampling_ratio > 0 ? sampling_ratio : ceil(roi_width / pooled_width)); - const float count = std::max(roi_bin_grid_h * roi_bin_grid_w, 1); + const float count = (float)std::max(roi_bin_grid_h * roi_bin_grid_w, 1); std::vector > pre_calc( roi_bin_grid_h * roi_bin_grid_w * pooled_width * pooled_height); diff --git a/src/mat_pixel_affine.cpp b/src/mat_pixel_affine.cpp index 79dcc0a1b45..5a17e9a691c 100644 --- a/src/mat_pixel_affine.cpp +++ b/src/mat_pixel_affine.cpp @@ -1,4 +1,4 @@ -// Tencent is pleased to support the open source community by making ncnn available. +// Tencent is pleased to support the open source community by making ncnn available. // // Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. // @@ -60,7 +60,7 @@ void get_affine_transform(const float* points_from, const float* points_to, int ma[1][1] = ma[0][0]; ma[2][1] = ma[1][2] = -ma[0][3]; ma[3][1] = ma[1][3] = ma[2][0] = ma[0][2]; - ma[2][2] = ma[3][3] = num_point; + ma[2][2] = ma[3][3] = (float)num_point; ma[3][0] = ma[0][3]; // MM = inv(A) * B @@ -208,7 +208,7 @@ void warpaffine_bilinear_c1(const unsigned char* src, int srcw, int srch, int sr const unsigned char* b0 = src0 + srcstride * (sy + 1) + sx; const unsigned char* b1 = src0 + srcstride * (sy + 1) + sx + 1; - *dst0 = (*a0 * (1.f - fx) + *a1 * fx) * (1.f - fy) + (*b0 * (1.f - fx) + *b1 * fx) * fy; + *dst0 = (unsigned char)((*a0 * (1.f - fx) + *a1 * fx) * (1.f - fy) + (*b0 * (1.f - fx) + *b1 * fx) * fy); } dst0 += 1; @@ -257,8 +257,8 @@ void warpaffine_bilinear_c2(const unsigned char* src, int srcw, int srch, int sr const unsigned char* b0 = src0 + srcstride * (sy + 1) + sx * 2; const unsigned char* b1 = src0 + srcstride * (sy + 1) + sx * 2 + 2; - dst0[0] = (a0[0] * (1.f - fx) + a1[0] * fx) * (1.f - fy) + (b0[0] * (1.f - fx) + b1[0] * fx) * fy; - dst0[1] = (a0[1] * (1.f - fx) + a1[1] * fx) * (1.f - fy) + (b0[1] * (1.f - fx) + b1[1] * fx) * fy; + dst0[0] = (unsigned char)((a0[0] * (1.f - fx) + a1[0] * fx) * (1.f - fy) + (b0[0] * (1.f - fx) + b1[0] * fx) * fy); + dst0[1] = (unsigned char)((a0[1] * (1.f - fx) + a1[1] * fx) * (1.f - fy) + (b0[1] * (1.f - fx) + b1[1] * fx) * fy); } dst0 += 2; @@ -308,9 +308,9 @@ void warpaffine_bilinear_c3(const unsigned char* src, int srcw, int srch, int sr const unsigned char* b0 = src0 + srcstride * (sy + 1) + sx * 3; const unsigned char* b1 = src0 + srcstride * (sy + 1) + sx * 3 + 3; - dst0[0] = (a0[0] * (1.f - fx) + a1[0] * fx) * (1.f - fy) + (b0[0] * (1.f - fx) + b1[0] * fx) * fy; - dst0[1] = (a0[1] * (1.f - fx) + a1[1] * fx) * (1.f - fy) + (b0[1] * (1.f - fx) + b1[1] * fx) * fy; - dst0[2] = (a0[2] * (1.f - fx) + a1[2] * fx) * (1.f - fy) + (b0[2] * (1.f - fx) + b1[2] * fx) * fy; + dst0[0] = (unsigned char)((a0[0] * (1.f - fx) + a1[0] * fx) * (1.f - fy) + (b0[0] * (1.f - fx) + b1[0] * fx) * fy); + dst0[1] = (unsigned char)((a0[1] * (1.f - fx) + a1[1] * fx) * (1.f - fy) + (b0[1] * (1.f - fx) + b1[1] * fx) * fy); + dst0[2] = (unsigned char)((a0[2] * (1.f - fx) + a1[2] * fx) * (1.f - fy) + (b0[2] * (1.f - fx) + b1[2] * fx) * fy); } dst0 += 3; @@ -361,10 +361,10 @@ void warpaffine_bilinear_c4(const unsigned char* src, int srcw, int srch, int sr const unsigned char* b0 = src0 + srcstride * (sy + 1) + sx * 4; const unsigned char* b1 = src0 + srcstride * (sy + 1) + sx * 4 + 4; - dst0[0] = (a0[0] * (1.f - fx) + a1[0] * fx) * (1.f - fy) + (b0[0] * (1.f - fx) + b1[0] * fx) * fy; - dst0[1] = (a0[1] * (1.f - fx) + a1[1] * fx) * (1.f - fy) + (b0[1] * (1.f - fx) + b1[1] * fx) * fy; - dst0[2] = (a0[2] * (1.f - fx) + a1[2] * fx) * (1.f - fy) + (b0[2] * (1.f - fx) + b1[2] * fx) * fy; - dst0[3] = (a0[3] * (1.f - fx) + a1[3] * fx) * (1.f - fy) + (b0[3] * (1.f - fx) + b1[3] * fx) * fy; + dst0[0] = (unsigned char)((a0[0] * (1.f - fx) + a1[0] * fx) * (1.f - fy) + (b0[0] * (1.f - fx) + b1[0] * fx) * fy); + dst0[1] = (unsigned char)((a0[1] * (1.f - fx) + a1[1] * fx) * (1.f - fy) + (b0[1] * (1.f - fx) + b1[1] * fx) * fy); + dst0[2] = (unsigned char)((a0[2] * (1.f - fx) + a1[2] * fx) * (1.f - fy) + (b0[2] * (1.f - fx) + b1[2] * fx) * fy); + dst0[3] = (unsigned char)((a0[3] * (1.f - fx) + a1[3] * fx) * (1.f - fy) + (b0[3] * (1.f - fx) + b1[3] * fx) * fy); } dst0 += 4; diff --git a/tools/mxnet/mxnet2ncnn.cpp b/tools/mxnet/mxnet2ncnn.cpp index f20b616c1af..5dcb5c63f9e 100644 --- a/tools/mxnet/mxnet2ncnn.cpp +++ b/tools/mxnet/mxnet2ncnn.cpp @@ -1,4 +1,4 @@ -// Tencent is pleased to support the open source community by making ncnn available. +// Tencent is pleased to support the open source community by making ncnn available. // // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. // @@ -176,7 +176,7 @@ std::vector MXNetNode::attr_ai(const char* key) const int i = 0; int c = 0; int nconsumed = 0; - int nscan = sscanf(it->second.c_str() + c, "%*[\[(,]%d%n", &i, &nconsumed); + int nscan = sscanf(it->second.c_str() + c, "%*[\\[(,]%d%n", &i, &nconsumed); if (nscan != 1) { // (None @@ -261,9 +261,9 @@ bool MXNetNode::has_weight(int i) const const std::string& name = (*nodes)[weights[i]].name; - for (int i = 0; i < (int)(*params).size(); i++) + for (int j = 0; j < (int)(*params).size(); j++) { - const MXNetParam& p = (*params)[i]; + const MXNetParam& p = (*params)[j]; if (p.name == name) return true; } @@ -278,9 +278,9 @@ std::vector MXNetNode::weight(int i, int init_len) const const std::string& name = (*nodes)[weights[i]].name; - for (int i = 0; i < (int)(*params).size(); i++) + for (int j = 0; j < (int)(*params).size(); j++) { - const MXNetParam& p = (*params)[i]; + const MXNetParam& p = (*params)[j]; if (p.name != name) continue;