* Fix warning C4244 in src/layer/normalize.cpp
C4244: '=': conversion from 'double' to 'float', possible loss of data
* Fix warning C4244 in src/layer/requantize.cpp
C4244: 'initializing': conversion from 'double' to 'int', possible loss of data
* Fix warning C4244 in src/mat_pixel_resize.cpp
C4244: '=': conversion from 'double' to 'int', possible loss of data
* Fix warning C4244 in src/mat_pixel.cpp
C4244: '=': conversion from 'int' to 'float', possible loss of data
* Fix warning C4267 in src/modelbin.cpp
C4267: 'initializing': conversion from 'size_t' to 'int', possible loss of data
* Fix warning C4244 in src/layer/batchnorm.cpp
C4244: 'initializing': conversion from 'double' to 'float',
possible loss of data
* Fix warning C4244 in src/layer/padding.cpp
C4244: 'argument': conversion from 'const float' to 'T', possible loss of data
* Fix warning C4244 in src/layer/priorbox.cpp
C4244: '=': conversion from 'double' to 'float',
possible loss of data
C4244: 'initializing': conversion from 'double' to 'float',
possible loss of data
tags/20200106
| @@ -60,7 +60,7 @@ int BatchNorm::load_model(const ModelBin& mb) | |||
| for (int i=0; i<channels; i++) | |||
| { | |||
| float sqrt_var = sqrt(var_data[i] + eps); | |||
| float sqrt_var = static_cast<float>(sqrt(var_data[i] + eps)); | |||
| a_data[i] = bias_data[i] - slope_data[i] * mean_data[i] / sqrt_var; | |||
| b_data[i] = slope_data[i] / sqrt_var; | |||
| } | |||
| @@ -86,7 +86,7 @@ int Normalize::forward_inplace(Mat& bottom_top_blob, const Option& opt) const | |||
| float a; | |||
| if (eps_mode == 0) // caffe/mxnet | |||
| { | |||
| a = 1.f / sqrt(ssum + eps); | |||
| a = static_cast<float>(1.f / sqrt(ssum + eps)); | |||
| } | |||
| else if (eps_mode == 1) // pytorch | |||
| { | |||
| @@ -94,7 +94,7 @@ int Normalize::forward_inplace(Mat& bottom_top_blob, const Option& opt) const | |||
| } | |||
| else //if (eps_mode == 2) // tensorflow | |||
| { | |||
| a = 1.f / sqrt(std::max(ssum, eps)); | |||
| a = static_cast<float>(1.f / sqrt(std::max(ssum, eps))); | |||
| } | |||
| if (channel_shared) | |||
| @@ -146,7 +146,7 @@ int Normalize::forward_inplace(Mat& bottom_top_blob, const Option& opt) const | |||
| float a; | |||
| if (eps_mode == 0) // caffe/mxnet | |||
| { | |||
| a = 1.f / sqrt(ssum + eps); | |||
| a = static_cast<float>(1.f / sqrt(ssum + eps)); | |||
| } | |||
| else if (eps_mode == 1) // pytorch | |||
| { | |||
| @@ -154,7 +154,7 @@ int Normalize::forward_inplace(Mat& bottom_top_blob, const Option& opt) const | |||
| } | |||
| else //if (eps_mode == 2) // tensorflow | |||
| { | |||
| a = 1.f / sqrt(std::max(ssum, eps)); | |||
| a = static_cast<float>(1.f / sqrt(std::max(ssum, eps))); | |||
| } | |||
| float scale = a * (channel_shared ? scale_data[0] : scale_data[q]); | |||
| @@ -193,7 +193,7 @@ int Normalize::forward_inplace(Mat& bottom_top_blob, const Option& opt) const | |||
| float a; | |||
| if (eps_mode == 0) // caffe/mxnet | |||
| { | |||
| a = 1.f / sqrt(ssum + eps); | |||
| a = static_cast<float>(1.f / sqrt(ssum + eps)); | |||
| } | |||
| else if (eps_mode == 1) // pytorch | |||
| { | |||
| @@ -201,7 +201,7 @@ int Normalize::forward_inplace(Mat& bottom_top_blob, const Option& opt) const | |||
| } | |||
| else //if (eps_mode == 2) // tensorflow | |||
| { | |||
| a = 1.f / sqrt(std::max(ssum, eps)); | |||
| a = static_cast<float>(1.f / sqrt(std::max(ssum, eps))); | |||
| } | |||
| square_sum_blob[i] = a * scale; | |||
| @@ -233,7 +233,7 @@ int Normalize::forward_inplace(Mat& bottom_top_blob, const Option& opt) const | |||
| float a; | |||
| if (eps_mode == 0) // caffe/mxnet | |||
| { | |||
| a = 1.f / sqrt(ssum + eps); | |||
| a = static_cast<float>(1.f / sqrt(ssum + eps)); | |||
| } | |||
| else if (eps_mode == 1) // pytorch | |||
| { | |||
| @@ -241,7 +241,7 @@ int Normalize::forward_inplace(Mat& bottom_top_blob, const Option& opt) const | |||
| } | |||
| else //if (eps_mode == 2) // tensorflow | |||
| { | |||
| a = 1.f / sqrt(std::max(ssum, eps)); | |||
| a = static_cast<float>(1.f / sqrt(std::max(ssum, eps))); | |||
| } | |||
| square_sum_blob[i] = a; | |||
| @@ -298,7 +298,7 @@ int Padding::forward(const Mat& bottom_blob, Mat& top_blob, const Option& opt) c | |||
| return -100; | |||
| if (elemsize == 1) | |||
| copy_make_border_image<signed char>(bottom_blob, top_blob, 0, left, type, value); | |||
| copy_make_border_image<signed char>(bottom_blob, top_blob, 0, left, type, static_cast<signed char>(value)); | |||
| else if (elemsize == 4) | |||
| copy_make_border_image<float>(bottom_blob, top_blob, 0, left, type, value); | |||
| @@ -314,7 +314,7 @@ int Padding::forward(const Mat& bottom_blob, Mat& top_blob, const Option& opt) c | |||
| return -100; | |||
| if (elemsize == 1) | |||
| copy_make_border_image<signed char>(bottom_blob, top_blob, top, left, type, value); | |||
| copy_make_border_image<signed char>(bottom_blob, top_blob, top, left, type, static_cast<signed char>(value)); | |||
| else if (elemsize == 4) | |||
| copy_make_border_image<float>(bottom_blob, top_blob, top, left, type, value); | |||
| @@ -334,7 +334,7 @@ int Padding::forward(const Mat& bottom_blob, Mat& top_blob, const Option& opt) c | |||
| Mat borderm = top_blob.channel(q); | |||
| if (elemsize == 1) | |||
| copy_make_border_image<signed char>(m, borderm, top, left, type, value); | |||
| copy_make_border_image<signed char>(m, borderm, top, left, type, static_cast<signed char>(value)); | |||
| else if (elemsize == 4) | |||
| copy_make_border_image<float>(m, borderm, top, left, type, value); | |||
| } | |||
| @@ -386,7 +386,7 @@ int Padding::forward(const std::vector<Mat>& bottom_blobs, std::vector<Mat>& top | |||
| return -100; | |||
| if (elemsize == 1) | |||
| copy_make_border_image<signed char>(bottom_blob, top_blob, 0, _left, type, value); | |||
| copy_make_border_image<signed char>(bottom_blob, top_blob, 0, _left, type, static_cast<signed char>(value)); | |||
| else if (elemsize == 4) | |||
| copy_make_border_image<float>(bottom_blob, top_blob, 0, _left, type, value); | |||
| @@ -402,7 +402,7 @@ int Padding::forward(const std::vector<Mat>& bottom_blobs, std::vector<Mat>& top | |||
| return -100; | |||
| if (elemsize == 1) | |||
| copy_make_border_image<signed char>(bottom_blob, top_blob, _top, _left, type, value); | |||
| copy_make_border_image<signed char>(bottom_blob, top_blob, _top, _left, type, static_cast<signed char>(value)); | |||
| else if (elemsize == 4) | |||
| copy_make_border_image<float>(bottom_blob, top_blob, _top, _left, type, value); | |||
| @@ -422,7 +422,7 @@ int Padding::forward(const std::vector<Mat>& bottom_blobs, std::vector<Mat>& top | |||
| Mat borderm = top_blob.channel(q); | |||
| if (elemsize == 1) | |||
| copy_make_border_image<signed char>(m, borderm, _top, _left, type, value); | |||
| copy_make_border_image<signed char>(m, borderm, _top, _left, type, static_cast<signed char>(value)); | |||
| else if (elemsize == 4) | |||
| copy_make_border_image<float>(m, borderm, _top, _left, type, value); | |||
| } | |||
| @@ -101,7 +101,7 @@ int PriorBox::forward(const std::vector<Mat>& bottom_blobs, std::vector<Mat>& to | |||
| float size = min_sizes[0]; | |||
| for (int p = 1; p < num_ratios; p++) | |||
| { | |||
| float ratio = sqrt(aspect_ratios[p]); | |||
| float ratio = static_cast<float>(sqrt(aspect_ratios[p])); | |||
| float cw = size * h / w * ratio / 2; | |||
| float ch = size / ratio / 2; | |||
| @@ -141,13 +141,13 @@ int PriorBox::forward(const std::vector<Mat>& bottom_blobs, std::vector<Mat>& to | |||
| { | |||
| step_w = (float)image_w / w; | |||
| if (step_mmdetection) | |||
| step_w = ceil((float)image_w / w); | |||
| step_w = static_cast<float>(ceil((float)image_w / w)); | |||
| } | |||
| if (step_h == -233) | |||
| { | |||
| step_h = (float)image_h / h; | |||
| if (step_mmdetection) | |||
| step_h = ceil((float)image_h / h); | |||
| step_h = static_cast<float>(ceil((float)image_h / h)); | |||
| } | |||
| int num_min_size = min_sizes.w; | |||
| @@ -200,7 +200,7 @@ int PriorBox::forward(const std::vector<Mat>& bottom_blobs, std::vector<Mat>& to | |||
| float max_size = max_sizes[k]; | |||
| // max size box | |||
| box_w = box_h = sqrt(min_size * max_size); | |||
| box_w = box_h = static_cast<float>(sqrt(min_size * max_size)); | |||
| box[0] = (center_x - box_w * 0.5f) / image_w; | |||
| box[1] = (center_y - box_h * 0.5f) / image_h; | |||
| @@ -215,8 +215,8 @@ int PriorBox::forward(const std::vector<Mat>& bottom_blobs, std::vector<Mat>& to | |||
| { | |||
| float ar = aspect_ratios[p]; | |||
| box_w = min_size * sqrt(ar); | |||
| box_h = min_size / sqrt(ar); | |||
| box_w = static_cast<float>(min_size * sqrt(ar)); | |||
| box_h = static_cast<float>(min_size / sqrt(ar)); | |||
| box[0] = (center_x - box_w * 0.5f) / image_w; | |||
| box[1] = (center_y - box_h * 0.5f) / image_h; | |||
| @@ -29,7 +29,7 @@ Requantize::Requantize() | |||
| 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; | |||
| @@ -717,7 +717,7 @@ static int from_rgb2gray(const unsigned char* rgb, int w, int h, int stride, Mat | |||
| #endif // __ARM_NEON | |||
| for (; remain>0; remain--) | |||
| { | |||
| *ptr = (rgb[0] * R2Y + rgb[1] * G2Y + rgb[2] * B2Y) >> Y_shift; | |||
| *ptr = static_cast<float>((rgb[0] * R2Y + rgb[1] * G2Y + rgb[2] * B2Y) >> Y_shift); | |||
| rgb += 3; | |||
| ptr++; | |||
| @@ -874,7 +874,7 @@ static int from_bgr2gray(const unsigned char* bgr, int w, int h, int stride, Mat | |||
| #endif // __ARM_NEON | |||
| for (; remain>0; remain--) | |||
| { | |||
| *ptr = (bgr[2] * R2Y + bgr[1] * G2Y + bgr[0] * B2Y) >> Y_shift; | |||
| *ptr = static_cast<float>((bgr[2] * R2Y + bgr[1] * G2Y + bgr[0] * B2Y) >> Y_shift); | |||
| bgr += 3; | |||
| ptr++; | |||
| @@ -1428,7 +1428,7 @@ static int from_rgba2gray(const unsigned char* rgba, int w, int h, int stride, M | |||
| #endif // __ARM_NEON | |||
| for (; remain>0; remain--) | |||
| { | |||
| *ptr = (rgba[0] * R2Y + rgba[1] * G2Y + rgba[2] * B2Y) >> Y_shift; | |||
| *ptr = static_cast<float>((rgba[0] * R2Y + rgba[1] * G2Y + rgba[2] * B2Y) >> Y_shift); | |||
| rgba += 4; | |||
| ptr++; | |||
| @@ -71,7 +71,7 @@ void resize_bilinear_c1(const unsigned char* src, int srcw, int srch, int srcstr | |||
| for (int dx = 0; dx < w; dx++) | |||
| { | |||
| fx = (float)((dx + 0.5) * scale_x - 0.5); | |||
| sx = floor(fx); | |||
| sx = static_cast<int>(floor(fx)); | |||
| fx -= sx; | |||
| if (sx < 0) | |||
| @@ -97,7 +97,7 @@ void resize_bilinear_c1(const unsigned char* src, int srcw, int srch, int srcstr | |||
| for (int dy = 0; dy < h; dy++) | |||
| { | |||
| fy = (float)((dy + 0.5) * scale_y - 0.5); | |||
| sy = floor(fy); | |||
| sy = static_cast<int>(floor(fy)); | |||
| fy -= sy; | |||
| if (sy < 0) | |||
| @@ -326,7 +326,7 @@ void resize_bilinear_c2(const unsigned char* src, int srcw, int srch, int srcstr | |||
| for (int dx = 0; dx < w; dx++) | |||
| { | |||
| fx = (float)((dx + 0.5) * scale_x - 0.5); | |||
| sx = floor(fx); | |||
| sx = static_cast<int>(floor(fx)); | |||
| fx -= sx; | |||
| if (sx < 0) | |||
| @@ -352,7 +352,7 @@ void resize_bilinear_c2(const unsigned char* src, int srcw, int srch, int srcstr | |||
| for (int dy = 0; dy < h; dy++) | |||
| { | |||
| fy = (float)((dy + 0.5) * scale_y - 0.5); | |||
| sy = floor(fy); | |||
| sy = static_cast<int>(floor(fy)); | |||
| fy -= sy; | |||
| if (sy < 0) | |||
| @@ -636,7 +636,7 @@ void resize_bilinear_c3(const unsigned char* src, int srcw, int srch, int srcstr | |||
| for (int dx = 0; dx < w; dx++) | |||
| { | |||
| fx = (float)((dx + 0.5) * scale_x - 0.5); | |||
| sx = floor(fx); | |||
| sx = static_cast<int>(floor(fx)); | |||
| fx -= sx; | |||
| if (sx < 0) | |||
| @@ -662,7 +662,7 @@ void resize_bilinear_c3(const unsigned char* src, int srcw, int srch, int srcstr | |||
| for (int dy = 0; dy < h; dy++) | |||
| { | |||
| fy = (float)((dy + 0.5) * scale_y - 0.5); | |||
| sy = floor(fy); | |||
| sy = static_cast<int>(floor(fy)); | |||
| fy -= sy; | |||
| if (sy < 0) | |||
| @@ -957,7 +957,7 @@ void resize_bilinear_c4(const unsigned char* src, int srcw, int srch, int srcstr | |||
| for (int dx = 0; dx < w; dx++) | |||
| { | |||
| fx = (float)((dx + 0.5) * scale_x - 0.5); | |||
| sx = floor(fx); | |||
| sx = static_cast<int>(floor(fx)); | |||
| fx -= sx; | |||
| if (sx < 0) | |||
| @@ -983,7 +983,7 @@ void resize_bilinear_c4(const unsigned char* src, int srcw, int srch, int srcstr | |||
| for (int dy = 0; dy < h; dy++) | |||
| { | |||
| fy = (float)((dy + 0.5) * scale_y - 0.5); | |||
| sy = floor(fy); | |||
| sy = static_cast<int>(floor(fy)); | |||
| fy -= sy; | |||
| if (sy < 0) | |||
| @@ -77,7 +77,7 @@ Mat ModelBinFromDataReader::load(int w, int type) const | |||
| if (flag_struct.tag == 0x01306B47) | |||
| { | |||
| // half-precision data | |||
| int align_data_size = alignSize(w * sizeof(unsigned short), 4); | |||
| size_t align_data_size = alignSize(w * sizeof(unsigned short), 4); | |||
| std::vector<unsigned short> float16_weights; | |||
| float16_weights.resize(align_data_size); | |||
| nread = dr.read(float16_weights.data(), align_data_size); | |||
| @@ -92,7 +92,7 @@ Mat ModelBinFromDataReader::load(int w, int type) const | |||
| else if (flag_struct.tag == 0x000D4B38) | |||
| { | |||
| // int8 data | |||
| int align_data_size = alignSize(w, 4); | |||
| size_t align_data_size = alignSize(w, 4); | |||
| std::vector<signed char> int8_weights; | |||
| int8_weights.resize(align_data_size); | |||
| nread = dr.read(int8_weights.data(), align_data_size); | |||
| @@ -142,7 +142,7 @@ Mat ModelBinFromDataReader::load(int w, int type) const | |||
| return Mat(); | |||
| } | |||
| int align_weight_data_size = alignSize(w * sizeof(unsigned char), 4); | |||
| size_t align_weight_data_size = alignSize(w * sizeof(unsigned char), 4); | |||
| std::vector<unsigned char> index_array; | |||
| index_array.resize(align_weight_data_size); | |||
| nread = dr.read(index_array.data(), align_weight_data_size); | |||