Pythonでcol2im関数を実装するときに下のコードの5行目のimages配列の3, 4次元目のサイズがなぜimg_h(img_w)+2pad+stride-1になるのかが分かりません。
im2col関数の入力画像と同じ形状にしたいのであればimg_h+2padでいいのではないかと考えてしまいます。
できれば具体例も示していただけると幸いです。
python
1def col2im(cols, img_shape, flt_h, flt_w, out_h, out_w, stride, pad): 2 n_bt, n_ch, img_h, img_w = img_shape 3 4 cols = cols.reshape(n_ch, flt_h, flt_w, n_bt, out_h, out_w).transpose(3, 0, 1, 2, 4, 5) 5 images = np.zeros((n_bt, n_ch, img_h + 2 * pad + stride - 1, img_w + 2 * pad + stride - 1)) 6 7 for h in range(flt_h): 8 h_lim = h + stride * out_h 9 for w in range(flt_w): 10 w_lim = w + stride * out_w 11 images[:, :, h:h_lim:stride, w:w_lim:stride] += cols[:, :, h, w, :, :] 12 13 return images[:, :, pad:img_h + pad, pad:img_w + pad]
あなたの回答
tips
プレビュー