Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deformable Parts Model #85

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open

Deformable Parts Model #85

wants to merge 27 commits into from

Conversation

kritsong
Copy link

@kritsong kritsong commented Mar 4, 2016

This is the first version of Deformable Parts Model(DPM) moved into menpo by converting the publicly available code from matlab.

DPM represents objects using a collection of parts usually represented by rectangle boxes. Each part captures local appearance of an object normally using Histogram of Gradient(HOG) feature, and the configuration of their connections are spring-like, tree structure.

The code consist of 3 main files:

  • base.py consists of 3 classes
    • class DPM(currently name Model) is a mixture model. Similar components may share a pool of filters, but use different deformable coefficients. It provides easy way to access filters and deformable coefficients as well as some utility methods.
    • class Qp (Quadratic programming) is a dual coordinate solvers which based on data-subsampling algorithms for collecting hard examples.
    • class DPMLearner train the mixture model from the given examples by using a class Qp.
      • Initially, each part of the DPM model is initialised by averaging the filters values(HOG) from the positive examples. Then they are trained independently with Qp
      • Each part is then combined into a initial DPM model by using the average deformable coefficients computed from positive examples. The model is then again trained using Qp.
  • fitter.py contains a class DPMFitter
    • DPMFitter detect the best configurations(locations) of part based on the given model for the given image
      • A given image is first transformed into a feature pyramid.
      • Fitter iterates through each level of the feature pyramid, then through each components of the model to compute the best possible score at each position.
      • The score is computed in two steps:
        • First, by convolving the filter of each part of the model with the feature pyramid, the independent scores of each part is computed.
        • Then, each part's score is combined efficiently by using Distance transform function to compute the best possible score of each position in the image (each position in an image can have multiple configurations depending on each part location).
      • The positions with the score above a given threshold are then returned.
  • main.py
    • It is used to debug and help visualising the results.
    • It provide options to
      • Fit the pre-trained model given by the original code by converting a matlab model into DPM model.
      • Fit the pre-trained model trained in python with 93 positive examples. (original code uses 900 positive examples)

TODO:

  • Currently, the codes that originally done in C are not all moved into C
  • DPMLearner use DPMFitter as part of the training. Maybe, the functionality outside of the fitting can all be moved into DPMLearner so that DPMFitter is cleaner.
  • More comment on how Qp work.
  • Update DPMLearner so that it properly take a set of image as an input to train.
  • Add functionality to learn the configuration from the positive examples e.g. tree sturcture

@patricksnape
Copy link
Contributor

@kritsong Add me as a collaborator to your menpofit fork 😄

@@ -6,6 +6,7 @@ requirements:
build:
- python
- setuptools
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Numpy is required - - numpy 1.10.*

scales[j + m_inter] = 0.5 * scales[j]

feats_np = {} # final feats (keep only numpy array, get rid of the image)
for k, val in scales.iteritems():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iteritems doesn't exist in Python 3

@grigorisg9gr
Copy link
Member

Amazing work @kritsong !
@patricksnape : If you check out the original code for backtracking, there is a difference whether the backtracking is just for fitting or for the learning part. In the latter case, it also updates some external variables that you don't need when you just fit a pre-trained model.

@menpobot
Copy link

Can one of the admins verify this patch?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants