Help us understand the problem. What is going on with this article?

[Chainer, PyTorch] Deconvolutionの出力サイズの計算式

chainerでDeconvolutionの出力サイズの計算がよくわからなかったのでメモ
pytorchの方のドキュメントを漁ったら出て来ました

pytorchの場合

こちらはちゃんとドキュメントに幅と高さの計算方法を書いてくれてます
https://pytorch.org/docs/stable/nn.html#torch.nn.ConvTranspose2d

class torch.nn.ConvTranspose2d(in_channels, out_channels, kernel_size, stride=1, padding=0, output_padding=0, groups=1, bias=True, dilation=1)
\begin{align}
    H_{out} &= (H_{in} - 1)\times stride[0] - 2 \times pad[0] + ksize[0] + output\_padding[0] \\ 
    W_{out} &= (W_{in} - 1)\times stride[1] - 2 \times pad[1] + ksize[1] + output\_padding[1]
\end{align}

chainerの場合

ドキュメントには書いていないですが、ソースコードを見るとほぼ同じであることがわかります
https://docs.chainer.org/en/stable/reference/generated/chainer.links.Deconvolution2D.html

class chainer.links.Deconvolution2D(self, in_channels, out_channels, ksize=None, stride=1, pad=0, nobias=False, outsize=None, initialW=None, initial_bias=None, *, groups=1)
\begin{align}
    H_{out} &= (H_{in} - 1)\times stride[0] - 2 \times pad[0] + ksize[0] \\ 
    W_{out} &= (W_{in} - 1)\times stride[1] - 2 \times pad[1] + ksize[1]
\end{align}

chainerはpytorchと違ってoutput_paddingがありません。
そのため、$H_{in}$とksizeが共に奇数の場合、

\begin{equation}
H_{out} = (奇数-1)\times stride[0] - 2\times pad[0] + 奇数 = 奇数
\end{equation}

より、$H_{out}$は奇数にしかなりません
$H_{out}$を偶数にしたい場合は、ksizeの方を変える必要が生じる場合がありそうです
(GANのコードとかだとdeconvolutionでconvolutionとksizeが違う場合は多々あるのでまあ良いのでは?)

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away