Skip to content

如何在 PyTorch 中实现 TensorFlow 里的 'SAME' padding 和 'VALID' padding? #16

@daa233

Description

@daa233

在 TensorFlow 中,进行卷积和池化等操作时,可以选择 padding 的方式,一般有 'SAME' 和 'VALID' 两种方式。根据 StackOverflow 上的这个回答,在 TensorFlow 中,这两种方式的区别如下。

对于 'SAME' padding,其输出的高度和宽度计算方式为:

out_height = ceil(float(in_height) / float(strides[1]))
out_width  = ceil(float(in_width) / float(strides[2]))

对于 'VALID' padding,其输出的高度和宽度计算方式为:

out_height = ceil(float(in_height - filter_height + 1) / float(strides[1]))
out_width  = ceil(float(in_width - filter_width + 1) / float(strides[2]))

但是在 PyTorch 中没有类似 'SAME' 和 'VALID' padding 这种接口,需要自行指定 padding 的大小。

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions