|
<html><head><title>dlib C++ Library - dnn_instance_segmentation_ex.h</title></head><body bgcolor='white'><pre> |
|
<font color='#009900'>// The contents of this file are in the public domain. See LICENSE_FOR_EXAMPLE_PROGRAMS.txt |
|
</font><font color='#009900'>/* |
|
Instance segmentation using the PASCAL VOC2012 dataset. |
|
|
|
Instance segmentation sort-of combines object detection with semantic |
|
segmentation. While each dog, for example, is detected separately, |
|
the output is not only a bounding-box but a more accurate, per-pixel |
|
mask. |
|
|
|
For introductions to object detection and semantic segmentation, you |
|
can have a look at dnn_mmod_ex.cpp and dnn_semantic_segmentation.h, |
|
respectively. |
|
|
|
Instructions how to run the example: |
|
1. Download the PASCAL VOC2012 data, and untar it somewhere. |
|
http://host.robots.ox.ac.uk/pascal/VOC/voc2012/VOCtrainval_11-May-2012.tar |
|
2. Build the dnn_instance_segmentation_train_ex example program. |
|
3. Run: |
|
./dnn_instance_segmentation_train_ex /path/to/VOC2012 |
|
4. Wait while the network is being trained. |
|
5. Build the dnn_instance_segmentation_ex example program. |
|
6. Run: |
|
./dnn_instance_segmentation_ex /path/to/VOC2012-or-other-images |
|
|
|
An alternative to steps 2-4 above is to download a pre-trained network |
|
from here: http://dlib.net/files/instance_segmentation_voc2012net_v2.dnn |
|
|
|
It would be a good idea to become familiar with dlib's DNN tooling before reading this |
|
example. So you should read dnn_introduction_ex.cpp and dnn_introduction2_ex.cpp |
|
before reading this example program. |
|
*/</font> |
|
|
|
<font color='#0000FF'>#ifndef</font> DLIB_DNn_INSTANCE_SEGMENTATION_EX_H_ |
|
<font color='#0000FF'>#define</font> DLIB_DNn_INSTANCE_SEGMENTATION_EX_H_ |
|
|
|
<font color='#0000FF'>#include</font> <font color='#5555FF'><</font>dlib<font color='#5555FF'>/</font>dnn.h<font color='#5555FF'>></font> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'>namespace</font> <b>{</b> |
|
<font color='#009900'>// Segmentation will be performed using patches having this size. |
|
</font> constexpr <font color='#0000FF'><u>int</u></font> seg_dim <font color='#5555FF'>=</font> <font color='#979000'>227</font>; |
|
<b>}</b> |
|
|
|
dlib::rectangle <b><a name='get_cropping_rect'></a>get_cropping_rect</b><font face='Lucida Console'>(</font><font color='#0000FF'>const</font> dlib::rectangle<font color='#5555FF'>&</font> rectangle<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font><font color='#5555FF'>!</font>rectangle.<font color='#BB00BB'>is_empty</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>; |
|
|
|
<font color='#0000FF'>const</font> <font color='#0000FF'>auto</font> center_point <font color='#5555FF'>=</font> dlib::<font color='#BB00BB'>center</font><font face='Lucida Console'>(</font>rectangle<font face='Lucida Console'>)</font>; |
|
<font color='#0000FF'>const</font> <font color='#0000FF'>auto</font> max_dim <font color='#5555FF'>=</font> std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>rectangle.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, rectangle.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>; |
|
<font color='#0000FF'>const</font> <font color='#0000FF'>auto</font> d <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'><</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>></font><font face='Lucida Console'>(</font>std::<font color='#BB00BB'>round</font><font face='Lucida Console'>(</font>max_dim <font color='#5555FF'>/</font> <font color='#979000'>2.0</font> <font color='#5555FF'>*</font> <font color='#979000'>1.5</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>; <font color='#009900'>// add +50% |
|
</font> |
|
<font color='#0000FF'>return</font> dlib::<font color='#BB00BB'>rectangle</font><font face='Lucida Console'>(</font> |
|
center_point.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> d, |
|
center_point.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> d, |
|
center_point.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> d, |
|
center_point.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> d |
|
<font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#009900'>// The object detection network. |
|
</font><font color='#009900'>// Adapted from dnn_mmod_train_find_cars_ex.cpp and friends. |
|
</font> |
|
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'><u>long</u></font> num_filters, <font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>></font> <font color='#0000FF'>using</font> con5d <font color='#5555FF'>=</font> dlib::con<font color='#5555FF'><</font>num_filters,<font color='#979000'>5</font>,<font color='#979000'>5</font>,<font color='#979000'>2</font>,<font color='#979000'>2</font>,SUBNET<font color='#5555FF'>></font>; |
|
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'><u>long</u></font> num_filters, <font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>></font> <font color='#0000FF'>using</font> con5 <font color='#5555FF'>=</font> dlib::con<font color='#5555FF'><</font>num_filters,<font color='#979000'>5</font>,<font color='#979000'>5</font>,<font color='#979000'>1</font>,<font color='#979000'>1</font>,SUBNET<font color='#5555FF'>></font>; |
|
|
|
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>></font> <font color='#0000FF'>using</font> bdownsampler <font color='#5555FF'>=</font> dlib::relu<font color='#5555FF'><</font>dlib::bn_con<font color='#5555FF'><</font>con5d<font color='#5555FF'><</font><font color='#979000'>128</font>,dlib::relu<font color='#5555FF'><</font>dlib::bn_con<font color='#5555FF'><</font>con5d<font color='#5555FF'><</font><font color='#979000'>128</font>,dlib::relu<font color='#5555FF'><</font>dlib::bn_con<font color='#5555FF'><</font>con5d<font color='#5555FF'><</font><font color='#979000'>32</font>,SUBNET<font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font>; |
|
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>></font> <font color='#0000FF'>using</font> adownsampler <font color='#5555FF'>=</font> dlib::relu<font color='#5555FF'><</font>dlib::affine<font color='#5555FF'><</font>con5d<font color='#5555FF'><</font><font color='#979000'>128</font>,dlib::relu<font color='#5555FF'><</font>dlib::affine<font color='#5555FF'><</font>con5d<font color='#5555FF'><</font><font color='#979000'>128</font>,dlib::relu<font color='#5555FF'><</font>dlib::affine<font color='#5555FF'><</font>con5d<font color='#5555FF'><</font><font color='#979000'>32</font>,SUBNET<font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font>; |
|
|
|
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>></font> <font color='#0000FF'>using</font> brcon5 <font color='#5555FF'>=</font> dlib::relu<font color='#5555FF'><</font>dlib::bn_con<font color='#5555FF'><</font>con5<font color='#5555FF'><</font><font color='#979000'>256</font>,SUBNET<font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font>; |
|
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>></font> <font color='#0000FF'>using</font> arcon5 <font color='#5555FF'>=</font> dlib::relu<font color='#5555FF'><</font>dlib::affine<font color='#5555FF'><</font>con5<font color='#5555FF'><</font><font color='#979000'>256</font>,SUBNET<font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font>; |
|
|
|
<font color='#0000FF'>using</font> det_bnet_type <font color='#5555FF'>=</font> dlib::loss_mmod<font color='#5555FF'><</font>dlib::con<font color='#5555FF'><</font><font color='#979000'>1</font>,<font color='#979000'>9</font>,<font color='#979000'>9</font>,<font color='#979000'>1</font>,<font color='#979000'>1</font>,brcon5<font color='#5555FF'><</font>brcon5<font color='#5555FF'><</font>brcon5<font color='#5555FF'><</font>bdownsampler<font color='#5555FF'><</font>dlib::input_rgb_image_pyramid<font color='#5555FF'><</font>dlib::pyramid_down<font color='#5555FF'><</font><font color='#979000'>6</font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font>; |
|
<font color='#0000FF'>using</font> det_anet_type <font color='#5555FF'>=</font> dlib::loss_mmod<font color='#5555FF'><</font>dlib::con<font color='#5555FF'><</font><font color='#979000'>1</font>,<font color='#979000'>9</font>,<font color='#979000'>9</font>,<font color='#979000'>1</font>,<font color='#979000'>1</font>,arcon5<font color='#5555FF'><</font>arcon5<font color='#5555FF'><</font>arcon5<font color='#5555FF'><</font>adownsampler<font color='#5555FF'><</font>dlib::input_rgb_image_pyramid<font color='#5555FF'><</font>dlib::pyramid_down<font color='#5555FF'><</font><font color='#979000'>6</font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font>; |
|
|
|
<font color='#009900'>// The segmentation network. |
|
</font><font color='#009900'>// For the time being, this is very much copy-paste from dnn_semantic_segmentation.h, although the network is made narrower (smaller feature maps). |
|
</font> |
|
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'><u>int</u></font> N, <font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'>typename</font><font color='#5555FF'>></font> <font color='#0000FF'>class</font> <b><a name='BN'></a>BN</b>, <font color='#0000FF'><u>int</u></font> stride, <font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>></font> |
|
<font color='#0000FF'>using</font> block <font color='#5555FF'>=</font> BN<font color='#5555FF'><</font>dlib::con<font color='#5555FF'><</font>N,<font color='#979000'>3</font>,<font color='#979000'>3</font>,<font color='#979000'>1</font>,<font color='#979000'>1</font>,dlib::relu<font color='#5555FF'><</font>BN<font color='#5555FF'><</font>dlib::con<font color='#5555FF'><</font>N,<font color='#979000'>3</font>,<font color='#979000'>3</font>,stride,stride,SUBNET<font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font>; |
|
|
|
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'><u>int</u></font> N, <font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'>typename</font><font color='#5555FF'>></font> <font color='#0000FF'>class</font> <b><a name='BN'></a>BN</b>, <font color='#0000FF'><u>int</u></font> stride, <font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>></font> |
|
<font color='#0000FF'>using</font> blockt <font color='#5555FF'>=</font> BN<font color='#5555FF'><</font>dlib::cont<font color='#5555FF'><</font>N,<font color='#979000'>3</font>,<font color='#979000'>3</font>,<font color='#979000'>1</font>,<font color='#979000'>1</font>,dlib::relu<font color='#5555FF'><</font>BN<font color='#5555FF'><</font>dlib::cont<font color='#5555FF'><</font>N,<font color='#979000'>3</font>,<font color='#979000'>3</font>,stride,stride,SUBNET<font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font>; |
|
|
|
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'><u>int</u></font>,<font color='#0000FF'>template</font><font color='#5555FF'><</font><font color='#0000FF'>typename</font><font color='#5555FF'>></font><font color='#0000FF'>class</font>,<font color='#0000FF'><u>int</u></font>,<font color='#0000FF'>typename</font><font color='#5555FF'>></font> <font color='#0000FF'>class</font> <b><a name='block'></a>block</b>, <font color='#0000FF'><u>int</u></font> N, <font color='#0000FF'>template</font><font color='#5555FF'><</font><font color='#0000FF'>typename</font><font color='#5555FF'>></font><font color='#0000FF'>class</font> <b><a name='BN'></a>BN</b>, <font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>></font> |
|
<font color='#0000FF'>using</font> residual <font color='#5555FF'>=</font> dlib::add_prev1<font color='#5555FF'><</font>block<font color='#5555FF'><</font>N,BN,<font color='#979000'>1</font>,dlib::tag1<font color='#5555FF'><</font>SUBNET<font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font>; |
|
|
|
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'><u>int</u></font>,<font color='#0000FF'>template</font><font color='#5555FF'><</font><font color='#0000FF'>typename</font><font color='#5555FF'>></font><font color='#0000FF'>class</font>,<font color='#0000FF'><u>int</u></font>,<font color='#0000FF'>typename</font><font color='#5555FF'>></font> <font color='#0000FF'>class</font> <b><a name='block'></a>block</b>, <font color='#0000FF'><u>int</u></font> N, <font color='#0000FF'>template</font><font color='#5555FF'><</font><font color='#0000FF'>typename</font><font color='#5555FF'>></font><font color='#0000FF'>class</font> <b><a name='BN'></a>BN</b>, <font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>></font> |
|
<font color='#0000FF'>using</font> residual_down <font color='#5555FF'>=</font> dlib::add_prev2<font color='#5555FF'><</font>dlib::avg_pool<font color='#5555FF'><</font><font color='#979000'>2</font>,<font color='#979000'>2</font>,<font color='#979000'>2</font>,<font color='#979000'>2</font>,dlib::skip1<font color='#5555FF'><</font>dlib::tag2<font color='#5555FF'><</font>block<font color='#5555FF'><</font>N,BN,<font color='#979000'>2</font>,dlib::tag1<font color='#5555FF'><</font>SUBNET<font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font>; |
|
|
|
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'><u>int</u></font>,<font color='#0000FF'>template</font><font color='#5555FF'><</font><font color='#0000FF'>typename</font><font color='#5555FF'>></font><font color='#0000FF'>class</font>,<font color='#0000FF'><u>int</u></font>,<font color='#0000FF'>typename</font><font color='#5555FF'>></font> <font color='#0000FF'>class</font> <b><a name='block'></a>block</b>, <font color='#0000FF'><u>int</u></font> N, <font color='#0000FF'>template</font><font color='#5555FF'><</font><font color='#0000FF'>typename</font><font color='#5555FF'>></font><font color='#0000FF'>class</font> <b><a name='BN'></a>BN</b>, <font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>></font> |
|
<font color='#0000FF'>using</font> residual_up <font color='#5555FF'>=</font> dlib::add_prev2<font color='#5555FF'><</font>dlib::cont<font color='#5555FF'><</font>N,<font color='#979000'>2</font>,<font color='#979000'>2</font>,<font color='#979000'>2</font>,<font color='#979000'>2</font>,dlib::skip1<font color='#5555FF'><</font>dlib::tag2<font color='#5555FF'><</font>blockt<font color='#5555FF'><</font>N,BN,<font color='#979000'>2</font>,dlib::tag1<font color='#5555FF'><</font>SUBNET<font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font>; |
|
|
|
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'><u>int</u></font> N, <font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>></font> <font color='#0000FF'>using</font> res <font color='#5555FF'>=</font> dlib::relu<font color='#5555FF'><</font>residual<font color='#5555FF'><</font>block,N,dlib::bn_con,SUBNET<font color='#5555FF'>></font><font color='#5555FF'>></font>; |
|
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'><u>int</u></font> N, <font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>></font> <font color='#0000FF'>using</font> ares <font color='#5555FF'>=</font> dlib::relu<font color='#5555FF'><</font>residual<font color='#5555FF'><</font>block,N,dlib::affine,SUBNET<font color='#5555FF'>></font><font color='#5555FF'>></font>; |
|
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'><u>int</u></font> N, <font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>></font> <font color='#0000FF'>using</font> res_down <font color='#5555FF'>=</font> dlib::relu<font color='#5555FF'><</font>residual_down<font color='#5555FF'><</font>block,N,dlib::bn_con,SUBNET<font color='#5555FF'>></font><font color='#5555FF'>></font>; |
|
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'><u>int</u></font> N, <font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>></font> <font color='#0000FF'>using</font> ares_down <font color='#5555FF'>=</font> dlib::relu<font color='#5555FF'><</font>residual_down<font color='#5555FF'><</font>block,N,dlib::affine,SUBNET<font color='#5555FF'>></font><font color='#5555FF'>></font>; |
|
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'><u>int</u></font> N, <font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>></font> <font color='#0000FF'>using</font> res_up <font color='#5555FF'>=</font> dlib::relu<font color='#5555FF'><</font>residual_up<font color='#5555FF'><</font>block,N,dlib::bn_con,SUBNET<font color='#5555FF'>></font><font color='#5555FF'>></font>; |
|
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'><u>int</u></font> N, <font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>></font> <font color='#0000FF'>using</font> ares_up <font color='#5555FF'>=</font> dlib::relu<font color='#5555FF'><</font>residual_up<font color='#5555FF'><</font>block,N,dlib::affine,SUBNET<font color='#5555FF'>></font><font color='#5555FF'>></font>; |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>></font> <font color='#0000FF'>using</font> res16 <font color='#5555FF'>=</font> res<font color='#5555FF'><</font><font color='#979000'>16</font>,SUBNET<font color='#5555FF'>></font>; |
|
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>></font> <font color='#0000FF'>using</font> res24 <font color='#5555FF'>=</font> res<font color='#5555FF'><</font><font color='#979000'>24</font>,SUBNET<font color='#5555FF'>></font>; |
|
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>></font> <font color='#0000FF'>using</font> res32 <font color='#5555FF'>=</font> res<font color='#5555FF'><</font><font color='#979000'>32</font>,SUBNET<font color='#5555FF'>></font>; |
|
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>></font> <font color='#0000FF'>using</font> res48 <font color='#5555FF'>=</font> res<font color='#5555FF'><</font><font color='#979000'>48</font>,SUBNET<font color='#5555FF'>></font>; |
|
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>></font> <font color='#0000FF'>using</font> ares16 <font color='#5555FF'>=</font> ares<font color='#5555FF'><</font><font color='#979000'>16</font>,SUBNET<font color='#5555FF'>></font>; |
|
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>></font> <font color='#0000FF'>using</font> ares24 <font color='#5555FF'>=</font> ares<font color='#5555FF'><</font><font color='#979000'>24</font>,SUBNET<font color='#5555FF'>></font>; |
|
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>></font> <font color='#0000FF'>using</font> ares32 <font color='#5555FF'>=</font> ares<font color='#5555FF'><</font><font color='#979000'>32</font>,SUBNET<font color='#5555FF'>></font>; |
|
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>></font> <font color='#0000FF'>using</font> ares48 <font color='#5555FF'>=</font> ares<font color='#5555FF'><</font><font color='#979000'>48</font>,SUBNET<font color='#5555FF'>></font>; |
|
|
|
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>></font> <font color='#0000FF'>using</font> level1 <font color='#5555FF'>=</font> dlib::repeat<font color='#5555FF'><</font><font color='#979000'>2</font>,res16,res<font color='#5555FF'><</font><font color='#979000'>16</font>,SUBNET<font color='#5555FF'>></font><font color='#5555FF'>></font>; |
|
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>></font> <font color='#0000FF'>using</font> level2 <font color='#5555FF'>=</font> dlib::repeat<font color='#5555FF'><</font><font color='#979000'>2</font>,res24,res_down<font color='#5555FF'><</font><font color='#979000'>24</font>,SUBNET<font color='#5555FF'>></font><font color='#5555FF'>></font>; |
|
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>></font> <font color='#0000FF'>using</font> level3 <font color='#5555FF'>=</font> dlib::repeat<font color='#5555FF'><</font><font color='#979000'>2</font>,res32,res_down<font color='#5555FF'><</font><font color='#979000'>32</font>,SUBNET<font color='#5555FF'>></font><font color='#5555FF'>></font>; |
|
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>></font> <font color='#0000FF'>using</font> level4 <font color='#5555FF'>=</font> dlib::repeat<font color='#5555FF'><</font><font color='#979000'>2</font>,res48,res_down<font color='#5555FF'><</font><font color='#979000'>48</font>,SUBNET<font color='#5555FF'>></font><font color='#5555FF'>></font>; |
|
|
|
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>></font> <font color='#0000FF'>using</font> alevel1 <font color='#5555FF'>=</font> dlib::repeat<font color='#5555FF'><</font><font color='#979000'>2</font>,ares16,ares<font color='#5555FF'><</font><font color='#979000'>16</font>,SUBNET<font color='#5555FF'>></font><font color='#5555FF'>></font>; |
|
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>></font> <font color='#0000FF'>using</font> alevel2 <font color='#5555FF'>=</font> dlib::repeat<font color='#5555FF'><</font><font color='#979000'>2</font>,ares24,ares_down<font color='#5555FF'><</font><font color='#979000'>24</font>,SUBNET<font color='#5555FF'>></font><font color='#5555FF'>></font>; |
|
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>></font> <font color='#0000FF'>using</font> alevel3 <font color='#5555FF'>=</font> dlib::repeat<font color='#5555FF'><</font><font color='#979000'>2</font>,ares32,ares_down<font color='#5555FF'><</font><font color='#979000'>32</font>,SUBNET<font color='#5555FF'>></font><font color='#5555FF'>></font>; |
|
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>></font> <font color='#0000FF'>using</font> alevel4 <font color='#5555FF'>=</font> dlib::repeat<font color='#5555FF'><</font><font color='#979000'>2</font>,ares48,ares_down<font color='#5555FF'><</font><font color='#979000'>48</font>,SUBNET<font color='#5555FF'>></font><font color='#5555FF'>></font>; |
|
|
|
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>></font> <font color='#0000FF'>using</font> level1t <font color='#5555FF'>=</font> dlib::repeat<font color='#5555FF'><</font><font color='#979000'>2</font>,res16,res_up<font color='#5555FF'><</font><font color='#979000'>16</font>,SUBNET<font color='#5555FF'>></font><font color='#5555FF'>></font>; |
|
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>></font> <font color='#0000FF'>using</font> level2t <font color='#5555FF'>=</font> dlib::repeat<font color='#5555FF'><</font><font color='#979000'>2</font>,res24,res_up<font color='#5555FF'><</font><font color='#979000'>24</font>,SUBNET<font color='#5555FF'>></font><font color='#5555FF'>></font>; |
|
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>></font> <font color='#0000FF'>using</font> level3t <font color='#5555FF'>=</font> dlib::repeat<font color='#5555FF'><</font><font color='#979000'>2</font>,res32,res_up<font color='#5555FF'><</font><font color='#979000'>32</font>,SUBNET<font color='#5555FF'>></font><font color='#5555FF'>></font>; |
|
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>></font> <font color='#0000FF'>using</font> level4t <font color='#5555FF'>=</font> dlib::repeat<font color='#5555FF'><</font><font color='#979000'>2</font>,res48,res_up<font color='#5555FF'><</font><font color='#979000'>48</font>,SUBNET<font color='#5555FF'>></font><font color='#5555FF'>></font>; |
|
|
|
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>></font> <font color='#0000FF'>using</font> alevel1t <font color='#5555FF'>=</font> dlib::repeat<font color='#5555FF'><</font><font color='#979000'>2</font>,ares16,ares_up<font color='#5555FF'><</font><font color='#979000'>16</font>,SUBNET<font color='#5555FF'>></font><font color='#5555FF'>></font>; |
|
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>></font> <font color='#0000FF'>using</font> alevel2t <font color='#5555FF'>=</font> dlib::repeat<font color='#5555FF'><</font><font color='#979000'>2</font>,ares24,ares_up<font color='#5555FF'><</font><font color='#979000'>24</font>,SUBNET<font color='#5555FF'>></font><font color='#5555FF'>></font>; |
|
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>></font> <font color='#0000FF'>using</font> alevel3t <font color='#5555FF'>=</font> dlib::repeat<font color='#5555FF'><</font><font color='#979000'>2</font>,ares32,ares_up<font color='#5555FF'><</font><font color='#979000'>32</font>,SUBNET<font color='#5555FF'>></font><font color='#5555FF'>></font>; |
|
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>></font> <font color='#0000FF'>using</font> alevel4t <font color='#5555FF'>=</font> dlib::repeat<font color='#5555FF'><</font><font color='#979000'>2</font>,ares48,ares_up<font color='#5555FF'><</font><font color='#979000'>48</font>,SUBNET<font color='#5555FF'>></font><font color='#5555FF'>></font>; |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'>template</font> <font color='#5555FF'><</font> |
|
<font color='#0000FF'>template</font><font color='#5555FF'><</font><font color='#0000FF'>typename</font><font color='#5555FF'>></font> <font color='#0000FF'>class</font> <b><a name='TAGGED'></a>TAGGED</b>, |
|
<font color='#0000FF'>template</font><font color='#5555FF'><</font><font color='#0000FF'>typename</font><font color='#5555FF'>></font> <font color='#0000FF'>class</font> <b><a name='PREV_RESIZED'></a>PREV_RESIZED</b>, |
|
<font color='#0000FF'>typename</font> SUBNET |
|
<font color='#5555FF'>></font> |
|
<font color='#0000FF'>using</font> resize_and_concat <font color='#5555FF'>=</font> dlib::add_layer<font color='#5555FF'><</font> |
|
dlib::concat_<font color='#5555FF'><</font>TAGGED,PREV_RESIZED<font color='#5555FF'>></font>, |
|
PREV_RESIZED<font color='#5555FF'><</font>dlib::resize_prev_to_tagged<font color='#5555FF'><</font>TAGGED,SUBNET<font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font>; |
|
|
|
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>></font> <font color='#0000FF'>using</font> utag1 <font color='#5555FF'>=</font> dlib::add_tag_layer<font color='#5555FF'><</font><font color='#979000'>2100</font><font color='#5555FF'>+</font><font color='#979000'>1</font>,SUBNET<font color='#5555FF'>></font>; |
|
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>></font> <font color='#0000FF'>using</font> utag2 <font color='#5555FF'>=</font> dlib::add_tag_layer<font color='#5555FF'><</font><font color='#979000'>2100</font><font color='#5555FF'>+</font><font color='#979000'>2</font>,SUBNET<font color='#5555FF'>></font>; |
|
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>></font> <font color='#0000FF'>using</font> utag3 <font color='#5555FF'>=</font> dlib::add_tag_layer<font color='#5555FF'><</font><font color='#979000'>2100</font><font color='#5555FF'>+</font><font color='#979000'>3</font>,SUBNET<font color='#5555FF'>></font>; |
|
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>></font> <font color='#0000FF'>using</font> utag4 <font color='#5555FF'>=</font> dlib::add_tag_layer<font color='#5555FF'><</font><font color='#979000'>2100</font><font color='#5555FF'>+</font><font color='#979000'>4</font>,SUBNET<font color='#5555FF'>></font>; |
|
|
|
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>></font> <font color='#0000FF'>using</font> utag1_ <font color='#5555FF'>=</font> dlib::add_tag_layer<font color='#5555FF'><</font><font color='#979000'>2110</font><font color='#5555FF'>+</font><font color='#979000'>1</font>,SUBNET<font color='#5555FF'>></font>; |
|
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>></font> <font color='#0000FF'>using</font> utag2_ <font color='#5555FF'>=</font> dlib::add_tag_layer<font color='#5555FF'><</font><font color='#979000'>2110</font><font color='#5555FF'>+</font><font color='#979000'>2</font>,SUBNET<font color='#5555FF'>></font>; |
|
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>></font> <font color='#0000FF'>using</font> utag3_ <font color='#5555FF'>=</font> dlib::add_tag_layer<font color='#5555FF'><</font><font color='#979000'>2110</font><font color='#5555FF'>+</font><font color='#979000'>3</font>,SUBNET<font color='#5555FF'>></font>; |
|
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>></font> <font color='#0000FF'>using</font> utag4_ <font color='#5555FF'>=</font> dlib::add_tag_layer<font color='#5555FF'><</font><font color='#979000'>2110</font><font color='#5555FF'>+</font><font color='#979000'>4</font>,SUBNET<font color='#5555FF'>></font>; |
|
|
|
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>></font> <font color='#0000FF'>using</font> concat_utag1 <font color='#5555FF'>=</font> resize_and_concat<font color='#5555FF'><</font>utag1,utag1_,SUBNET<font color='#5555FF'>></font>; |
|
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>></font> <font color='#0000FF'>using</font> concat_utag2 <font color='#5555FF'>=</font> resize_and_concat<font color='#5555FF'><</font>utag2,utag2_,SUBNET<font color='#5555FF'>></font>; |
|
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>></font> <font color='#0000FF'>using</font> concat_utag3 <font color='#5555FF'>=</font> resize_and_concat<font color='#5555FF'><</font>utag3,utag3_,SUBNET<font color='#5555FF'>></font>; |
|
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>></font> <font color='#0000FF'>using</font> concat_utag4 <font color='#5555FF'>=</font> resize_and_concat<font color='#5555FF'><</font>utag4,utag4_,SUBNET<font color='#5555FF'>></font>; |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'>static</font> <font color='#0000FF'>const</font> <font color='#0000FF'><u>char</u></font><font color='#5555FF'>*</font> instance_segmentation_net_filename <font color='#5555FF'>=</font> "<font color='#CC0000'>instance_segmentation_voc2012net_v2.dnn</font>"; |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#009900'>// training network type |
|
</font><font color='#0000FF'>using</font> seg_bnet_type <font color='#5555FF'>=</font> dlib::loss_binary_log_per_pixel<font color='#5555FF'><</font> |
|
dlib::cont<font color='#5555FF'><</font><font color='#979000'>1</font>,<font color='#979000'>1</font>,<font color='#979000'>1</font>,<font color='#979000'>1</font>,<font color='#979000'>1</font>, |
|
dlib::relu<font color='#5555FF'><</font>dlib::bn_con<font color='#5555FF'><</font>dlib::cont<font color='#5555FF'><</font><font color='#979000'>16</font>,<font color='#979000'>7</font>,<font color='#979000'>7</font>,<font color='#979000'>2</font>,<font color='#979000'>2</font>, |
|
concat_utag1<font color='#5555FF'><</font>level1t<font color='#5555FF'><</font> |
|
concat_utag2<font color='#5555FF'><</font>level2t<font color='#5555FF'><</font> |
|
concat_utag3<font color='#5555FF'><</font>level3t<font color='#5555FF'><</font> |
|
concat_utag4<font color='#5555FF'><</font>level4t<font color='#5555FF'><</font> |
|
level4<font color='#5555FF'><</font>utag4<font color='#5555FF'><</font> |
|
level3<font color='#5555FF'><</font>utag3<font color='#5555FF'><</font> |
|
level2<font color='#5555FF'><</font>utag2<font color='#5555FF'><</font> |
|
level1<font color='#5555FF'><</font>dlib::max_pool<font color='#5555FF'><</font><font color='#979000'>3</font>,<font color='#979000'>3</font>,<font color='#979000'>2</font>,<font color='#979000'>2</font>,utag1<font color='#5555FF'><</font> |
|
dlib::relu<font color='#5555FF'><</font>dlib::bn_con<font color='#5555FF'><</font>dlib::con<font color='#5555FF'><</font><font color='#979000'>16</font>,<font color='#979000'>7</font>,<font color='#979000'>7</font>,<font color='#979000'>2</font>,<font color='#979000'>2</font>, |
|
dlib::input<font color='#5555FF'><</font>dlib::matrix<font color='#5555FF'><</font>dlib::rgb_pixel<font color='#5555FF'>></font><font color='#5555FF'>></font> |
|
<font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font>; |
|
|
|
<font color='#009900'>// testing network type (replaced batch normalization with fixed affine transforms) |
|
</font><font color='#0000FF'>using</font> seg_anet_type <font color='#5555FF'>=</font> dlib::loss_binary_log_per_pixel<font color='#5555FF'><</font> |
|
dlib::cont<font color='#5555FF'><</font><font color='#979000'>1</font>,<font color='#979000'>1</font>,<font color='#979000'>1</font>,<font color='#979000'>1</font>,<font color='#979000'>1</font>, |
|
dlib::relu<font color='#5555FF'><</font>dlib::affine<font color='#5555FF'><</font>dlib::cont<font color='#5555FF'><</font><font color='#979000'>16</font>,<font color='#979000'>7</font>,<font color='#979000'>7</font>,<font color='#979000'>2</font>,<font color='#979000'>2</font>, |
|
concat_utag1<font color='#5555FF'><</font>alevel1t<font color='#5555FF'><</font> |
|
concat_utag2<font color='#5555FF'><</font>alevel2t<font color='#5555FF'><</font> |
|
concat_utag3<font color='#5555FF'><</font>alevel3t<font color='#5555FF'><</font> |
|
concat_utag4<font color='#5555FF'><</font>alevel4t<font color='#5555FF'><</font> |
|
alevel4<font color='#5555FF'><</font>utag4<font color='#5555FF'><</font> |
|
alevel3<font color='#5555FF'><</font>utag3<font color='#5555FF'><</font> |
|
alevel2<font color='#5555FF'><</font>utag2<font color='#5555FF'><</font> |
|
alevel1<font color='#5555FF'><</font>dlib::max_pool<font color='#5555FF'><</font><font color='#979000'>3</font>,<font color='#979000'>3</font>,<font color='#979000'>2</font>,<font color='#979000'>2</font>,utag1<font color='#5555FF'><</font> |
|
dlib::relu<font color='#5555FF'><</font>dlib::affine<font color='#5555FF'><</font>dlib::con<font color='#5555FF'><</font><font color='#979000'>16</font>,<font color='#979000'>7</font>,<font color='#979000'>7</font>,<font color='#979000'>2</font>,<font color='#979000'>2</font>, |
|
dlib::input<font color='#5555FF'><</font>dlib::matrix<font color='#5555FF'><</font>dlib::rgb_pixel<font color='#5555FF'>></font><font color='#5555FF'>></font> |
|
<font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>></font>; |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'>#endif</font> <font color='#009900'>// DLIB_DNn_INSTANCE_SEGMENTATION_EX_H_ |
|
</font> |
|
</pre></body></html> |