プリンキピア

第14章コンピュータビジョン

14.8.2. Fast R-CNN14.8.2 Fast R-CNN

The main performance bottleneck of an R-CNN lies in the independent CNN forward propagation for each region proposal, without sharing computation. Since these regions usually have overlaps, independent feature extractions lead to much repeated computation. One of the major improvements of the fast R-CNN from the R-CNN is that the CNN forward propagation is only performed on the entire image (Girshick, 2015).
英語のヒント
R-CNNの性能の主なボトルネックは、計算を共有せずに、各領域候補について独立にCNNの順伝播を行う点にある。これらの領域はふつう重なるので、独立に特徴を抽出すると多くの計算が繰り返される。R-CNNからのfast R-CNNの主な改良の一つは、CNNの順伝播を画像全体に対してだけ行うことである(Girshick, 2015)。
Fig. 14.8.2図14.8.2
The fast R-CNN model.
英語のヒント
fast R-CNNモデル。
Fig. 14.8.2 describes the fast R-CNN model. Its major computations are as follows:
英語のヒント
図14.8.2は、fast R-CNNモデルを説明している。その主な計算は次のとおりである。
  1. Compared with the R-CNN, in the fast R-CNN the input of the CNN for feature extraction is the entire image, rather than individual region proposals. Moreover, this CNN is trainable. Given an input image, let the shape of the CNN output be 1×c×h1×w1.
    英語のヒント
    R-CNNと比べて、fast R-CNNでは、特徴を抽出するCNNの入力は、個々の領域候補ではなく画像全体である。さらに、このCNNは訓練できる。入力画像が与えられたとき、CNNの出力の形状を1×c×h1×w1とする。
  2. Suppose that selective search generates n region proposals. These region proposals (of different shapes) mark regions of interest (of different shapes) on the CNN output. Then these regions of interest further extract features of the same shape (say height h2 and width w2 are specified) in order to be easily concatenated. To achieve this, the fast R-CNN introduces the region of interest (RoI) pooling layer: the CNN output and region proposals are input into this layer, outputting concatenated features of shape n×c×h2×w2 that are further extracted for all the region proposals.
    英語のヒント
    選択的探索がn個の領域候補を生成するとする。これらの(形の異なる)領域候補は、CNNの出力の上に(形の異なる)注目領域を示す。それから、これらの注目領域は、簡単に連結できるように、同じ形状(たとえば高さh2と幅w2を指定する)の特徴をさらに抽出する。これを達成するため、fast R-CNNは注目領域(RoI)プーリング層を導入する。CNNの出力と領域候補がこの層に入力され、すべての領域候補についてさらに抽出された、形状n×c×h2×w2の連結された特徴を出力する。
  3. Using a fully connected layer, transform the concatenated features into an output of shape n×d, where d depends on the model design.
    英語のヒント
    全結合層を使って、連結した特徴を形状n×dの出力に変換する。ここでdはモデルの設計に依存する。
  4. Predict the class and bounding box for each of the n region proposals. More concretely, in class and bounding box prediction, transform the fully connected layer output into an output of shape n×q (q is the number of classes) and an output of shape n×4, respectively. The class prediction uses softmax regression.
    英語のヒント
    n個の領域候補のそれぞれについて、クラスと境界ボックスを予測する。もっと具体的には、クラスと境界ボックスの予測では、全結合層の出力を、それぞれ形状n×qの出力(qはクラスの数)と形状n×4の出力に変換する。クラスの予測にはソフトマックス回帰を使う。
