Browse Source

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'
tags/20200106
Sungmann Cho nihui 6 years ago
parent
commit
9bfc554bc9
17 changed files with 117 additions and 117 deletions
  1. +2
    -2
      src/layer/bnll.cpp
  2. +1
    -1
      src/layer/concat.cpp
  3. +2
    -2
      src/layer/convolutiondepthwise.cpp
  4. +2
    -2
      src/layer/deconvolutiondepthwise.cpp
  5. +12
    -12
      src/layer/detectionoutput.cpp
  6. +1
    -1
      src/layer/instancenorm.cpp
  7. +4
    -4
      src/layer/interp.cpp
  8. +1
    -1
      src/layer/quantize.cpp
  9. +8
    -8
      src/layer/roipooling.cpp
  10. +1
    -1
      src/layer/sigmoid.cpp
  11. +7
    -7
      src/layer/slice.cpp
  12. +6
    -6
      src/layer/softmax.cpp
  13. +13
    -13
      src/layer/yolodetectionoutput.cpp
  14. +15
    -15
      src/layer/yolov3detectionoutput.cpp
  15. +9
    -9
      src/net.cpp
  16. +1
    -1
      src/net.h
  17. +32
    -32
      tools/mxnet/mxnet2ncnn.cpp

+ 2
- 2
src/layer/bnll.cpp View File

@@ -40,9 +40,9 @@ int BNLL::forward_inplace(Mat& bottom_top_blob, const Option& opt) const
for (int i=0; i<size; i++)
{
if (ptr[i] > 0)
ptr[i] = ptr[i] + log(1.f + exp(-ptr[i]));
ptr[i] = static_cast<float>(ptr[i] + log(1.f + exp(-ptr[i])));
else
ptr[i] = log(1.f + exp(ptr[i]));
ptr[i] = static_cast<float>(log(1.f + exp(ptr[i])));
}
}



+ 1
- 1
src/layer/concat.cpp View File

@@ -164,7 +164,7 @@ int Concat::forward(const std::vector<Mat>& bottom_blobs, std::vector<Mat>& 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);


+ 2
- 2
src/layer/convolutiondepthwise.cpp View File

@@ -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<float>(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<float>(1.f / (1.f + exp(-sum)));
}

outptr[j] = sum;


+ 2
- 2
src/layer/deconvolutiondepthwise.cpp View File

@@ -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<float>(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<float>(1.f / (1.f + exp(-outptr[i])));
}
}
}


+ 12
- 12
src/layer/detectionoutput.cpp View File

@@ -103,17 +103,17 @@ static void qsort_descent_inplace(std::vector<T>& datas, std::vector<float>& sco
if (datas.empty() || scores.empty())
return;

qsort_descent_inplace(datas, scores, 0, scores.size() - 1);
qsort_descent_inplace(datas, scores, 0, static_cast<int>(scores.size() - 1));
}

static void nms_sorted_bboxes(const std::vector<BBoxRect>& bboxes, std::vector<int>& picked, float nms_threshold)
static void nms_sorted_bboxes(const std::vector<BBoxRect>& bboxes, std::vector<size_t>& picked, float nms_threshold)
{
picked.clear();

const int n = bboxes.size();
const size_t n = bboxes.size();

std::vector<float> 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<BBoxRect>& bboxes, std::vector<i
areas[i] = width * height;
}

