hszhao / PSPNet

Pyramid Scene Parsing Network, CVPR2017.
https://hszhao.github.io/projects/pspnet
Other
1.59k stars 545 forks source link

[FIXED] Why are scale_factors used to scale pixel values? #92

Closed jianchao-li closed 6 years ago

jianchao-li commented 6 years ago

I read the function TransformImgAndSeg, which has the following codes.

// perform scaling
if (scale_factors_.size() > 0) {
  int scale_ind = Rand(scale_factors_.size());
  Dtype scale   = scale_factors_[scale_ind];

  if (scale != 1) {
    img_height *= scale;
    img_width  *= scale;
    ...

scale is a random scale_factor defined in transform_param, used to scale the size of the image. This makes perfect sense.

However, I noticed that the scale is also used to scale the pixel values in the same function.

if (has_mean_file) {
  int mean_index = (c * img_height + h_off + h) * img_width + w_off + w;
  transformed_data[top_index] =
    (pixel - mean[mean_index]) * scale;
} else {
    if (has_mean_values) {
      transformed_data[top_index] =
        (pixel - mean_values_[c]) * scale;
    } else {
      transformed_data[top_index] = pixel * scale;
    }
}

I think we should scale the pixel values using the scale in transform_param instead of this random scale_factor, right?

jianchao-li commented 6 years ago

I misunderstood the codes. The correct scale is defined in the outer scope which is used to scale the pixel values.