\documentclass[a4paper,10pt]{article}
%\documentclass[a4paper,10pt]{scrartcl}

\usepackage[utf8]{inputenc}
\usepackage[a4paper, left=1.0in, right=1.0in, top=1.5in, bottom=1.5in]{geometry}
\usepackage{titling}

\usepackage{parskip}
\usepackage{hyperref}
\usepackage{graphicx}

\title{Discriminatively trained deformable part models\\{\LARGE Short Report}}
\author{Jorge Almeida}
\date{\today}
\makeatother

\pdfinfo{%
  /Title    (Discriminatively trained deformable part models, Short Report)
  /Author   (Jorge Almeida)
  /Creator  (Jorge Almeida)
  /Producer (Jorge Almeida)
  /Subject  (Discriminatively trained deformable part models, implementation)
  /Keywords (Short Report, implementation)
}

\begin{document}
% \maketitle

{\LARGE \textbf{Discriminatively trained deformable parts models\\}}
{\Large \textbf{Short report\\}}

{\Large \theauthor\\}
\thedate

% \vspace{0.5in}
\section{Introduction}

The \verb|voc_release5| is a complete learning-based system for detecting and localizing objects in images. The system
represents objects using mixtures of deformable part models. These models are trained using a discriminative method
that only requires bounding boxes for the objects in an image. This system achieved state of the art results on the
PASCAL dataset.

This document presents an overview of the main functions and their interaction.

The \verb|voc_release5| package is accessible in \url{http://www.cs.berkeley.edu/~rbg/latent/}

\section{Configuration}

To prepare Matlab to use the \verb|voc_release5| use the function \verb|startup()|. This function adds all necessary
paths.

The \verb|voc_release5| uses \verb|C++| \verb|mex| functions to increase performance.
The \verb|mex| functions can be compiled by calling the function \verb|compile()|. To successfully compile, additional
\verb|CXXOPTIMFLAGS| are needed, these flags are \verb|-msse -msse2 -msse3 -mfpmath=sse|.

Package parameters are configured by \verb|voc_config()|. This function provides a simple overwrite mechanism, the user
must only define the global variable \verb|VOC_CONFIG_OVERRIDE| with a handler to an additional user defined
configuration file. All parameters already defined in the user configuration file will \textbf{not} be redefined. 

\section{Training}

The top level training function is \verb|pascal()|, this function trains and evaluates a model using the PASCAL
database. This function calls \verb|pascal_train()| for the training phase.

\verb|pascal_train()| starts by obtaining the configuration using \verb|voc_config()| and loading the training
information (headers only) by calling \verb|pascal_data()|.

The \verb|pascal_train()| function performs multiple rounds of training using the \verb|train()| function. First, it
starts by training only the root filters, figure \ref{fig:asymmetric_root}, the user specifies how many root filters
must be trained for each class, the positives are sorted by aspect ratio and $n$ root filters are initialized. Then
mirrored versions of the initialized root filters are added to create mixture models, and subsequently trained, figure
\ref{fig:mirrored_root}. Following that, all root filters are combined into one mixture model and undergo another round
of training. The last step is the inclusion of part filters, 8 parts for each root model, and retraining, figure
\ref{fig:final_mix}.

\begin{figure} [h!]
	\centering
	\includegraphics[height=1.5in]{figures/asymmetric_root_2.pdf}
	\caption{Asymmetrical root filter trained with warped positives and random negatives. This is just one of the root
filters created for each class, in this case a car.}
	\label{fig:asymmetric_root}
\end{figure}

\begin{figure} [h!]
	\centering
	\includegraphics[height=2.0in]{figures/mirrored_root_2.pdf}
	\caption{Mixture of two mirrored root filters trained with latent positives and hard negatives. In this stage there
are still multiple models created from the initial positives.}
	\label{fig:mirrored_root}
\end{figure}

\begin{figure} [h!]
	\centering
	\includegraphics[height=2.0in]{figures/final_mix_single_root.pdf}
	\caption{Part of a final model, only one of the mirrored root filters. On the left the root filters; in the middle
the part filters and on the right the cost of placing the part filters away from their initial position, relative to the
root.}
	\label{fig:final_mix}
\end{figure}

Function \verb|root_model()| is used for root model initialization; \verb|lr_root_model()| is used to add mirrored root
filters; \verb|model_merge()| combines all root models into a single mixture model and \verb|model_add_parts()| adds
parts to a model.

\verb|train()| implements the main training routine, this function uses a \verb|C++| implemented feature cache.
The examples are prepared using specialized functions and put in the cache: \verb|poswarp()| prepares warped positive
examples; \verb|poslatent()| prepares the latent positives; \verb|neghard()| prepares the hard negatives and finally
\verb|negrandom()| prepares the random negatives.

The preparing functions use the \verb|C++| implemented \verb|features()| function to calculate HOG features. Both
\verb|poswarp()| and \verb|negrandom()| call \verb|features()| directly. \verb|poslatent()| calls
\verb|gdetect_pos_prepare()| to create a feature pyramid (using \verb|featpyramid()|) and prepare it for latent
detection, while the \verb|neghard()| calls \verb|featpyramid()| directly.

\verb|train()| uses the \verb|fv_obj_func()| to calculate the objective function value and gradient, this operation is
also performed on the cache. L-BFGS is used to minimize the objective function by calling \verb|minConf_TMP()|
(function from an external library included in the package).

All cache operations are performed by calling \verb|fv_cache()| with different arguments (see the \verb|handlers|
structure in \verb|fv_cache.cc| for a list of possibilities and the corresponding handling functions).

\section{Detection}

To perform a detection using a previously trained model the function \verb|process()| is used. This function calls
\verb|imgdetect()|, that calculates the feature pyramid, \verb|featpyramid()|, and calls \verb|gdetect()|.
\verb|gdetect()| performs detections by first computing dynamic programming tables using \verb|gdetect_dp()| and
obtaining detections by calling \verb|gdetect_parse()|. 

Detections are output as bounding boxes for both the root filter position and parts positions.

\begin{figure} [h!]
	\centering
	\includegraphics[height=3.0in]{figures/detection.pdf}
	\caption{Example of a vehicle detection. The red box denotes the root filter detection while the blue boxes are
part filters.}
	\label{fig:detection}
\end{figure}

\end{document}
