Siamese neural network explained

A Siamese neural network (sometimes called a twin neural network) is an artificial neural network that uses the same weights while working in tandem on two different input vectors to compute comparable output vectors.[1] [2] [3] Often one of the output vectors is precomputed, thus forming a baseline against which the other output vector is compared. This is similar to comparing fingerprints but can be described more technically as a distance function for locality-sensitive hashing.

It is possible to build an architecture that is functionally similar to a twin network but implements a slightly different function. This is typically used for comparing similar instances in different type sets.

Uses of similarity measures where a twin network might be used are such things as recognizing handwritten checks, automatic detection of faces in camera images, and matching queries with indexed documents. The perhaps most well-known application of twin networks are face recognition, where known images of people are precomputed and compared to an image from a turnstile or similar. It is not obvious at first, but there are two slightly different problems. One is recognizing a person among a large number of other persons, that is the facial recognition problem. DeepFace is an example of such a system. In its most extreme form this is recognizing a single person at a train station or airport. The other is face verification, that is to verify whether the photo in a pass is the same as the person claiming he or she is the same person. The twin network might be the same, but the implementation can be quite different.

Learning

Learning in twin networks can be done with triplet loss or contrastive loss. For learning by triplet loss a baseline vector (anchor image) is compared against a positive vector (truthy image) and a negative vector (falsy image). The negative vector will force learning in the network, while the positive vector will act like a regularizer. For learning by contrastive loss there must be a weight decay to regularize the weights, or some similar operation like a normalization.

A distance metric for a loss function may have the following properties[4]

\delta(x,y)\ge0

\delta(x,y)=0\iffx=y

\delta(x,y)=\delta(y,x)

\delta(x,z)\le\delta(x,y)+\delta(y,z)

In particular, the triplet loss algorithm is often defined with squared Euclidean (which unlike Euclidean, does not have triangle inequality) distance at its core.

Predefined metrics, Euclidean distance metric

The common learning goal is to minimize a distance metric for similar objects and maximize for distinct ones. This gives a loss function like

\begin{align} \delta(x(i),x(j))= \begin{cases} min\|\operatorname{f}\left(x(i)\right)-\operatorname{f}\left(x(j)\right)\|,i=j\\ max\|\operatorname{f}\left(x(i)\right)-\operatorname{f}\left(x(j)\right)\|,ij \end{cases} \end{align}

i,j

are indexes into a set of vectors

\operatorname{f}()

function implemented by the twin network

The most common distance metric used is Euclidean distance, in case of which the loss function can be rewritten in matrix form as

\operatorname{\delta}(x(i),x(j))(x(i)-x(j))T(x(i)-x(j))

Learned metrics, nonlinear distance metric

A more general case is where the output vector from the twin network is passed through additional network layers implementing non-linear distance metrics.

\begin{align} ifi=jthen&\operatorname{\delta}\left[\operatorname{f}\left(x(i)\right),\operatorname{f}\left(x(j)\right)\right]issmall\\ otherwise&\operatorname{\delta}\left[\operatorname{f}\left(x(i)\right),\operatorname{f}\left(x(j)\right)\right]islarge \end{align}

i,j

are indexes into a set of vectors

\operatorname{f}()

function implemented by the twin network

\operatorname{\delta}()

function implemented by the network joining outputs from the twin network

On a matrix form the previous is often approximated as a Mahalanobis distance for a linear space as[5]

\operatorname{\delta}(x(i),x(j))(x(i)-x(j))TM(x(i)-x(j))

This can be further subdivided in at least Unsupervised learning and Supervised learning.

Learned metrics, half-twin networks

This form also allows the twin network to be more of a half-twin, implementing a slightly different functions

\begin{align} ifi=jthen&\operatorname{\delta}\left[\operatorname{f}\left(x(i)\right),\operatorname{g}\left(x(j)\right)\right]issmall\\ otherwise&\operatorname{\delta}\left[\operatorname{f}\left(x(i)\right),\operatorname{g}\left(x(j)\right)\right]islarge \end{align}

i,j

are indexes into a set of vectors