for (int i = 0; i < n; i++)
for (size_t i = 0; i < n; i++)
{
const BBoxRect& a = bboxes[i];

@@ -185,8 +185,8 @@ int DetectionOutput::forward(const std::vector<Mat>& bottom_blobs, std::vector<M

float bbox_cx = var[0] * loc[0] * pb_w + pb_cx;
float bbox_cy = var[1] * loc[1] * pb_h + pb_cy;
float bbox_w = exp(var[2] * loc[2]) * pb_w;
float bbox_h = exp(var[3] * loc[3]) * pb_h;
float bbox_w = static_cast<float>(exp(var[2] * loc[2]) * pb_w);
float bbox_h = static_cast<float>(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<Mat>& bottom_blobs, std::vector<M
}

// apply nms
std::vector<int> picked;
std::vector<size_t> 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<Mat>& bottom_blobs, std::vector<M
}

// fill result
int num_detected = bbox_rects.size();
int num_detected = static_cast<int>(bbox_rects.size());
if (num_detected == 0)
return 0;

@@ -286,7 +286,7 @@ int DetectionOutput::forward(const std::vector<Mat>& bottom_blobs, std::vector<M
float score = bbox_scores[i];
float* outptr = top_blob.row(i);

outptr[0] = r.label;
outptr[0] = static_cast<float>(r.label);
outptr[1] = score;
outptr[2] = r.xmin;
outptr[3] = r.ymin;


+ 1
- 1
src/layer/instancenorm.cpp View File

@@ -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<float>(gamma / (sqrt(var + eps)));
float b = - mean * a + beta;

for (int i=0; i<size; i++)


+ 4
- 4
src/layer/interp.cpp View File

@@ -43,7 +43,7 @@ static void linear_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<int>(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<int>(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<int>(h * height_scale);
ow = static_cast<int>(w * width_scale);
}
if (oh == h && ow == w)
{


+ 1
- 1
src/layer/quantize.cpp View File

@@ -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<int>(round(v));
if (int32 > 127) return 127;
if (int32 < -127) return -127;
return (signed char)int32;


+ 8
- 8
src/layer/roipooling.cpp View File

@@ -51,10 +51,10 @@ int ROIPooling::forward(const std::vector<Mat>& bottom_blobs, std::vector<Mat>&
// 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<int>(round(roi_ptr[0] * spatial_scale));
int roi_y1 = static_cast<int>(round(roi_ptr[1] * spatial_scale));
int roi_x2 = static_cast<int>(round(roi_ptr[2] * spatial_scale));
int roi_y2 = static_cast<int>(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<Mat>& bottom_blobs, std::vector<Mat>&
// 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<int>(roi_y1 + floor((float)(ph) * bin_size_h));
int wstart = static_cast<int>(roi_x1 + floor((float)(pw) * bin_size_w));
int hend = static_cast<int>(roi_y1 + ceil((float)(ph + 1) * bin_size_h));
int wend = static_cast<int>(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);


+ 1
- 1
src/layer/sigmoid.cpp View File

@@ -39,7 +39,7 @@ int Sigmoid::forward_inplace(Mat& bottom_top_blob, const Option& opt) const

for (int i=0; i<size; i++)
{
ptr[i] = 1.f / (1.f + exp(-ptr[i]));
ptr[i] = static_cast<float>(1.f / (1.f + exp(-ptr[i])));
}
}



+ 7
- 7
src/layer/slice.cpp View File

@@ -47,7 +47,7 @@ int Slice::forward(const std::vector<Mat>& bottom_blobs, std::vector<Mat>& top_b
int slice = slices_ptr[i];
if (slice == -233)
{
slice = (w - q) / (top_blobs.size() - i);
slice = static_cast<int>((w - q) / (top_blobs.size() - i));
}

Mat& top_blob = top_blobs[i];
@@ -76,7 +76,7 @@ int Slice::forward(const std::vector<Mat>& bottom_blobs, std::vector<Mat>& top_b
int slice = slices_ptr[i];
if (slice == -233)
{
slice = (h - q) / (top_blobs.size() - i);
slice = static_cast<int>((h - q) / (top_blobs.size() - i));
}

Mat& top_blob = top_blobs[i];
@@ -107,7 +107,7 @@ int Slice::forward(const std::vector<Mat>& bottom_blobs, std::vector<Mat>& top_b
int slice = slices_ptr[i];
if (slice == -233)
{
slice = (w - q) / (top_blobs.size() - i);
slice = static_cast<int>((w - q) / (top_blobs.size() - i));
}

Mat& top_blob = top_blobs[i];
@@ -141,7 +141,7 @@ int Slice::forward(const std::vector<Mat>& bottom_blobs, std::vector<Mat>& top_b
int slice = slices_ptr[i];
if (slice == -233)
{
slice = (channels - q) / (top_blobs.size() - i);
slice = static_cast<int>((channels - q) / (top_blobs.size() - i));
}

Mat& top_blob = top_blobs[i];
@@ -149,7 +149,7 @@ int Slice::forward(const std::vector<Mat>& bottom_blobs, std::vector<Mat>& top_b
if (top_blob.empty())
return -100;

int size = bottom_blob.cstep * slice;
int size = static_cast<int>(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<Mat>& bottom_blobs, std::vector<Mat>& top_b
int slice = slices_ptr[i];
if (slice == -233)
{
slice = (h - q) / (top_blobs.size() - i);
slice = static_cast<int>((h - q) / (top_blobs.size() - i));
}

Mat& top_blob = top_blobs[i];
@@ -209,7 +209,7 @@ int Slice::forward(const std::vector<Mat>& bottom_blobs, std::vector<Mat>& top_b
int slice = slices_ptr[i];
if (slice == -233)
{
slice = (w - q) / (top_blobs.size() - i);
slice = static_cast<int>((w - q) / (top_blobs.size() - i));
}

Mat& top_blob = top_blobs[i];


+ 6
- 6
src/layer/softmax.cpp View File

@@ -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<w; i++)
{
ptr[i] = exp(ptr[i] - max);
ptr[i] = static_cast<float>(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<w; j++)
{
ptr[j] = exp(ptr[j] - max[j]);
ptr[j] = static_cast<float>(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<w; j++)
{
ptr[j] = exp(ptr[j] - m);
ptr[j] = static_cast<float>(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<size; i++)
{
ptr[i] = exp(ptr[i] - max[i]);
ptr[i] = static_cast<float>(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<w; j++)
{
ptr[j] = exp(ptr[j] - maxptr[j]);
ptr[j] = static_cast<float>(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<w; j++)
{
ptr[j] = exp(ptr[j] - max);
ptr[j] = static_cast<float>(exp(ptr[j] - max));
sum += ptr[j];
}



+ 13
- 13
src/layer/yolodetectionoutput.cpp View File

@@ -128,17 +128,17 @@ static void qsort_descent_inplace(std::vector<T>& datas, std::vector<float>& sco
if (datas.empty() || scores.empty())
return;

qsort_descent_inplace(datas, scores, 0, scores.size() - 1);
qsort_descent_inplace(datas, scores, 0, static_cast<int>(scores.size() - 1));
}

static void nms_sorted_bboxes(const std::vector<BBoxRect>& bboxes, std::vector<int>& picked, float nms_threshold)
static void nms_sorted_bboxes(const std::vector<BBoxRect>& bboxes, std::vector<size_t>& picked, float nms_threshold)
{
picked.clear();

const int n = bboxes.size();
const size_t n = bboxes.size();

std::vector<float> 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<BBoxRect>& bboxes, std::vector<i
areas[i] = width * height;
}

for (int i = 0; i < n; i++)
for (size_t i = 0; i < n; i++)
{
const BBoxRect& a = bboxes[i];

@@ -172,7 +172,7 @@ static void nms_sorted_bboxes(const std::vector<BBoxRect>& bboxes, std::vector<i

static inline float sigmoid(float x)
{
return 1.f / (1.f + exp(-x));
return static_cast<float>(1.f / (1.f + exp(-x)));
}

int YoloDetectionOutput::forward_inplace(std::vector<Mat>& bottom_top_blobs, const Option& opt) const
@@ -226,8 +226,8 @@ int YoloDetectionOutput::forward_inplace(std::vector<Mat>& 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<float>(exp(wptr[0]) * bias_w / w);
float bbox_h = static_cast<float>(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<Mat>& bottom_top_blobs, con
qsort_descent_inplace(all_bbox_rects, all_bbox_scores);

// apply nms
std::vector<int> picked;
std::vector<size_t> picked;
nms_sorted_bboxes(all_bbox_rects, picked, nms_threshold);

// select
std::vector<BBoxRect> bbox_rects;
std::vector<float> 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<int>(bbox_rects.size());
if (num_detected == 0)
return 0;

@@ -314,7 +314,7 @@ int YoloDetectionOutput::forward_inplace(std::vector<Mat>& 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<float>(r.label + 1);// +1 for prepend background class
outptr[1] = score;
outptr[2] = r.xmin;
outptr[3] = r.ymin;


+ 15
- 15
src/layer/yolov3detectionoutput.cpp View File

@@ -115,17 +115,17 @@ static void qsort_descent_inplace(std::vector<T>& datas, std::vector<float>& sco
if (datas.empty() || scores.empty())
return;

qsort_descent_inplace(datas, scores, 0, scores.size() - 1);
qsort_descent_inplace(datas, scores, 0, static_cast<int>(scores.size() - 1));
}

static void nms_sorted_bboxes(const std::vector<BBoxRect>& bboxes, std::vector<int>& picked, float nms_threshold)
static void nms_sorted_bboxes(const std::vector<BBoxRect>& bboxes, std::vector<size_t>& picked, float nms_threshold)
{
picked.clear();

const int n = bboxes.size();
const size_t n = bboxes.size();

std::vector<float> 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<BBoxRect>& bboxes, std::vector<i
areas[i] = width * height;
}

for (int i = 0; i < n; i++)
for (size_t i = 0; i < n; i++)
{
const BBoxRect& a = bboxes[i];

@@ -159,7 +159,7 @@ static void nms_sorted_bboxes(const std::vector<BBoxRect>& bboxes, std::vector<i

static inline float sigmoid(float x)
{
return 1.f / (1.f + exp(-x));
return static_cast<float>(1.f / (1.f + exp(-x)));
}

int Yolov3DetectionOutput::forward(const std::vector<Mat>& bottom_blobs, std::vector<Mat>& top_blobs, const Option& opt) const
@@ -185,7 +185,7 @@ int Yolov3DetectionOutput::forward(const std::vector<Mat>& 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<Mat>& 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<int>(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<Mat>& 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<float>(exp(wptr[0]) * bias_w / net_w);
float bbox_h = static_cast<float>(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<Mat>& bottom_blobs, std::ve
qsort_descent_inplace(all_bbox_rects, all_bbox_scores);

// apply nms
std::vector<int> picked;
std::vector<size_t> picked;
nms_sorted_bboxes(all_bbox_rects, picked, nms_threshold);

// select
std::vector<BBoxRect> bbox_rects;
std::vector<float> 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<int>(bbox_rects.size());
if (num_detected == 0)
return 0;

@@ -313,7 +313,7 @@ int Yolov3DetectionOutput::forward(const std::vector<Mat>& 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<float>(r.label + 1);// +1 for prepend background class
outptr[1] = score;
outptr[2] = r.xmin;
outptr[3] = r.ymin;


+ 9
- 9
src/net.cpp View File

@@ -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<int>(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<int>(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<int>(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<int>(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<custom_layer_registry_entry_count; i++)
const size_t custom_layer_registry_entry_count = custom_layer_registry.size();
for (size_t i=0; i<custom_layer_registry_entry_count; i++)
{
if (strcmp(type, custom_layer_registry[i].name) == 0)
return i;
return static_cast<int>(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<Mat>& 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;


+ 1
- 1
src/net.h View File

@@ -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;


+ 32
- 32
tools/mxnet/mxnet2ncnn.cpp View File

@@ -559,19 +559,19 @@ static bool read_mxnet_param(const char* parampath, std::vector<MXNetParam>& 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<MXNetParam>& 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<MXNetParam>& 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<MXNetParam>& 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<MXNetParam>& 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<MXNetParam>& 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<MXNetParam>& 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<MXNetParam>& 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<MXNetParam>& 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<MXNetParam>& 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<MXNetParam>& 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<MXNetParam>& 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<MXNetParam>& 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<MXNetParam>& 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<MXNetParam>& par

static void fuse_shufflechannel(std::vector<MXNetNode>& nodes, std::vector<MXNetParam>& params, std::map<int, int>& node_reference, std::set<std::string>& blob_names, int& reduced_node_count)
{
int node_count = nodes.size();
for (int i=0; i<node_count; i++)
size_t node_count = nodes.size();
for (size_t i=0; i<node_count; i++)
{
const MXNetNode& n = nodes[i];

@@ -943,7 +943,7 @@ int main(int argc, char** argv)
// magic
fprintf(pp, "7767517\n");

int node_count = nodes.size();
size_t node_count = nodes.size();

// node reference
std::map<int, int> 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<float> slope_data = n.weight(0);
std::vector<float> bias_data = n.weight(1);

int channels = slope_data.size();
int channels = static_cast<int>(slope_data.size());

std::vector<float> mean_data = n.weight(2, channels);
std::vector<float> 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<int>(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<num_filter_g; k++)
{
@@ -2115,7 +2115,7 @@ int main(int argc, char** argv)
else if (n.op == "L2Normalization")
{
std::string mode = n.attr("mode");
float eps = n.has_attr("eps") ? n.attr("eps") : 1e-10;
float eps = n.has_attr("eps") ? n.attr("eps") : 1e-10f;

int across_spatial = 0;
int across_channel = 1;
@@ -2205,7 +2205,7 @@ int main(int argc, char** argv)
{
// if axis set, reduce according to axis
fprintf(pp, " 1=%d", 0);
fprintf(pp, " -23303=%d", axis.size());
fprintf(pp, " -23303=%zd", axis.size());
for (int i=0; i< axis.size(); i++)
{
if (axis[i] == 0 || axis[i] > 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]);


Loading…
Cancel
Save