Skip to content

Whether can remove caffeMode. #2460

@hedaoyuan

Description

@hedaoyuan

In Paddle's code, caffeMode is a value of type bool (ConvBaseLayer::caffeMode_ and caffe_mode). Set to true or false, will affect the output size of the convolution calculation (outputSize and cnn_output_size).

The calculation result when caffeMode is set to false or true is as follows.

/**
 * Calculate output size based on caffeMode_.
 * - input(+padding): 0123456789
 * - imageSize(+padding) = 10;
 * - filterSize = 3;
 * - stride = 2;
 * - caffeMode is true:
     - output: (012), (234), (456), (678)
     - outputSize = 4;
 * - caffeMode is false:
 *   - output: (012), (234), (456), (678), (9)
 *   - outputSize = 5;
 */
int outputSize(int imageSize, int filterSize, int padding, int stride, bool caffeMode) {
  int outputSize;
  if (!caffeMode) {
    outputSize = (imageSize - filterSize + 2 * padding + stride - 1) / stride + 1;
  } else {
    outputSize = (imageSize - filterSize + 2 * padding) / stride + 1;
  }
  return outputSize;
}
  1. The two modes are not the same in some cases.
  2. caffeMode = true refers to the calculation method in caffe. This method is also used in cudnn. So, if the convolution layer is configured as cudnn, you need to ensure that caffe_mode = True.
  3. If the padding is replaced with paddingLeft and paddingRight two arguments. In caffeMode = true formula, modify the size of the padding can also achieve caffeMode = false results.

So, can we remove this configuration argument?

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions