1
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?

DPT(Dense Prediction Transformer)の論文と実装の確認

Last updated at Posted at 2025-09-10

当記事ではピクセル単位での予測(Dense Predictionタスク)にViTを用いた研究であるDPT(Dense Prediction Transformer)の論文とPyTorch実装の確認を行います。

DPTの論文

概要

DPT_1.png
DPT論文 Figure.1

VGGT(Visual Geometry Grounded Transformer)では上図のように複数の画像(上図の左)から3DのPointmap(上図の中央)を構築し、ピクセルマッチング(上図の右の左側)や深度推定(上図の右の右側)などに活用します。

DPTの処理の流れ

DPT_1.png
DPT論文 Figure.1

DPTの処理の流れの大枠は上図より確認することができます。詳しい処理については以下で確認します。

Transformer Encoder

Transformerに基づくEncoderではまずEmbedding処理を行うことで下記のようなテンソルを取得します。

\begin{align}
t^0 &= \{ t_0^0, \cdots , t_{N_p}^0 \} \\
t_n^0 & \in \mathbb{R}^{D} \\
N_p &= \frac{WH}{p^{2}}
\end{align}

上記の$t^0$の$0$はTransformerの$0$層(入力)であると解釈すると良いです。$p$はパッチサイズでありDPTではオリジナルのViTと同様に$p=16$が用いられます。

また、DPT論文では下記のような3種類のネットワーク構造を用いて検証が行われている点も合わせて抑えておくと良いです。

ネットワークの名称 実行される処理
ViT-Base patch-based Embedding + 12層のTransformer
ViT-Large patch-based Embedding + 24層のTransformer
ViT-Hybrid ResNet50を用いたEmbedding + 12層のTransformer

Convolutional Decoder

\begin{align}
\mathrm{Reassemble}_{s}^{\hat{D}}(t) = (\mathrm{Resample}_{s} \circ \mathrm{Concatenate} \circ \mathrm{Read})(t)
\end{align}

Convolutional Decoderでは上記のような3段階の処理が行われます。以下、それぞれについて詳しく確認します。

\begin{align}
\mathrm{Read}: \, \mathbb{R}^{(N_p + 1) \times D} \longrightarrow \mathbb{R}^{N_p \times D}
\end{align}

まず$\mathrm{Read}$では上記のようにトークンの数を$N_{p}+1$個から$N_{p}$個に減らす処理を行います(ViTなどではパッチに基づくトークン以外にもう1つトークンを持つように実装されている)。実装方法は様々ですが、たとえば下記の3通りの方法などが挙げられます。

\begin{align}
\mathrm{Read}_{\mathrm{ingore}}(t) &= \{ t_1, \cdots , t_{N_p} \} \\
\mathrm{Read}_{\mathrm{add}}(t) &= \{ t_1+t_0, \cdots , t_{N_p}+t_0 \} \\
\mathrm{Read}_{\mathrm{proj}}(t) &= \{ \mathrm{MLP}(\mathrm{concat}(t_1,t_0)), \cdots , \mathrm{MLP}(\mathrm{concat}(t_{N_p},t_0)) \}
\end{align}

上記はそれぞれ「$t_0$の特徴量を用いない(ignore)」、「他のトークンに加える(add)」、「concatで連結した後にMLPで元の次元に戻す(proj)」のように理解すると良いです。

次に$\mathrm{Concatenate}$ではTransformerの1Dのトークンを画像に対応するように2Dに配置します。

\begin{align}
\mathrm{Concatenate} &: \, \mathbb{R}^{N_p \times D} \longrightarrow \mathbb{R}^{\frac{W}{p} \times \frac{H}{p} \times D} \\
N^{p} &= \frac{WH}{p^2}
\end{align}

$\mathrm{Resample}$処理では$1 \times 1$畳み込みによってチャネルの数を$D \rightarrow \hat{D}$に変えた後にリサンプリングを行います。

\begin{align}
\mathrm{Resample}_s & : \, \mathbb{R}^{\frac{W}{p} \times \frac{H}{p} \times D} \longrightarrow \mathbb{R}^{\frac{W}{s} \times \frac{H}{s} \times \hat{D}} \\
\hat{D} &= 256 \qquad \mathrm{(Default} \, \mathrm{Architecture)}
\end{align}

上記のような処理を行うことで複数の解像度の特徴マップを構築することができます。また、下記の表では3種類のDPTにおけるReassemble処理を行うViTのlayerについてまとめました。

ネットワークの名称 Reassemble処理を行うViTのlayer
DPT-Base 5, 12, 18, 24
DPT-Large 3, 6, 9, 12
DPT-Hybrid 9, 12

DPTの実装

1
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
1
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?