# Instance Segmentation with Cosine Embeddings

##### Posted on Apr 25, 2021 (Update: May 24, 2021) 0 Comments

The instance segmentation is more difficult than semantic segmentation, since it does not only assign class labels to pixels, but also distinguishes between instances within each class.

Many methods for instance segmentation have in common that they solely segment one instance at a time. It can be problematic when hundreds of instances are visible in the image.

Recent methods are segmenting each instance simultaneously, by predicting embeddings for all pixels at once. These embeddings have similar values within an instance, but differ among instances. The paper proposes to use recurrent fully convolutional networks for embedding-based instance segementation and tracking, and integrate convolutional gated recurrent units (ConvGRU) into a stacked hourglass network to memorize temporal information.

## Recurrent Stacked Hourglass Network

The paper modifies the stacked hourglass architecture by integrating ConvGRU to propagate temporal information, as shown in the following figure, The hourglass network is similar to the U-Net, i.e., it consists of convolution layers in a contracting and an expanding path for multiple levels, but it additionally introduces convolution layers in the split connections as a parallel path.

The paper exchnage these convolution layers by ConvGRUs, which allow to propagate temporal video information within a fully convolutional network architecture. Each of the ConvGRUs has its own internal state $s_t$ at timestamp $t$, which has a size that is equal to the size of its input.

For $t=0$ the state $s_t$ is initialized with zeros. Based on its current input and current value, the internal state $s_t$ is updated to the new state $s_{t+1}$ after each timestamp. Thus, by consecutively providing the recurrent stacked hourglass network (RSHN) with individual frames, information from previous frames is encoded in the current state and propagated to the next frame.

## Cosine Embedding Loss

Let the network predict a $d$-dimensional embedding vector $e_p\in \IR^d$ for each pixel $p$ of the image. To separate instances $i\in I$,

• firstly, embeddings of pixels $p\in S^{(i)}$ belonging to the same instance $i$ need to be similar,
• secondly, embeddings of $S^{(i)}$ need to be dissimilar to embeddings of pixels $p\in S^{(j)}$ of other instances $j\neq i$.

Treat background as an independent instance. Following from the four color map theorem, only neighboring instances need to have different embeddings. Thus, relax the need of dissimilarity between different instances only to the neighboring ones, i.e., $N^{(i)} = \cup_j S^{(j)}$ for all instances $j\neq i$ within pixel-wise distance $r_N$ to instance $i$. This relaxation simplifies the problem by assigning only a limited number of different embeddings to a possibly large number of different instances.

Define the cosine embedding loss as

$L = \frac{1}{\vert I\vert}\sum_{i\in I}\left(1-\frac{1}{\vert S^{(i)}\vert}\sum_{p\in S^{(i)}}\cos(\bar e^{(i)}, e_p)\right) + \left(\frac{1}{\vert N^{(i)}\vert}\sum_{p\in N^{(i)}}\cos(\bar e^{(i)}, e_p)^2\right)\,.$

By minimizing $L$,

• the first term urges $e_p$ of pixels $p\in S^{(i)}$ to have the same direction as the mean $\bar e^{(i)}$
• the second term pushes $e_p$ of pixels $p\in N^{(i)}$ to be orthogonal to the mean $\bar e^{(i)}$

## Clustering of Embeddings

Since the number of instances is not known, the paper performs grouping with the clustering algorithm HDBSCAN that estimates the number of clusters automatically.

Two parameters for HDBSCAN:

• minimal points $m_{pts}$
• minimal cluster size $m_{clSize}$

To simplify clustering and still be able to detect splitting of instances, cluster only overlapping pairs of consecutive frames at a time. (??)

Note that the embedding loss allows same embeddings for different instances that are far apart, the paper use both image coordinates and value of the embeddings as data points for the clustering algorithm.

Identify same instances by the highest intersection over union (IoU) between each segmented instance in the overlapping frame.

Published in categories Note
{"ft_lang_label":"__label__en","ft_lang_prob":0.8500423,"math_prob":0.9937131,"size":4317,"snap":"2023-40-2023-50","text_gpt3_token_len":1026,"char_repetition_ratio":0.13540459,"word_repetition_ratio":0.0,"special_character_ratio":0.22863099,"punctuation_ratio":0.103896104,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9980146,"pos_list":[0,1,2,3,4,5,6,7,8],"im_url_duplicate_count":[null,2,null,2,null,2,null,2,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-12-05T18:14:27Z\",\"WARC-Record-ID\":\"<urn:uuid:03762314-47d8-421e-bf45-15f083127215>\",\"Content-Length\":\"12022\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:3f4bd7b3-be1e-4aed-83ff-eee208bfe9b0>\",\"WARC-Concurrent-To\":\"<urn:uuid:e13655e7-6ceb-4540-b481-a7256ef9c4eb>\",\"WARC-IP-Address\":\"185.199.111.153\",\"WARC-Target-URI\":\"https://stats.hohoweiya.xyz/2021/04/25/instance-segmentation-and-tracking/\",\"WARC-Payload-Digest\":\"sha1:FE6R32BVWE66FS5X5LSJD6AIWRTWJYOT\",\"WARC-Block-Digest\":\"sha1:7DKYAOGD5LLHFVJOKJT5EWEUGG4HO6J4\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-50/CC-MAIN-2023-50_segments_1700679100555.27_warc_CC-MAIN-20231205172745-20231205202745-00042.warc.gz\"}"}