0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

特徴画像のサイズを計算する

Last updated at Posted at 2024-04-12

畳み込みとプーリングを2回ずつ行った際の、特徴画像の一辺の長さを計算する関数です。

def calc_character_size(image_node, padding, kernel_size, stride):
    
    x = ((image_node + 2*padding - kernel_size) // stride) + 1
    x = x // 2
    x = ((x + 2*padding - kernel_size) // stride) + 1
    x = x // 2

    return int(x)

#MNISTの場合、一辺が28ピクセルの正方形
#padding=0, kernel_size=3, stride=1として計算
character_size = calc_character_size(28, 0, 3, 1)
print(character_size)
#5
#特徴画像の一辺は5ピクセル

PyTorch以外のライブラリ(KerasとかTensorflowとか)だと、畳み込みで小さくなった画像サイズを自動でpaddingして補完してくれる関数(same関数?)があったりするらしいです。PyTorchにはないみたいで、残念です。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?