Grid Mapping: From Occupancy Map to Semantic Map

Binary Bayes Filters

Suppose a cell has a binary state that does not change over time, e.g. occupancy state, the belief of state can be described as:

$$ \begin{align} bel_t(x) =& p(x| z_{1, \cdots, t}) \end{align} $$

The state is chosen from two: $x$ and $\neg x$, where $bel_t(x) + bel_t(\neg x) = 1$.

Recursive Estimation

$$ \begin{align} bel_t(x) =& p(x| z_{1, \cdots, t}) \\ =& \frac{p(z_t | x, z_{1, \cdots, t-1})p(x|z_{1, \cdots, t-1})}{p(z_t | z_{1, \cdots, t-1})} \\ =& \frac{p(z_t | x)bel_{t-1}(x)}{p(z_t | z_{1, \cdots, t-1})} \\ bel_t(\neg x) =& p(\neg x| z_{1, \cdots, t}) \\ =& \frac{p(z_t | \neg x)bel_{t-1}(\neg x)}{p(z_t | z_{1, \cdots, t-1})} \\ \end{align} $$

Then we can get:

$$ \begin{align} \frac{bel_t(x)}{bel_t(\neg x)} =& \frac{p(z_t | x)bel_{t-1}(x)}{p(z_t | \neg x)bel_{t-1}(\neg x)} \end{align} $$

Normally, we will use log-based update:

$$ \begin{align} ln(\frac{bel_t(x)}{bel_t(\neg x)}) =& ln(\frac{p(z_t | x)bel_{t-1}(x)}{p(z_t | \neg x)bel_{t-1}(\neg x)})\\ l_t =& l_{t-1} + ln(\frac{p(z_t | x)}{p(z_t | \neg x)}) \end{align} $$

where $bel_t(x) = 1 - \frac{1}{1+e^{l_t}}$

We call $p(z_t | x)$ as forward model as it calculate the likelihood distribution. However, sometimes, it is hard to get the the likelihood distribution over distributions, e.g. measurement is an image. In such case, it is much easier to get the inverse model , aka $p(x | z_t$). Then we will have:

$$ \begin{align} ln(\frac{bel_t(x)}{bel_t(\neg x)}) =& ln(\frac{p(z_t | x)bel_{t-1}(x)}{p(z_t | \neg x)bel_{t-1}(\neg x)})\\ l_t =& l_{t-1} + ln(\frac{p(x|z_t)p(\neg x_0)}{p(\neg x|z_t)p(x_0)}) \\ l_t =& l_{t-1} - l_0 + ln(\frac{p(x|z_t)}{1- p(x|z_t)}) \end{align} $$
In [71]:
observations: ['occupied', 'empty', 'occupied', 'occupied', 'occupied', 'empty', 'occupied', 'empty', 'occupied', 'empty']

Beta Distribution as Conjugate Prior

Dirichlet distribution is the conjugate prior for the Categorical distribution. For the binary case, Dirichlet distribution is a Beta distribution . We can track the posterior distribution use a Beta distribution.

In [51]:

Occupancy Grid Map

Occupancy grid map is an idea that extends from a single cell to many cells and considers cell states are independent:

$$ p(m | z_{1:t}, x_{1:t}) = \prod p(m_i | z_{1:t}, x_{1:t}) $$$$ \begin{align} l_t =& l_{t-1} - l_0 + ln(\frac{p(m_i|z_t)}{1- p(m_i|z_t)}) \end{align} $$

Semantic Map

Occupancy grid map only consider binary states in a cell, whereas semantic map maintains a categorical distribution in a cell.

Recursive Estimation with Histogram Filters

For forward model: $$ \begin{align} bel_t(x) =& p(x| z_{1, \cdots, t}) \\ =& \frac{p(z_t | x, z_{1, \cdots, t-1})p(x|z_{1, \cdots, t-1})}{p(z_t | z_{1, \cdots, t-1})} \\ =& \frac{p(z_t | x)bel_{t-1}(x)}{p(z_t | z_{1, \cdots, t-1})} \\ \propto& p(z_t | x)bel_{t-1}(x) \\ \end{align} $$

For inverse model: $$ \begin{align} bel_t(x) =& p(x| z_{1, \cdots, t}) \\ =& \frac{p(x| z_t)p(z_t)bel_{t-1}(x)}{p(z_t | z_{1, \cdots, t-1})p(x_0)} \\ \propto& \frac{p(x | z_t)bel_{t-1}(x)}{p(x)} \\ \end{align} $$

Since state $x$ can take multiple values for semantic mapping, we will use a histogram to track the categorical distribution in a cell. The table below shows one example using forward model.

state:r state:g state:b
obs: r 0.7 0.1 0.1
obs: g 0.2 0.7 0.1
obs: b 0.1 0.2 0.8
In [93]:
GT: r:0.2, g:0.2, b:0.6
Observations: [2, 2, 0, 2, 1, 0, 1, 0, 2, 2]
Estimation: r:0.03, g:0.03, b:0.94

Dirichlet Distribution as Conjugate Prior

Dirichlet distribution is the conjugate prior for the Categorical distribution. The example below shows the MAP of the categorical distribution for a single cell.

In [55]:
GT: r:0.2, g:0.3, b:0.5
Estimation: r:0.20, g:0.30, b:0.50

The example below shows the MAP of the categorical distribution for lane estimation.

In [56]:
(70, 100, 3)
Out[56]:
<matplotlib.image.AxesImage at 0x13a9b0f10>
In [58]:
Aggregated observations
Out[58]:
<matplotlib.image.AxesImage at 0x13abc0f10>
In [63]:
Segmentation map without kernel smoothing
In [60]:
In [62]:
Segmentation map with sparse kernel smoothing

Reference:

  • Lu, Bayesian Spatial Kernel Smoothing for Scalable Dense Semantic Mapping
  • Thrun, Probabilistic Robotics
  • Tu, The Dirichlet-Multinomial and Dirichlet-Categorical models for Bayesian inference
This blog is converted from grid-mapping.ipynb
Written on May 25, 2021