The region of interest pooling layer proposed in the fast R-CNN is different from the pooling layer introduced in Section 7.5. In the pooling layer, we indirectly control the output shape by specifying sizes of the pooling window, padding, and stride. In contrast, we can directly specify the output shape in the region of interest pooling layer.
英語のヒント
fast R-CNNで提案された注目領域プーリング層は、7.5節で紹介したプーリング層とは異なる。プーリング層では、プーリングの窓、パディング、ストライドの大きさを指定して、出力の形状を間接的に制御する。対照的に、注目領域プーリング層では、出力の形状を直接指定できる。
For example, let’s specify the output height and width for each region as h2 and w2, respectively. For any region of interest window of shape h×w, this window is divided into a h2×w2 grid of subwindows, where the shape of each subwindow is approximately (h/h2)×(w/w2). In practice, the height and width of any subwindow shall be rounded up, and the largest element shall be used as output of the subwindow. Therefore, the region of interest pooling layer can extract features of the same shape even when regions of interest have different shapes.
英語のヒント
たとえば、各領域の出力の高さと幅をそれぞれh2とw2と指定しよう。形状h×wの任意の注目領域の窓について、この窓はh2×w2の格子の部分窓に分けられ、各部分窓の形状はおよそ(h/h2)×(w/w2)である。実際には、どの部分窓の高さと幅も切り上げられ、最大の要素がその部分窓の出力として使われる。したがって、注目領域プーリング層は、注目領域の形状が異なっていても、同じ形状の特徴を抽出できる。
As an illustrative example, in Fig. 14.8.3, the upper-left 3×3 region of interest is selected on a 4×4 input. For this region of interest, we use a 2×2 region of interest pooling layer to obtain a 2×2 output. Note that each of the four divided subwindows contains elements 0, 1, 4, and 5 (5 is the maximum); 2 and 6 (6 is the maximum); 8 and 9 (9 is the maximum); and 10.
英語のヒント
例として、図14.8.3では、4×4の入力の上で左上の3×3の注目領域が選ばれている。この注目領域について、2×2の注目領域プーリング層を使って2×2の出力を得る。四つに分けた部分窓には、それぞれ要素0、1、4、5(5が最大)、2と6(6が最大)、8と9(9が最大)、そして10が含まれることに注意してほしい。
Fig. 14.8.3図14.8.3
A 2×2 region of interest pooling layer.
英語のヒント
2×2の注目領域プーリング層。
Below we demonstrate the computation of the region of interest pooling layer. Suppose that the height and width of the CNN-extracted features X are both 4, and there is only a single channel.
英語のヒント
下では、注目領域プーリング層の計算を示す。CNNで抽出した特徴Xの高さと幅はどちらも4で、チャネルは一つだけだとする。
import torch
import torchvision

X = torch.arange(16.).reshape(1, 1, 4, 4)
X
tensor([[[[ 0.,  1.,  2.,  3.],
          [ 4.,  5.,  6.,  7.],
          [ 8.,  9., 10., 11.],
          [12., 13., 14., 15.]]]])
Let’s further suppose that the height and width of the input image are both 40 pixels and that selective search generates two region proposals on this image. Each region proposal is expressed as five elements: its object class followed by the (x,y)-coordinates of its upper-left and lower-right corners.
英語のヒント
さらに、入力画像の高さと幅はどちらも40画素で、選択的探索がこの画像上に二つの領域候補を生成するとしよう。各領域候補は五つの要素で表される。物体のクラスと、それに続く左上と右下の角の(x,y)座標である。
rois = torch.Tensor([[0, 0, 0, 20, 20], [0, 0, 10, 30, 30]])
Because the height and width of X are 1/10 of the height and width of the input image, the coordinates of the two region proposals are multiplied by 0.1 according to the specified spatial_scale argument. Then the two regions of interest are marked on X as X[:, :, 0:3, 0:3] and X[:, :, 1:4, 0:4], respectively. Finally in the 2×2 region of interest pooling, each region of interest is divided into a grid of sub-windows to further extract features of the same shape 2×2.
英語のヒント
Xの高さと幅は入力画像の高さと幅の1/10なので、指定したspatial_scale引数に従って、二つの領域候補の座標に0.1を掛ける。すると、二つの注目領域はXの上でそれぞれX[:, :, 0:3, 0:3]とX[:, :, 1:4, 0:4]として示される。最後に、2×2の注目領域プーリングで、各注目領域は部分窓の格子に分けられ、同じ形状2×2の特徴がさらに抽出される。
torchvision.ops.roi_pool(X, rois, output_size=(2, 2), spatial_scale=0.1)
tensor([[[[ 5.,  6.],
          [ 9., 10.]]],


        [[[ 9., 11.],
          [13., 15.]]]])