未验证 提交 56879f2e 编写于 作者: B BUG1989 提交者: GitHub

Fix, interp, pad (#691)

上级 00dfa15c
......@@ -165,43 +165,81 @@ void resize_bilinear_image(float* src, float* dst, float* alpha, int* xofs, floa
int ref_interp_fp32(struct tensor* input_tensor, struct tensor* output_tensor, struct interp_param* param)
{
float* input = input_tensor->data;
float* output = output_tensor->data;
if (param->resize_type == 1)
{
float* input = input_tensor->data;
float* output = output_tensor->data;
int batch = input_tensor->dims[0];
int channel = input_tensor->dims[1];
int in_h = input_tensor->dims[2];
int in_w = input_tensor->dims[3];
int out_h = output_tensor->dims[2];
int out_w = output_tensor->dims[3];
int batch = output_tensor->dims[0];
int channel = output_tensor->dims[1];
int output_h = output_tensor->dims[2];
int output_w = output_tensor->dims[3];
int input_h = input_tensor->dims[2];
int input_w = input_tensor->dims[3];
int in_channel_size = in_h * in_w;
int out_channel_size = out_h * out_w;
for (int n = 0; n < batch; ++n)
{
for (int c = 0; c < channel; c++)
{
for (int h = 0; h < output_h; h++)
{
for (int w = 0; w < output_w; w++)
{
int in_w = w / param->width_scale;
int in_h = h / param->height_scale;
int out_idx = n * channel * output_h * output_w + c * output_h * output_w + h * output_w + w;
int in_idx = n * channel * input_h * input_w + c * input_w * input_h + in_h * input_w + in_w;
output[out_idx] = input[in_idx];
}
}
}
}
}
else if (param->resize_type == 2)
{
float* input = input_tensor->data;
float* output = output_tensor->data;
int* buf = sys_malloc((param->output_width + param->output_height + param->output_width*2 + param->output_height*2)*sizeof(float));
int batch = input_tensor->dims[0];
int channel = input_tensor->dims[1];
int in_h = input_tensor->dims[2];
int in_w = input_tensor->dims[3];
int out_h = output_tensor->dims[2];
int out_w = output_tensor->dims[3];
if (buf == NULL)
{
TLOG_ERR("interp malloc failed!\n");
return -1;
}
int in_channel_size = in_h * in_w;
int out_channel_size = out_h * out_w;
int* xofs = buf;//new int[ow];
int* yofs = buf + param->output_width ;//new int[oh];
int* buf = sys_malloc((param->output_width + param->output_height + param->output_width*2 + param->output_height*2)*sizeof(float));
float* alpha = (float*)(buf + param->output_width + param->output_height);//new float[ow * 2];
float* beta = (float*)(buf + param->output_width + param->output_height + param->output_width*2);//new float[oh * 2];
if (buf == NULL)
{
TLOG_ERR("interp malloc failed!\n");
return -1;
}
int* xofs = buf;//new int[ow];
int* yofs = buf + param->output_width ;//new int[oh];
float* alpha = (float*)(buf + param->output_width + param->output_height);//new float[ow * 2];
float* beta = (float*)(buf + param->output_width + param->output_height + param->output_width*2);//new float[oh * 2];
linear_coeffs(in_w, out_w, xofs, alpha);
linear_coeffs(in_h, out_h, yofs, beta);
linear_coeffs(in_w, out_w, xofs, alpha);
linear_coeffs(in_h, out_h, yofs, beta);
for (int q = 0; q < channel; ++q)
{
resize_bilinear_image(input+in_channel_size*q, output+out_channel_size*q, alpha, xofs, beta, yofs, out_h, out_w, in_h, in_w);
}
for (int q = 0; q < channel; ++q)
sys_free(buf);
}
else
{
resize_bilinear_image(input+in_channel_size*q, output+out_channel_size*q, alpha, xofs, beta, yofs, out_h, out_w, in_h, in_w);
TLOG_ERR("interp resize type %d not support!\n", param->resize_type);
return -1;
}
sys_free(buf);
return 0;
}
......@@ -227,36 +265,73 @@ int ref_interp_uint8(struct tensor* input_tensor, struct tensor* output_tensor,
}
/* process */
int batch = input_tensor->dims[0];
int channel = input_tensor->dims[1];
int in_h = input_tensor->dims[2];
int in_w = input_tensor->dims[3];
int out_h = output_tensor->dims[2];
int out_w = output_tensor->dims[3];
if (param->resize_type == 1)
{
int batch = output_tensor->dims[0];
int channel = output_tensor->dims[1];
int output_h = output_tensor->dims[2];
int output_w = output_tensor->dims[3];
int input_h = input_tensor->dims[2];
int input_w = input_tensor->dims[3];
for (int n = 0; n < batch; ++n)
{
for (int c = 0; c < channel; c++)
{
for (int h = 0; h < output_h; h++)
{
for (int w = 0; w < output_w; w++)
{
int in_w = w / param->width_scale;
int in_h = h / param->height_scale;
int out_idx = n * channel * output_h * output_w + c * output_h * output_w + h * output_w + w;
int in_idx = n * channel * input_h * input_w + c * input_w * input_h + in_h * input_w + in_w;
output_fp32[out_idx] = input_fp32[in_idx];
}
}
}
}
}
else if (param->resize_type == 2)
{
int batch = input_tensor->dims[0];
int channel = input_tensor->dims[1];
int in_h = input_tensor->dims[2];
int in_w = input_tensor->dims[3];
int out_h = output_tensor->dims[2];
int out_w = output_tensor->dims[3];
int in_channel_size = in_h * in_w;
int out_channel_size = out_h * out_w;
int in_channel_size = in_h * in_w;
int out_channel_size = out_h * out_w;
int* buf = sys_malloc((param->output_width + param->output_height + param->output_width*2 + param->output_height*2)*sizeof(float));
int* buf = sys_malloc((param->output_width + param->output_height + param->output_width*2 + param->output_height*2)*sizeof(float));
if (buf == NULL)
{
TLOG_ERR("interp malloc failed!\n");
return -1;
}
if (buf == NULL)
{
TLOG_ERR("interp malloc failed!\n");
return -1;
}
int* xofs = buf;//new int[ow];
int* yofs = buf + param->output_width ;//new int[oh];
int* xofs = buf;//new int[ow];
int* yofs = buf + param->output_width ;//new int[oh];
float* alpha = (float*)(buf + param->output_width + param->output_height);//new float[ow * 2];
float* beta = (float*)(buf + param->output_width + param->output_height + param->output_width*2);//new float[oh * 2];
float* alpha = (float*)(buf + param->output_width + param->output_height);//new float[ow * 2];
float* beta = (float*)(buf + param->output_width + param->output_height + param->output_width*2);//new float[oh * 2];
linear_coeffs(in_w, out_w, xofs, alpha);
linear_coeffs(in_h, out_h, yofs, beta);
linear_coeffs(in_w, out_w, xofs, alpha);
linear_coeffs(in_h, out_h, yofs, beta);
for (int q = 0; q < channel; ++q)
for (int q = 0; q < channel; ++q)
{
resize_bilinear_image(input_fp32+in_channel_size*q, output_fp32+out_channel_size*q, alpha, xofs, beta, yofs, out_h, out_w, in_h, in_w);
}
sys_free(buf);
}
else
{
resize_bilinear_image(input_fp32+in_channel_size*q, output_fp32+out_channel_size*q, alpha, xofs, beta, yofs, out_h, out_w, in_h, in_w);
TLOG_ERR("interp resize type %d not support!\n", param->resize_type);
return -1;
}
/* quant */
......@@ -270,7 +345,6 @@ int ref_interp_uint8(struct tensor* input_tensor, struct tensor* output_tensor,
output_uint8[i] = udata;
}
sys_free(buf);
sys_free(input_fp32);
sys_free(output_fp32);
......
......@@ -80,13 +80,10 @@ static void ref_pad_fp32(float* input, float* output, int in_h, int in_w, int ou
}
else
{
// memcpy(outptr + left, ptr, in_w * sizeof(float));
// x += in_w;
for (x = 0; x < in_w; x++)
{
outptr[left + x] = ptr[x];
}
x++;
}
for (; x < out_w; x++)
{
......@@ -140,8 +137,6 @@ static void ref_pad_uint8(uint8_t* input, uint8_t* output, int in_h, int in_w, i
}
else
{
// memcpy(outptr + left, ptr, in_w * sizeof(float));
// x += in_w;
for (; x < in_w; x++)
{
outptr[left + x] = ptr[x];
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册