From 9bfc554bc967e9a40581fcd634e49f8062bffc6c Mon Sep 17 00:00:00 2001 From: Sungmann Cho Date: Tue, 24 Dec 2019 23:58:05 +0900 Subject: [PATCH] Fix warnings on Visual Studio (#1431) * Fix warnings C4244, C4267 in src/layer/yolov3detectionoutput.cpp C4244: '=': conversion from 'int' to 'float', possible loss of data C4244: 'initializing': conversion from 'float' to 'int', possible loss of data C4244: 'initializing': conversion from 'double' to 'float', possible loss of data C4244: 'return': conversion from 'double' to 'float', possible loss of data C4267: 'argument': conversion from 'size_t' to 'int', possible loss of data C4267: 'initializing': conversion from 'size_t' to 'int', possible loss of data * Fix warnings C4244, C4267 in src/layer/yolodetectionoutput.cpp C4244: '=': conversion from 'int' to 'float', possible loss of data C4244: 'initializing': conversion from 'float' to 'int', possible loss of data C4244: 'initializing': conversion from 'double' to 'float', possible loss of data C4244: 'return': conversion from 'double' to 'float', possible loss of data C4267: 'argument': conversion from 'size_t' to 'int', possible loss of data C4267: 'initializing': conversion from 'size_t' to 'int', possible loss of data * Fix warning C4244 in src/layer/quantize.cpp C4244: 'initializing': conversion from 'double' to 'int', possible loss of data * Fix warnings C4244, C4267 in src/layer/detectionoutput.cpp C4244: '=': conversion from 'int' to 'float', possible loss of data C4244: 'initializing': conversion from 'double' to 'float', possible loss of data C4267: 'argument': conversion from 'size_t' to 'int', possible loss of data C4267: 'initializing': conversion from 'size_t' to 'int', possible loss of data * Fix warning C4244 in src/layer/roipooling.cpp C4244: 'initializing': conversion from 'double' to 'int', possible loss of data * Fix warning C4244 in src/layer/sigmoid.cpp C4244: '=': conversion from 'double' to 'float', possible loss of data * Fix warning C4267 in src/layer/slice.cpp C4267: '=': conversion from 'size_t' to 'int', possible loss of data C4267: 'initializing': conversion from 'size_t' to 'int', possible loss of data * Fix warning C4267 in src/layer/softmax.cpp C4244: '=': conversion from 'double' to 'float', possible loss of data * Fix warning C4244 in src/layer/interp.cpp C4244: '=': conversion from 'float' to 'int', possible loss of data C4244: 'initializing': conversion from 'double' to 'int', possible loss of data * Fix warning C4244 in src/layer/instancenorm.cpp C4244: 'initializing': conversion from 'double' to 'float', possible loss of data * Fix warning C4244 in src/layer/deconvolutiondepthwise.cpp C4244: '=': conversion from 'double' to 'float', possible loss of data * Fix warning C4244 in src/layer/convolutiondepthwise.cpp C4244: '=': conversion from 'double' to 'float', possible loss of data * Fix warning C4244 in src/net.cpp C4244: 'return': conversion from '__int64' to 'int', possible loss of data C4267: 'argument': conversion from 'size_t' to 'int', possible loss of data C4267: 'initializing': conversion from 'size_t' to 'int', possible loss of data C4267: 'return': conversion from 'size_t' to 'int', possible loss of data * Fix warning C4244 in src/layer/bnll.cpp C4244: '=': conversion from 'double' to 'float', possible loss of data * Fix warning C4267 in src/layer/concat.cpp C4267: 'initializing': conversion from 'size_t' to 'int', possible loss of data * Fix warning C4267 in tools/mxnet/mxnet2ncnn.cpp C4244: 'initializing': conversion from 'double' to 'float', possible loss of data C4267: '=': conversion from 'size_t' to 'int', possible loss of data C4267: 'initializing': conversion from 'size_t' to 'int', possible loss of data C4305: 'initializing': truncation from 'double' to 'float' --- src/layer/bnll.cpp | 4 +- src/layer/concat.cpp | 2 +- src/layer/convolutiondepthwise.cpp | 4 +- src/layer/deconvolutiondepthwise.cpp | 4 +- src/layer/detectionoutput.cpp | 24 +++++------ src/layer/instancenorm.cpp | 2 +- src/layer/interp.cpp | 8 ++-- src/layer/quantize.cpp | 2 +- src/layer/roipooling.cpp | 16 +++---- src/layer/sigmoid.cpp | 2 +- src/layer/slice.cpp | 14 +++--- src/layer/softmax.cpp | 12 +++--- src/layer/yolodetectionoutput.cpp | 26 +++++------ src/layer/yolov3detectionoutput.cpp | 30 ++++++------- src/net.cpp | 18 ++++---- src/net.h | 2 +- tools/mxnet/mxnet2ncnn.cpp | 64 ++++++++++++++-------------- 17 files changed, 117 insertions(+), 117 deletions(-) diff --git a/src/layer/bnll.cpp b/src/layer/bnll.cpp index 74c0735e8..3ec0fcd8b 100644 --- a/src/layer/bnll.cpp +++ b/src/layer/bnll.cpp @@ -40,9 +40,9 @@ int BNLL::forward_inplace(Mat& bottom_top_blob, const Option& opt) const for (int i=0; i 0) - ptr[i] = ptr[i] + log(1.f + exp(-ptr[i])); + ptr[i] = static_cast(ptr[i] + log(1.f + exp(-ptr[i]))); else - ptr[i] = log(1.f + exp(ptr[i])); + ptr[i] = static_cast(log(1.f + exp(ptr[i]))); } } diff --git a/src/layer/concat.cpp b/src/layer/concat.cpp index 2416a8deb..ac77a1c2e 100644 --- a/src/layer/concat.cpp +++ b/src/layer/concat.cpp @@ -164,7 +164,7 @@ int Concat::forward(const std::vector& bottom_blobs, std::vector& top_ const Mat& bottom_blob = bottom_blobs[b]; int channels = bottom_blob.c; - int size = bottom_blob.cstep * channels; + size_t size = bottom_blob.cstep * channels; const float* ptr = bottom_blob; float* outptr = top_blob.channel(q); diff --git a/src/layer/convolutiondepthwise.cpp b/src/layer/convolutiondepthwise.cpp index 7a51abcdd..46339702b 100644 --- a/src/layer/convolutiondepthwise.cpp +++ b/src/layer/convolutiondepthwise.cpp @@ -713,7 +713,7 @@ int ConvolutionDepthWise::forward(const Mat& bottom_blob, Mat& top_blob, const O } else if (activation_type == 4) { - sum = 1.f / (1.f + exp(-sum)); + sum = static_cast(1.f / (1.f + exp(-sum))); } outptr[j] = sum; @@ -788,7 +788,7 @@ int ConvolutionDepthWise::forward(const Mat& bottom_blob, Mat& top_blob, const O } else if (activation_type == 4) { - sum = 1.f / (1.f + exp(-sum)); + sum = static_cast(1.f / (1.f + exp(-sum))); } outptr[j] = sum; diff --git a/src/layer/deconvolutiondepthwise.cpp b/src/layer/deconvolutiondepthwise.cpp index c38d69c50..6225017ac 100644 --- a/src/layer/deconvolutiondepthwise.cpp +++ b/src/layer/deconvolutiondepthwise.cpp @@ -197,7 +197,7 @@ int DeconvolutionDepthWise::forward(const Mat& bottom_blob, Mat& top_blob, const for (int i = 0; i < size; i++) { - outptr[i] = 1.f / (1.f + exp(-outptr[i])); + outptr[i] = static_cast(1.f / (1.f + exp(-outptr[i]))); } } } @@ -291,7 +291,7 @@ int DeconvolutionDepthWise::forward(const Mat& bottom_blob, Mat& top_blob, const for (int i = 0; i < size; i++) { - outptr[i] = 1.f / (1.f + exp(-outptr[i])); + outptr[i] = static_cast(1.f / (1.f + exp(-outptr[i]))); } } } diff --git a/src/layer/detectionoutput.cpp b/src/layer/detectionoutput.cpp index 5dd10d6cf..97eaa8162 100644 --- a/src/layer/detectionoutput.cpp +++ b/src/layer/detectionoutput.cpp @@ -103,17 +103,17 @@ static void qsort_descent_inplace(std::vector& datas, std::vector& sco if (datas.empty() || scores.empty()) return; - qsort_descent_inplace(datas, scores, 0, scores.size() - 1); + qsort_descent_inplace(datas, scores, 0, static_cast(scores.size() - 1)); } -static void nms_sorted_bboxes(const std::vector& bboxes, std::vector& picked, float nms_threshold) +static void nms_sorted_bboxes(const std::vector& bboxes, std::vector& picked, float nms_threshold) { picked.clear(); - const int n = bboxes.size(); + const size_t n = bboxes.size(); std::vector areas(n); - for (int i = 0; i < n; i++) + for (size_t i = 0; i < n; i++) { const BBoxRect& r = bboxes[i]; @@ -123,7 +123,7 @@ static void nms_sorted_bboxes(const std::vector& bboxes, std::vector& bottom_blobs, std::vector(exp(var[2] * loc[2]) * pb_w); + float bbox_h = static_cast(exp(var[3] * loc[3]) * pb_h); bbox[0] = bbox_cx - bbox_w * 0.5f; bbox[1] = bbox_cy - bbox_h * 0.5f; @@ -235,13 +235,13 @@ int DetectionOutput::forward(const std::vector& bottom_blobs, std::vector picked; + std::vector picked; nms_sorted_bboxes(class_bbox_rects, picked, nms_threshold); // select - for (int j = 0; j < (int)picked.size(); j++) + for (size_t j = 0; j < picked.size(); j++) { - int z = picked[j]; + size_t z = picked[j]; all_class_bbox_rects[i].push_back(class_bbox_rects[z]); all_class_bbox_scores[i].push_back(class_bbox_scores[z]); } @@ -271,7 +271,7 @@ int DetectionOutput::forward(const std::vector& bottom_blobs, std::vector(bbox_rects.size()); if (num_detected == 0) return 0; @@ -286,7 +286,7 @@ int DetectionOutput::forward(const std::vector& bottom_blobs, std::vector(r.label); outptr[1] = score; outptr[2] = r.xmin; outptr[3] = r.ymin; diff --git a/src/layer/instancenorm.cpp b/src/layer/instancenorm.cpp index 5ab06f73f..196087dfa 100644 --- a/src/layer/instancenorm.cpp +++ b/src/layer/instancenorm.cpp @@ -81,7 +81,7 @@ int InstanceNorm::forward_inplace(Mat& bottom_top_blob, const Option& opt) const float gamma = gamma_data[q]; float beta = beta_data[q]; - float a = gamma / (sqrt(var + eps)); + float a = static_cast(gamma / (sqrt(var + eps))); float b = - mean * a + beta; for (int i=0; i(floor(fx)); fx -= sx; if (sx < 0) @@ -172,7 +172,7 @@ static void cubic_coeffs(int w, int outw, int* xofs, float* alpha) for (int dx = 0; dx < outw; dx++) { float fx = (float)((dx + 0.5) * scale - 0.5); - int sx = floor(fx); + int sx = static_cast(floor(fx)); fx -= sx; interpolate_cubic(fx, alpha + dx*4); @@ -406,8 +406,8 @@ int Interp::forward(const Mat &bottom_blob, Mat &top_blob, const Option& opt) co } if (oh == 0 || ow == 0) { - oh = h * height_scale; - ow = w * width_scale; + oh = static_cast(h * height_scale); + ow = static_cast(w * width_scale); } if (oh == h && ow == w) { diff --git a/src/layer/quantize.cpp b/src/layer/quantize.cpp index ee368f8ae..68db9820b 100644 --- a/src/layer/quantize.cpp +++ b/src/layer/quantize.cpp @@ -35,7 +35,7 @@ int Quantize::load_param(const ParamDict& pd) static inline signed char float2int8(float v) { - int int32 = round(v); + int int32 = static_cast(round(v)); if (int32 > 127) return 127; if (int32 < -127) return -127; return (signed char)int32; diff --git a/src/layer/roipooling.cpp b/src/layer/roipooling.cpp index 5efc53142..2a093bc6a 100644 --- a/src/layer/roipooling.cpp +++ b/src/layer/roipooling.cpp @@ -51,10 +51,10 @@ int ROIPooling::forward(const std::vector& bottom_blobs, std::vector& // For each ROI R = [x y w h]: max pool over R const float* roi_ptr = roi_blob; - int roi_x1 = round(roi_ptr[0] * spatial_scale); - int roi_y1 = round(roi_ptr[1] * spatial_scale); - int roi_x2 = round(roi_ptr[2] * spatial_scale); - int roi_y2 = round(roi_ptr[3] * spatial_scale); + int roi_x1 = static_cast(round(roi_ptr[0] * spatial_scale)); + int roi_y1 = static_cast(round(roi_ptr[1] * spatial_scale)); + int roi_x2 = static_cast(round(roi_ptr[2] * spatial_scale)); + int roi_y2 = static_cast(round(roi_ptr[3] * spatial_scale)); int roi_w = std::max(roi_x2 - roi_x1 + 1, 1); int roi_h = std::max(roi_y2 - roi_y1 + 1, 1); @@ -75,10 +75,10 @@ int ROIPooling::forward(const std::vector& bottom_blobs, std::vector& // Compute pooling region for this output unit: // start (included) = floor(ph * roi_height / pooled_height) // end (excluded) = ceil((ph + 1) * roi_height / pooled_height) - int hstart = roi_y1 + floor((float)(ph) * bin_size_h); - int wstart = roi_x1 + floor((float)(pw) * bin_size_w); - int hend = roi_y1 + ceil((float)(ph + 1) * bin_size_h); - int wend = roi_x1 + ceil((float)(pw + 1) * bin_size_w); + int hstart = static_cast(roi_y1 + floor((float)(ph) * bin_size_h)); + int wstart = static_cast(roi_x1 + floor((float)(pw) * bin_size_w)); + int hend = static_cast(roi_y1 + ceil((float)(ph + 1) * bin_size_h)); + int wend = static_cast(roi_x1 + ceil((float)(pw + 1) * bin_size_w)); hstart = std::min(std::max(hstart, 0), h); wstart = std::min(std::max(wstart, 0), w); diff --git a/src/layer/sigmoid.cpp b/src/layer/sigmoid.cpp index 6704cea2c..330168866 100644 --- a/src/layer/sigmoid.cpp +++ b/src/layer/sigmoid.cpp @@ -39,7 +39,7 @@ int Sigmoid::forward_inplace(Mat& bottom_top_blob, const Option& opt) const for (int i=0; i(1.f / (1.f + exp(-ptr[i]))); } } diff --git a/src/layer/slice.cpp b/src/layer/slice.cpp index e16e8a253..5a327ba69 100644 --- a/src/layer/slice.cpp +++ b/src/layer/slice.cpp @@ -47,7 +47,7 @@ int Slice::forward(const std::vector& bottom_blobs, std::vector& top_b int slice = slices_ptr[i]; if (slice == -233) { - slice = (w - q) / (top_blobs.size() - i); + slice = static_cast((w - q) / (top_blobs.size() - i)); } Mat& top_blob = top_blobs[i]; @@ -76,7 +76,7 @@ int Slice::forward(const std::vector& bottom_blobs, std::vector& top_b int slice = slices_ptr[i]; if (slice == -233) { - slice = (h - q) / (top_blobs.size() - i); + slice = static_cast((h - q) / (top_blobs.size() - i)); } Mat& top_blob = top_blobs[i]; @@ -107,7 +107,7 @@ int Slice::forward(const std::vector& bottom_blobs, std::vector& top_b int slice = slices_ptr[i]; if (slice == -233) { - slice = (w - q) / (top_blobs.size() - i); + slice = static_cast((w - q) / (top_blobs.size() - i)); } Mat& top_blob = top_blobs[i]; @@ -141,7 +141,7 @@ int Slice::forward(const std::vector& bottom_blobs, std::vector& top_b int slice = slices_ptr[i]; if (slice == -233) { - slice = (channels - q) / (top_blobs.size() - i); + slice = static_cast((channels - q) / (top_blobs.size() - i)); } Mat& top_blob = top_blobs[i]; @@ -149,7 +149,7 @@ int Slice::forward(const std::vector& bottom_blobs, std::vector& top_b if (top_blob.empty()) return -100; - int size = bottom_blob.cstep * slice; + int size = static_cast(bottom_blob.cstep * slice); const float* ptr = bottom_blob.channel(q); float* outptr = top_blob; @@ -173,7 +173,7 @@ int Slice::forward(const std::vector& bottom_blobs, std::vector& top_b int slice = slices_ptr[i]; if (slice == -233) { - slice = (h - q) / (top_blobs.size() - i); + slice = static_cast((h - q) / (top_blobs.size() - i)); } Mat& top_blob = top_blobs[i]; @@ -209,7 +209,7 @@ int Slice::forward(const std::vector& bottom_blobs, std::vector& top_b int slice = slices_ptr[i]; if (slice == -233) { - slice = (w - q) / (top_blobs.size() - i); + slice = static_cast((w - q) / (top_blobs.size() - i)); } Mat& top_blob = top_blobs[i]; diff --git a/src/layer/softmax.cpp b/src/layer/softmax.cpp index 102800c7c..cdad47b33 100644 --- a/src/layer/softmax.cpp +++ b/src/layer/softmax.cpp @@ -67,7 +67,7 @@ int Softmax::forward_inplace(Mat& bottom_top_blob, const Option& opt) const float sum = 0.f; for (int i=0; i(exp(ptr[i] - max)); sum += ptr[i]; } @@ -110,7 +110,7 @@ int Softmax::forward_inplace(Mat& bottom_top_blob, const Option& opt) const float* ptr = bottom_top_blob.row(i); for (int j=0; j(exp(ptr[j] - max[j])); sum[j] += ptr[j]; } } @@ -144,7 +144,7 @@ int Softmax::forward_inplace(Mat& bottom_top_blob, const Option& opt) const float s = 0.f; for (int j=0; j(exp(ptr[j] - m)); s += ptr[j]; } @@ -190,7 +190,7 @@ int Softmax::forward_inplace(Mat& bottom_top_blob, const Option& opt) const for (int i=0; i(exp(ptr[i] - max[i])); sum[i] += ptr[i]; } } @@ -253,7 +253,7 @@ int Softmax::forward_inplace(Mat& bottom_top_blob, const Option& opt) const { for (int j=0; j(exp(ptr[j] - maxptr[j])); sumptr[j] += ptr[j]; } @@ -303,7 +303,7 @@ int Softmax::forward_inplace(Mat& bottom_top_blob, const Option& opt) const float sum = 0.f; for (int j=0; j(exp(ptr[j] - max)); sum += ptr[j]; } diff --git a/src/layer/yolodetectionoutput.cpp b/src/layer/yolodetectionoutput.cpp index 8d8518687..be1378a62 100644 --- a/src/layer/yolodetectionoutput.cpp +++ b/src/layer/yolodetectionoutput.cpp @@ -128,17 +128,17 @@ static void qsort_descent_inplace(std::vector& datas, std::vector& sco if (datas.empty() || scores.empty()) return; - qsort_descent_inplace(datas, scores, 0, scores.size() - 1); + qsort_descent_inplace(datas, scores, 0, static_cast(scores.size() - 1)); } -static void nms_sorted_bboxes(const std::vector& bboxes, std::vector& picked, float nms_threshold) +static void nms_sorted_bboxes(const std::vector& bboxes, std::vector& picked, float nms_threshold) { picked.clear(); - const int n = bboxes.size(); + const size_t n = bboxes.size(); std::vector areas(n); - for (int i = 0; i < n; i++) + for (size_t i = 0; i < n; i++) { const BBoxRect& r = bboxes[i]; @@ -148,7 +148,7 @@ static void nms_sorted_bboxes(const std::vector& bboxes, std::vector& bboxes, std::vector(1.f / (1.f + exp(-x))); } int YoloDetectionOutput::forward_inplace(std::vector& bottom_top_blobs, const Option& opt) const @@ -226,8 +226,8 @@ int YoloDetectionOutput::forward_inplace(std::vector& bottom_top_blobs, con // region box float bbox_cx = (j + sigmoid(xptr[0])) / w; float bbox_cy = (i + sigmoid(yptr[0])) / h; - float bbox_w = exp(wptr[0]) * bias_w / w; - float bbox_h = exp(hptr[0]) * bias_h / h; + float bbox_w = static_cast(exp(wptr[0]) * bias_w / w); + float bbox_h = static_cast(exp(hptr[0]) * bias_h / h); float bbox_xmin = bbox_cx - bbox_w * 0.5f; float bbox_ymin = bbox_cy - bbox_h * 0.5f; @@ -284,22 +284,22 @@ int YoloDetectionOutput::forward_inplace(std::vector& bottom_top_blobs, con qsort_descent_inplace(all_bbox_rects, all_bbox_scores); // apply nms - std::vector picked; + std::vector picked; nms_sorted_bboxes(all_bbox_rects, picked, nms_threshold); // select std::vector bbox_rects; std::vector bbox_scores; - for (int i = 0; i < (int)picked.size(); i++) + for (size_t i = 0; i < picked.size(); i++) { - int z = picked[i]; + size_t z = picked[i]; bbox_rects.push_back(all_bbox_rects[z]); bbox_scores.push_back(all_bbox_scores[z]); } // fill result - int num_detected = bbox_rects.size(); + int num_detected = static_cast(bbox_rects.size()); if (num_detected == 0) return 0; @@ -314,7 +314,7 @@ int YoloDetectionOutput::forward_inplace(std::vector& bottom_top_blobs, con float score = bbox_scores[i]; float* outptr = top_blob.row(i); - outptr[0] = r.label + 1;// +1 for prepend background class + outptr[0] = static_cast(r.label + 1);// +1 for prepend background class outptr[1] = score; outptr[2] = r.xmin; outptr[3] = r.ymin; diff --git a/src/layer/yolov3detectionoutput.cpp b/src/layer/yolov3detectionoutput.cpp index 011b7fe17..55c4df1d7 100644 --- a/src/layer/yolov3detectionoutput.cpp +++ b/src/layer/yolov3detectionoutput.cpp @@ -115,17 +115,17 @@ static void qsort_descent_inplace(std::vector& datas, std::vector& sco if (datas.empty() || scores.empty()) return; - qsort_descent_inplace(datas, scores, 0, scores.size() - 1); + qsort_descent_inplace(datas, scores, 0, static_cast(scores.size() - 1)); } -static void nms_sorted_bboxes(const std::vector& bboxes, std::vector& picked, float nms_threshold) +static void nms_sorted_bboxes(const std::vector& bboxes, std::vector& picked, float nms_threshold) { picked.clear(); - const int n = bboxes.size(); + const size_t n = bboxes.size(); std::vector areas(n); - for (int i = 0; i < n; i++) + for (size_t i = 0; i < n; i++) { const BBoxRect& r = bboxes[i]; @@ -135,7 +135,7 @@ static void nms_sorted_bboxes(const std::vector& bboxes, std::vector& bboxes, std::vector(1.f / (1.f + exp(-x))); } int Yolov3DetectionOutput::forward(const std::vector& bottom_blobs, std::vector& top_blobs, const Option& opt) const @@ -185,7 +185,7 @@ int Yolov3DetectionOutput::forward(const std::vector& bottom_blobs, std::ve // anchor coord + box score + num_class if (channels_per_box != 4 + 1 + num_class) return -1; - int mask_offset = b * num_box; + size_t mask_offset = b * num_box; int net_w = (int)(anchors_scale[b] * w); int net_h = (int)(anchors_scale[b] * h); //printf("%d %d\n", net_w, net_h); @@ -195,7 +195,7 @@ int Yolov3DetectionOutput::forward(const std::vector& bottom_blobs, std::ve for (int pp = 0; pp < num_box; pp++) { int p = pp * channels_per_box; - int biases_index = mask[pp + mask_offset]; + int biases_index = static_cast(mask[pp + mask_offset]); //printf("%d\n", biases_index); const float bias_w = biases[biases_index * 2]; const float bias_h = biases[biases_index * 2 + 1]; @@ -242,8 +242,8 @@ int Yolov3DetectionOutput::forward(const std::vector& bottom_blobs, std::ve // region box float bbox_cx = (j + sigmoid(xptr[0])) / w; float bbox_cy = (i + sigmoid(yptr[0])) / h; - float bbox_w = exp(wptr[0]) * bias_w / net_w; - float bbox_h = exp(hptr[0]) * bias_h / net_h; + float bbox_w = static_cast(exp(wptr[0]) * bias_w / net_w); + float bbox_h = static_cast(exp(hptr[0]) * bias_h / net_h); float bbox_xmin = bbox_cx - bbox_w * 0.5f; float bbox_ymin = bbox_cy - bbox_h * 0.5f; @@ -283,22 +283,22 @@ int Yolov3DetectionOutput::forward(const std::vector& bottom_blobs, std::ve qsort_descent_inplace(all_bbox_rects, all_bbox_scores); // apply nms - std::vector picked; + std::vector picked; nms_sorted_bboxes(all_bbox_rects, picked, nms_threshold); // select std::vector bbox_rects; std::vector bbox_scores; - for (int i = 0; i < (int)picked.size(); i++) + for (size_t i = 0; i < picked.size(); i++) { - int z = picked[i]; + size_t z = picked[i]; bbox_rects.push_back(all_bbox_rects[z]); bbox_scores.push_back(all_bbox_scores[z]); } // fill result - int num_detected = bbox_rects.size(); + int num_detected = static_cast(bbox_rects.size()); if (num_detected == 0) return 0; @@ -313,7 +313,7 @@ int Yolov3DetectionOutput::forward(const std::vector& bottom_blobs, std::ve float score = bbox_scores[i]; float* outptr = top_blob.row(i); - outptr[0] = r.label + 1;// +1 for prepend background class + outptr[0] = static_cast(r.label + 1);// +1 for prepend background class outptr[1] = score; outptr[2] = r.xmin; outptr[3] = r.ymin; diff --git a/src/net.cpp b/src/net.cpp index a22d0ac89..e2013d6d5 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -535,7 +535,7 @@ int Net::load_param(const unsigned char* _mem) const unsigned char* mem = _mem; DataReaderFromMemory dr(mem); load_param_bin(dr); - return mem - _mem; + return static_cast(mem - _mem); } int Net::load_model(const unsigned char* _mem) @@ -543,7 +543,7 @@ int Net::load_model(const unsigned char* _mem) const unsigned char* mem = _mem; DataReaderFromMemory dr(mem); load_model(dr); - return mem - _mem; + return static_cast(mem - _mem); } #if __ANDROID_API__ >= 9 @@ -947,7 +947,7 @@ int Net::find_blob_index_by_name(const char* name) const const Blob& blob = blobs[i]; if (blob.name == name) { - return i; + return static_cast(i); } } @@ -962,7 +962,7 @@ int Net::find_layer_index_by_name(const char* name) const const Layer* layer = layers[i]; if (layer->name == name) { - return i; + return static_cast(i); } } @@ -972,11 +972,11 @@ int Net::find_layer_index_by_name(const char* name) const int Net::custom_layer_to_index(const char* type) { - const int custom_layer_registry_entry_count = custom_layer_registry.size(); - for (int i=0; i(i); } return -1; @@ -994,7 +994,7 @@ Layer* Net::create_custom_layer(const char* type) Layer* Net::create_custom_layer(int index) { - const int custom_layer_registry_entry_count = custom_layer_registry.size(); + const size_t custom_layer_registry_entry_count = custom_layer_registry.size(); if (index < 0 || index >= custom_layer_registry_entry_count) return 0; @@ -1798,7 +1798,7 @@ int Net::forward_layer(int layer_index, std::vector& blob_mats, std::vector } #endif // NCNN_VULKAN -Extractor::Extractor(const Net* _net, int blob_count) : net(_net) +Extractor::Extractor(const Net* _net, size_t blob_count) : net(_net) { blob_mats.resize(blob_count); opt = net->opt; diff --git a/src/net.h b/src/net.h index cfb26c3e8..df0926f6c 100644 --- a/src/net.h +++ b/src/net.h @@ -244,7 +244,7 @@ public: protected: friend Extractor Net::create_extractor() const; - Extractor(const Net* net, int blob_count); + Extractor(const Net* net, size_t blob_count); private: const Net* net; diff --git a/tools/mxnet/mxnet2ncnn.cpp b/tools/mxnet/mxnet2ncnn.cpp index 76d69a677..8b9df7193 100644 --- a/tools/mxnet/mxnet2ncnn.cpp +++ b/tools/mxnet/mxnet2ncnn.cpp @@ -559,19 +559,19 @@ static bool read_mxnet_param(const char* parampath, std::vector& par return false; } - int nread; + size_t nread; uint64_t header; uint64_t reserved; nread = fread(&header, sizeof(uint64_t), 1, fp); if (nread != 1) { - fprintf(stderr, "read header failed %d\n", nread); + fprintf(stderr, "read header failed %zd\n", nread); return false; } nread = fread(&reserved, sizeof(uint64_t), 1, fp); if (nread != 1) { - fprintf(stderr, "read reserved failed %d\n", nread); + fprintf(stderr, "read reserved failed %zd\n", nread); return false; } @@ -582,7 +582,7 @@ static bool read_mxnet_param(const char* parampath, std::vector& par nread = fread(&data_count, sizeof(uint64_t), 1, fp); if (nread != 1) { - fprintf(stderr, "read data_count failed %d\n", nread); + fprintf(stderr, "read data_count failed %zd\n", nread); return false; } @@ -594,7 +594,7 @@ static bool read_mxnet_param(const char* parampath, std::vector& par nread = fread(&magic, sizeof(uint32_t), 1, fp); if (nread != 1) { - fprintf(stderr, "read magic failed %d\n", nread); + fprintf(stderr, "read magic failed %zd\n", nread); return false; } @@ -608,14 +608,14 @@ static bool read_mxnet_param(const char* parampath, std::vector& par nread = fread(&stype, sizeof(int32_t), 1, fp); if (nread != 1) { - fprintf(stderr, "read stype failed %d\n", nread); + fprintf(stderr, "read stype failed %zd\n", nread); return false; } nread = fread(&ndim, sizeof(uint32_t), 1, fp); if (nread != 1) { - fprintf(stderr, "read ndim failed %d\n", nread); + fprintf(stderr, "read ndim failed %zd\n", nread); return false; } @@ -623,7 +623,7 @@ static bool read_mxnet_param(const char* parampath, std::vector& par nread = fread(&shape[0], ndim * sizeof(int64_t), 1, fp); if (nread != 1) { - fprintf(stderr, "read shape failed %d\n", nread); + fprintf(stderr, "read shape failed %zd\n", nread); return false; } } @@ -632,7 +632,7 @@ static bool read_mxnet_param(const char* parampath, std::vector& par nread = fread(&ndim, sizeof(uint32_t), 1, fp); if (nread != 1) { - fprintf(stderr, "read ndim failed %d\n", nread); + fprintf(stderr, "read ndim failed %zd\n", nread); return false; } @@ -640,7 +640,7 @@ static bool read_mxnet_param(const char* parampath, std::vector& par nread = fread(&shape[0], ndim * sizeof(int64_t), 1, fp); if (nread != 1) { - fprintf(stderr, "read shape failed %d\n", nread); + fprintf(stderr, "read shape failed %zd\n", nread); return false; } } @@ -655,7 +655,7 @@ static bool read_mxnet_param(const char* parampath, std::vector& par nread = fread(&shape32[0], ndim * sizeof(uint32_t), 1, fp); if (nread != 1) { - fprintf(stderr, "read shape failed %d\n", nread); + fprintf(stderr, "read shape failed %zd\n", nread); return false; } @@ -671,13 +671,13 @@ static bool read_mxnet_param(const char* parampath, std::vector& par nread = fread(&dev_type, sizeof(int32_t), 1, fp); if (nread != 1) { - fprintf(stderr, "read dev_type failed %d\n", nread); + fprintf(stderr, "read dev_type failed %zd\n", nread); return false; } nread = fread(&dev_id, sizeof(int32_t), 1, fp); if (nread != 1) { - fprintf(stderr, "read dev_id failed %d\n", nread); + fprintf(stderr, "read dev_id failed %zd\n", nread); return false; } @@ -685,7 +685,7 @@ static bool read_mxnet_param(const char* parampath, std::vector& par nread = fread(&type_flag, sizeof(int32_t), 1, fp); if (nread != 1) { - fprintf(stderr, "read type_flag failed %d\n", nread); + fprintf(stderr, "read type_flag failed %zd\n", nread); return false; } @@ -702,7 +702,7 @@ static bool read_mxnet_param(const char* parampath, std::vector& par nread = fread(&p.data[0], len * sizeof(float), 1, fp); if (nread != 1) { - fprintf(stderr, "read MXNetParam data failed %d\n", nread); + fprintf(stderr, "read MXNetParam data failed %zd\n", nread); return false; } @@ -716,7 +716,7 @@ static bool read_mxnet_param(const char* parampath, std::vector& par nread = fread(&name_count, sizeof(uint64_t), 1, fp); if (nread != 1) { - fprintf(stderr, "read name_count failed %d\n", nread); + fprintf(stderr, "read name_count failed %zd\n", nread); return false; } @@ -728,7 +728,7 @@ static bool read_mxnet_param(const char* parampath, std::vector& par nread = fread(&len, sizeof(uint64_t), 1, fp); if (nread != 1) { - fprintf(stderr, "read name length failed %d\n", nread); + fprintf(stderr, "read name length failed %zd\n", nread); return false; } @@ -738,7 +738,7 @@ static bool read_mxnet_param(const char* parampath, std::vector& par nread = fread((char*)p.name.data(), len, 1, fp); if (nread != 1) { - fprintf(stderr, "read MXNetParam name failed %d\n", nread); + fprintf(stderr, "read MXNetParam name failed %zd\n", nread); return false; } @@ -762,8 +762,8 @@ static bool read_mxnet_param(const char* parampath, std::vector& par static void fuse_shufflechannel(std::vector& nodes, std::vector& params, std::map& node_reference, std::set& blob_names, int& reduced_node_count) { - int node_count = nodes.size(); - for (int i=0; i node_reference; @@ -1095,7 +1095,7 @@ int main(int argc, char** argv) // fprintf(stderr, "%d %d %d %d, %d %d\n", node_count, reduced_node_count, node_reference.size(), weight_nodes.size(), blob_names.size(), splitncnn_blob_count); - fprintf(pp, "%lu %lu\n", node_count - reduced_node_count + node_reference.size() - weight_nodes.size(), blob_names.size() + splitncnn_blob_count); + fprintf(pp, "%zu %zu\n", node_count - reduced_node_count + node_reference.size() - weight_nodes.size(), blob_names.size() + splitncnn_blob_count); int internal_split = 0; @@ -1469,7 +1469,7 @@ int main(int argc, char** argv) fprintf(pp, "%-16s", n.op.c_str()); } - int input_size = n.inputs.size(); + size_t input_size = n.inputs.size(); for (int j=0; j<(int)n.inputs.size(); j++) { int input_index = n.inputs[j]; @@ -1485,7 +1485,7 @@ int main(int argc, char** argv) input_size--; } - fprintf(pp, " %-32s %d %d", n.name.c_str(), input_size, n.output_size); + fprintf(pp, " %-32s %zd %d", n.name.c_str(), input_size, n.output_size); for (int j=0; j<(int)n.inputs.size(); j++) { @@ -1749,7 +1749,7 @@ int main(int argc, char** argv) } else if (n.op == "BatchNorm") { - float eps = 1e-3; + float eps = 1e-3f; if (n.has_attr("eps")) { eps = n.attr("eps"); } @@ -1757,7 +1757,7 @@ int main(int argc, char** argv) std::vector slope_data = n.weight(0); std::vector bias_data = n.weight(1); - int channels = slope_data.size(); + int channels = static_cast(slope_data.size()); std::vector mean_data = n.weight(2, channels); std::vector var_data = n.weight(3, channels); @@ -1961,7 +1961,7 @@ int main(int argc, char** argv) { // reorder weight from inch-outch to outch-inch int num_filter_g = num_filter / num_group; - int num_input = weight_data.size() / maxk / num_filter_g / num_group; + int num_input = static_cast(weight_data.size() / maxk / num_filter_g / num_group); const float* weight_data_ptr = weight_data.data() + g * maxk * num_filter_g * num_input; for (int k=0; k 3 || axis[i] < -3) @@ -2391,12 +2391,12 @@ int main(int argc, char** argv) fprintf(stderr, "Unsupported slice step !\n"); } - fprintf(pp, " -23309=%d", begin.size()); + fprintf(pp, " -23309=%zd", begin.size()); for (int i=0; i<(int)begin.size(); i++) { fprintf(pp, ",%d", begin[i]); } - fprintf(pp, " -23310=%d", end.size()); + fprintf(pp, " -23310=%zd", end.size()); for (int i=0; i<(int)end.size(); i++) { fprintf(pp, ",%d", end[i]); @@ -2466,7 +2466,7 @@ int main(int argc, char** argv) } else { - fprintf(pp, " -23303=%d", axis.size()); + fprintf(pp, " -23303=%zd", axis.size()); for (int i=0; i<(int)axis.size(); i++) { fprintf(pp, ",%d", axis[i]);