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?

More than 3 years have passed since last update.

畳み込み

Last updated at Posted at 2021-05-02

2D畳み込み演算の表現

| | | | | |
|:-:|:-:|:-:|:-:|:-:|:-:|
|| a | b | c | d | e |
|| f | g | h | i | j |
|| k | l | m | n | o |
|| p | q | r | s | t |

上のような入力画像に対し、以下のような3*3のカーネル(フィルター/チャネル)を使ってたたみ込むとする。
padding=same, stride=1,dilation rate=1とする。

1 4 7
2 5 8
3 6 9

gの欄に、畳み込みの結果割り当てられる値は
a+4b+7c+2f+5g+8h+3k+6l+9mとなる

カーネルの9がaに重なる時 最も左上となり、1がtと重なる時に最も右下となる。
総パターン数は(縦にカーネルが動ける行:4+2)x(横にカーネルが動ける列:5+2) = 6行7列の 42通りとなる。
gの欄は3行3列目にあたる。

これを2つの行列の積で表現するには以下のように並べるとよいと思われる。

左からカーネルにあたる6行x12列

| | | | | | | | | | | | | | | | |
|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|
| 3 | 0 | 0 | 0 || 6 | 0 | 0 | 0 || 9 | 0 | 0 | 0 |
| 2 | 3 | 0 | 0 || 5 | 6 | 0 | 0 || 8 | 9 | 0 | 0 |
| 1 | 2 | 3 | 0 || 4 | 5 | 6 | 0 || 7 | 8 | 9 | 0 |
| 0 | 1 | 2 | 3 || 0 | 4 | 5 | 6 || 0 | 7 | 8 | 9 |
| 0 | 0 | 1 | 2 || 0 | 0 | 4 | 5 || 0 | 0 | 7 | 8 |
| 0 | 0 | 0 | 1 || 0 | 0 | 0 | 4 || 0 | 0 | 0 | 7 |

を 右の入力値 12行x7列 に掛けて

| | | | | | | | |
|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|
| 0 | 0 || a | b | c | d | e |
| … | … || f | g | h | i | j |
| … | … || k | l | m | n | o |
| … | 0 || p | q | r | s | t |
| | | | | | |
| … || a | b | c | d | e || 0 |
| … || f | g | h | i | j || … |
| … || k | l | m | n | o || … |
| 0 || p | q | r | s | t || … |
| | | | | | |
|| a | b | c | d | e || 0 | … |
|| f | g | h | i | j || … | … |
|| k | l | m | n | o || … | … |
|| p | q | r | s | t || 0 | 0 |

見やすさのために適宜空白を入れた。

dilation の幅は 入力値の4x5の四角同士のズレにあたるか。
stride の幅は カーネルの行を間引きする間隔となるか。

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?