简体   繁体   English

为什么 PyTorch DQN 教程中的 CNN 卷积输出大小是用 `kernel_size -1` 计算的?

[英]Why is CNN convolution output size in PyTorch DQN tutorial computed with `kernel_size -1`?

Based on my understanding, CNN output size for 1D is根据我的理解,1D 的 CNN 输出大小是

output_size = (input_size - kernel_size + 2*padding)//stride + 1

Refer to PyTorch DQN Tutorial .请参阅PyTorch DQN 教程 In the tutorial, it uses 0 padding, which is fine.在教程中,它使用 0 填充,这很好。 However, it computes the output size as follows:但是,它计算输出大小如下:

        def conv2d_size_out(size, kernel_size = 5, stride = 2):
            return (size - (kernel_size - 1) - 1) // stride  + 1

It the above a mistake or is there something I missed?以上是错误还是我错过了什么?

No, it's not a mistake because不,这不是错误,因为

size - (kernel_size - 1) - 1 = size - kernel_size + 2 * 0

with 0 as padding以 0 作为填充
(it's not code, its an equation sorry for the formatting) (这不是代码,它是一个公式,抱歉格式化)
I think the tutorial is using the formula for the output size from the official document which is我认为本教程使用的是官方文档中的输出大小公式

output_size = ((input_size + 2 * padding - dialation * (kernel_size - 1) - 1) // stride + 1

official doc for conv1d conv1d 的官方文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM