# Probabilistic Ship Detection and Classification Using Deep Learning
## 4 Probabilistic Ship Detection and Classification in a Sequence of Images  
In this section, \(B^{1:T}=\big{\{}B^{1},B^{2},\ldots,B^{t},\ldots,B^{T}\big{\}}\) is a sequence of the bounding boxes predicted by the Faster R-CNN, where \(B^{t}\) is the bounding box detected at time \(t\). We determine the class of the bounding box sequence \(B^{1:T}\) using maximum _a posteriori_ (MAP). That is, the class of the sequence of the bounding boxes is predicted by:  
\[class(B^{1:T})=\underset{k=1,\sim,C}{\text{argmax}}p(\omega=k|B^{1:T}) \tag{8}\]  
Assuming that \(t\) denotes the current time, we can rewrite Equation (8) as:  
\[p\Big{(}\omega=k|B^{1:t}\Big{)}=p(\omega=k|B^{t},B^{1:t-1}), \tag{9}\]  
where \(B^{1:t}\) is divided into the current measurement \(B^{t}\) and all the previous measurements are \(B^{1:t-1}\). Using the Bayes rule, Equation (9) can be rewritten as:  
\[p\Big{(}\omega=k|B^{1:t}\Big{)}=p(\omega=k|B^{t},B^{1:t-1})=\frac{p\big{(}B^{t }|\omega=k,B^{1:t-1}\big{)}p\big{(}\omega=k|B^{1:t-1}\big{)}}{p(B^{t}|B^{1:t- 1})}. \tag{10}\]  
Since the current measurement \(B^{t}\) is not affected by previous measurements \(B^{1:t-1}\) conditioned on \(\omega=k\), we obtain \(p\big{(}B^{t}|\omega=k,B^{1:t-1}\big{)}=p\big{(}B^{t}|\omega=k\big{)}\), and Equation (10) can be simplified as:  
\[p\Big{(}\omega=k|B^{1:t}\Big{)}=\frac{p\big{(}B^{t}|\omega=k\big{)}p\big{(} \omega=k|B^{1:t-1}\big{)}}{p(B^{t}|B^{1:t-1})}. \tag{11}\]  
Substituting the Bayes rule  
\[p\big{(}B^{t}|\omega=k\big{)}=\frac{p\big{(}\omega=k|B^{t}\big{)}p\big{(}B^{t }\big{)}}{p(\omega=k)} \tag{12}\]  
into Equation (11) yields:  
\[p\Big{(}\omega=k|B^{1:t}\Big{)}=\frac{p\big{(}\omega=k|B^{t}\big{)}p(B^{t})}{p (\omega=k)}\frac{p\big{(}\omega=k|B^{1:t-1}\big{)}}{p(B^{t}|B^{1:t-1})} \tag{13}\]  
Furthermore, we define the class confidence of a sequence of bounding boxes from the Faster R-CNN with:  
\[p(\omega=k|B^{1:t})\triangleq f^{t}_{k},\text{ where }\sum_{k=1}^{C}f^{t}_{k}=1 \tag{14}\]  
Figure 4: Initial bounding box selection in the first frame.  
```
Step 1: At frame 1, initialize the target ship-bounding box \(B^{1}=\underset{B^{1}_{r}\in\{B^{1}_{1},\ldots,B^{1}_{k}\}}{\operatorname{argmax}}\;p( \omega=k|B^{1}_{r})\) \(k=1,\cdots,C-1\) \(f^{1}_{k}=p^{1}_{k}=p(\omega=k|B^{1})\) \(f^{0}_{k}=1/C\;\;for\;\forall k\) Step 2: For a given image at frame \(t>1\), update the bounding boxes \(\underset{B^{t}\in\{B^{1}_{r},\ldots,B^{t}_{k}\}}{\operatorname{argmax}}\; IoU(B^{t}_{r},B^{1-1})\geq\epsilon_{thd}\), \(B^{t}=\underset{B^{t}\in\{B^{t}_{1},\ldots,B^{t}_{k}\}}{\operatorname{argmax}}\; IoU(B^{t}_{r},B^{t-1})\) \(p^{t}_{k}=p(\omega=k|B^{t})\) else \(B^{t}=B^{t-1}+\delta B\) \(p^{t}_{k}=\left\{\begin{array}{ll}0.9&\;\;for\;\;k=C\;(background)\\ 0.1/(C-1)&\;\;otherwise\end{array}\right.\)  End Step 3: Evaluate the class of a sequence of bounding boxes recursively by \(\rho^{t}_{k}=\sum\limits_{k=1}^{C}\frac{p^{t}_{k},f^{t-1}_{k},f^{0}_{k}}{p^{t} _{k},f^{t-1}_{k},f^{0}_{k}}\) \(f^{t}_{k}=\frac{1}{\rho^{t}_{k}}\) Step 4: Determine the class at frame \(t\) using \(\underset{k=1,\ldots,C}{\operatorname{argmax}}f^{t}_{k}\) Step 5: For every next frame, repeat Steps 2, 3, and 4.
```  
**Algorithm 1**Probabilistic ship detection and classification from video.