第14章コンピュータビジョン
14.7.5. Exercises14.7.5 練習問題
- Can you improve the single-shot multibox detection by improving the loss function? For example, replace norm loss with smooth norm loss for the predicted offsets. This loss function uses a square function around zero for smoothness, which is controlled by the hyperparameter :
英語のヒント
損失関数を改良して、シングルショット・マルチボックス検出を改善できるか。たとえば、予測したオフセットについて、ノルム損失をなめらかなノルム損失に置き換えよ。この損失関数は、なめらかさのためにゼロの近くで2乗関数を使い、それはハイパーパラメータで制御される。式は次のとおりである。
(14.7.1)
When is very large, this loss is similar to the norm loss. When its value is smaller, the loss function is smoother.
英語のヒント
がとても大きいとき、この損失はノルム損失に似ている。その値が小さいほど、損失関数はなめらかになる。
def smooth_l1(data, scalar):
out = []
for i in data:
if abs(i) < 1 / (scalar ** 2):
out.append(((scalar * i) ** 2) / 2)
else:
out.append(abs(i) - 0.5 / (scalar ** 2))
return torch.tensor(out)
sigmas = [10, 1, 0.5]
lines = ['-', '--', '-.']
x = torch.arange(-2, 2, 0.1)
d2l.set_figsize()
for l, s in zip(lines, sigmas):
y = smooth_l1(x, scalar=s)
d2l.plt.plot(x, y, l, label='sigma=%.1f' % s)
d2l.plt.legend();Besides, in the experiment we used cross-entropy loss for class prediction: denoting by the predicted probability for the ground-truth class , the cross-entropy loss is . We can also use the focal loss (Lin et al., 2017): given hyperparameters and , this loss is defined as:
英語のヒント
さらに、実験ではクラスの予測に交差エントロピー損失を使った。正解のクラスについて予測した確率をで表すと、交差エントロピー損失はである。焦点損失(Lin et al., 2017)を使うこともできる。ハイパーパラメータとが与えられたとき、この損失は次のように定義される。
(14.7.2)
As we can see, increasing can effectively reduce the relative loss for well-classified examples (e.g., ) so the training can focus more on those difficult examples that are misclassified.
英語のヒント
見てのとおり、を大きくすると、よく分類された事例(たとえば)についての相対的な損失を効果的に減らせるので、訓練は誤分類されている難しい事例にもっと集中できる。
def focal_loss(gamma, x):
return -(1 - x) ** gamma * torch.log(x)
x = torch.arange(0.01, 1, 0.01)
for l, gamma in zip(lines, [0, 1, 5]):
y = d2l.plt.plot(x, focal_loss(gamma, x), l, label='gamma=%.1f' % gamma)
d2l.plt.legend();- Due to space limitations, we have omitted some implementation details of the single shot multibox detection model in this section. Can you further improve the model in the following aspects:
英語のヒント
紙幅の都合で、この節ではシングルショット・マルチボックス検出のモデルの実装の詳細をいくつか省いた。次の点で、モデルをさらに改善できるか。- When an object is much smaller compared with the image, the model could resize the input image bigger.
英語のヒント
物体が画像に比べてずっと小さいときは、モデルは入力画像を大きくすることができる。 - There are typically a vast number of negative anchor boxes. To make the class distribution more balanced, we could downsample negative anchor boxes.
英語のヒント
ふつう、負のアンカーボックスは膨大にある。クラスの分布をもっと釣り合ったものにするため、負のアンカーボックスをダウンサンプリングできる。 - In the loss function, assign different weight hyperparameters to the class loss and the offset loss.
英語のヒント
損失関数で、クラスの損失とオフセットの損失に異なる重みのハイパーパラメータを割り当てよ。 - Use other methods to evaluate the object detection model, such as those in the single shot multibox detection paper (Liu et al., 2016).
英語のヒント
シングルショット・マルチボックス検出の論文(Liu et al., 2016)にあるもののような、ほかの方法を使って物体検出のモデルを評価せよ。