\operatorname{f}(),\operatorname{g}()

function implemented by the half-twin network

\operatorname{\delta}()

function implemented by the network joining outputs from the twin network

Twin networks for object tracking

Twin networks have been used in object tracking because of its unique two tandem inputs and similarity measurement. In object tracking, one input of the twin network is user pre-selected exemplar image, the other input is a larger search image, which twin network's job is to locate exemplar inside of search image. By measuring the similarity between exemplar and each part of the search image, a map of similarity score can be given by the twin network. Furthermore, using a Fully Convolutional Network, the process of computing each sector's similarity score can be replaced with only one cross correlation layer.[6]

After being first introduced in 2016, Twin fully convolutional network has been used in many High-performance Real-time Object Tracking Neural Networks. Like CFnet,[7] StructSiam,[8] SiamFC-tri,[9] DSiam,[10] SA-Siam,[11] SiamRPN,[12] DaSiamRPN,[13] Cascaded SiamRPN,[14] SiamMask,[15] SiamRPN++,[16] Deeper and Wider SiamRPN.[17]

See also

References

  1. Bromley. Jane. Guyon. Isabelle. LeCun. Yann. Säckinger. Eduard. Shah. Roopak. 1994. Signature verification using a "Siamese" time delay neural network. Advances in Neural Information Processing Systems . 6. 737–744.
  2. Book: Chopra. S.. Hadsell. R.. LeCun. Y.. 2005 IEEE Computer Society Conference on Computer Vision and Pattern Recognition (CVPR'05) . Learning a Similarity Metric Discriminatively, with Application to Face Verification . June 2005. 1. 539–546 vol. 1. 10.1109/CVPR.2005.202. 0-7695-2372-2. 5555257.
  3. Book: Taigman. Y.. Yang. M.. Ranzato. M.. Wolf. L.. 2014 IEEE Conference on Computer Vision and Pattern Recognition . DeepFace: Closing the Gap to Human-Level Performance in Face Verification . June 2014. 1701–1708. 10.1109/CVPR.2014.220. 978-1-4799-5118-5. 2814088.
  4. Web site: Similarity Learning with (or without) Convolutional Neural Network. Chatterjee. Moitreya. Luo. Yunan. 2018-12-07.
  5. Chandra. M.P.. 1936. On the generalized distance in statistics. Proceedings of the National Institute of Sciences of India. 1. 2. 49–55.
  6. Fully-Convolutional Siamese Networks for Object Tracking
  7. Web site: End-to-end representation learning for Correlation Filter based tracking.
  8. Web site: Structured Siamese Network for Real-Time Visual Tracking.
  9. Web site: Triplet Loss in Siamese Network for Object Tracking.
  10. Web site: Learning Dynamic Siamese Network for Visual Object Tracking.
  11. Web site: A Twofold Siamese Network for Real-Time Object Tracking.
  12. Web site: High Performance Visual Tracking with Siamese Region Proposal Network.
  13. Distractor-aware Siamese Networks for Visual Object Tracking. 1808.06048. Zhu. Zheng. Wang. Qiang. Li. Bo. Wu. Wei. Yan. Junjie. Hu. Weiming. cs.CV. 2018.
  14. Siamese Cascaded Region Proposal Networks for Real-Time Visual Tracking. 1812.06148. Fan. Heng. Ling. Haibin. cs.CV. 2018.
  15. Fast Online Object Tracking and Segmentation: A Unifying Approach. 1812.05050. Wang. Qiang. Zhang. Li. Bertinetto. Luca. Hu. Weiming. Torr. Philip H. S.. cs.CV. 2018.
  16. SiamRPN++: Evolution of Siamese Visual Tracking with Very Deep Networks. 1812.11703. Li. Bo. Wu. Wei. Wang. Qiang. Zhang. Fangyi. Xing. Junliang. Yan. Junjie. cs.CV. 2018.
  17. Deeper and Wider Siamese Networks for Real-Time Visual Tracking. 1901.01660. Zhang. Zhipeng. Peng. Houwen. cs.CV. 2019.