SlideShare a Scribd company logo
1 of 82
Computer vision:
models, learning and inference
             Chapter 11
     Fitting probability models


      Please send errata to s.prince@cs.ucl.ac.uk
Structure
•   Chain and tree models
•   MAP inference in chain models
•   MAP inference in tree models
•   Maximum marginals in chain models
•   Maximum marginals in tree models
•   Models with loops
•   Applications

          Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   2
Chain and tree models
• Given a set of measurements            and world
  states         , infer the world states from the
  measurements

• Problem: if N is large then the model relating the
  two will have a very large number of parameters.

• Solution: build sparse models where we only
  describe subsets of the relations between
  variables.

          Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   3
Chain and tree models
Chain model: only model connections between
  world variable and its predecessing and
  subsequent variables

Tree model: connections between world
  variables are organized as a tree (no loops).
  Disregard directionality of connections for
  directed model

         Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   4
Assumptions
We’ll assume that

  – World states                     are discrete

  – Observed data variables                                    for each world state

  – The nth data variable    is conditionally
    independent of all of other data variables and
    world states given associated world state

         Computer vision: models, learning and inference. ©2011 Simon J.D. Prince     5
Gesture Tracking




Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   6
Directed model for chains
 (Hidden Markov model)




 Compatibility of measurement                            Compatibility of world state and
       and world state                                       previous world state
Computer vision: models, learning and inference. ©2011 Simon J.D. Prince              7
Undirected model for chains




    Compatibility of measurement                            Compatibility of world state and
          and world state                                       previous world state
   Computer vision: models, learning and inference. ©2011 Simon J.D. Prince              8
Equivalence of chain models
Directed:



Undirected:




Equivalence:




               Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   9
Chain model for sign language
               application




Observations are normally distributed but depend on sign k


World state is categorically distributed, parameters depend on
previous world state

           Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   10
Structure
•   Chain and tree models
•   MAP inference in chain models
•   MAP inference in tree models
•   Maximum marginals in chain models
•   Maximum marginals in tree models
•   Models with loops
•   Applications

          Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   11
MAP inference in chain model
Directed model:




MAP inference:




Substituting in :




                 Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   12
MAP inference in chain model



Takes the general form:




Unary term:
Pairwise term:


              Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   13
Dynamic programming
Maximizes functions of the form:




Set up as cost for traversing graph – each path from left to right is one possible
configuration of world states




                     Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   14
Dynamic programming
Algorithm:

1. Work through graph computing minimum possible cost                               to reach each node
2. When we get to last column find minimum
3. Trace back to see how we got there




                Computer vision: models, learning and inference. ©2011 Simon J.D. Prince                 15
Worked example




Unary cost                Pairwise costs              1. Zero cost to stay at same label
                                                      2. Cost of 2 to change label by 1
                                                      3. Infinite cost for changing by more
                                                         than one (not shown)

     Computer vision: models, learning and inference. ©2011 Simon J.D. Prince           16
Worked example




Minimum cost
to reach first node is just unary cost



      Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   17
Worked example




Minimum cost          is minimum of two possible routes to get here

Route 1: 2.0+0.0+1.1 = 3.1
Route 2: 0.8+2.0+1.1 = 3.9

               Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   18
Worked example




Minimum cost          is minimum of two possible routes to get here

Route 1: 2.0+0.0+1.1 = 3.1             -- this is the minimum – note this down
Route 2: 0.5+2.0+1.1 = 3.6

               Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   19
Worked example




General rule:




                Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   20
Worked example




Work through the graph, computing the minimum
cost to reach each node

          Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   21
Worked example




Keep going until we reach the end of the graph



           Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   22
Worked example




Find the minimum possible cost to reach the final column



           Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   23
Worked example




Trace back the route that we arrived here by – this is the
minimum configuration

            Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   24
Structure
•   Chain and tree models
•   MAP inference in chain models
•   MAP inference in tree models
•   Maximum marginals in chain models
•   Maximum marginals in tree models
•   Models with loops
•   Applications

          Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   25
MAP inference for trees




Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   26
MAP inference for trees




Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   27
Worked example




Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   28
Worked example
                                                           Variables 1-4 proceed as for
                                                           the chain example.




Computer vision: models, learning and inference. ©2011 Simon J.D. Prince              29
Worked example
                                                           At variable n=5 must
                                                           consider all pairs of paths
                                                           from into the current node.




Computer vision: models, learning and inference. ©2011 Simon J.D. Prince                 30
Worked example
                                                           Variable 6 proceeds as
                                                           normal.

                                                           Then we trace back through
                                                           the variables, splitting at the
                                                           junction.




Computer vision: models, learning and inference. ©2011 Simon J.D. Prince                31
Structure
•   Chain and tree models
•   MAP inference in chain models
•   MAP inference in tree models
•   Maximum marginals in chain models
•   Maximum marginals in tree models
•   Models with loops
•   Applications

          Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   32
Marginal posterior inference

• Start by computing the marginal distribution
  over the Nth variable

• Then we`ll consider how to compute the other marginal
  distributions




          Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   33
Computing one marginal distribution
Compute the posterior using Bayes` rule:




We compute this expression by writing the joint probability :




                  Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   34
Computing one marginal distribution



Problem: Computing all NK states and marginalizing explicitly is intractable.

Solution: Re-order terms and move summations to the right




                 Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   35
Computing one marginal distribution



Define function of variable w1 (two rightmost terms)



Then compute function of variables w2 in terms of previous function




Leads to the recursive relation




               Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   36
Computing one marginal distribution



We work our way through the sequence using this recursion.

At the end we normalize the result to compute the posterior


Total number of summations is (N-1)K as opposed to KN for
brute force approach.


          Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   37
Forward-backward algorithm
• We could compute the other N-1 marginal posterior
  distributions using a similar set of computations
• However, this is inefficient as much of the computation is
  duplicated
• The forward-backward algorithm computes all of the
  marginal posteriors at once




 Solution:                                                                               ... and take
                                                                                           products
                 Compute all first term                          Compute all second
                   using a recursion                           terms using a recursion
             Computer vision: models, learning and inference. ©2011 Simon J.D. Prince              38
Forward recursion
                                                                                 Conditional
                                                                               probability rule




                                                                              Using conditional
                                                                           independence relations

 This is the same recursion as before




Computer vision: models, learning and inference. ©2011 Simon J.D. Prince                    39
Backward recursion
                                                                             Conditional
                                                                           probability rule




                                                                           Using conditional
                                                                            independence
                                                                               relations
 This is another recursion of the form




Computer vision: models, learning and inference. ©2011 Simon J.D. Prince                40
Forward backward algorithm
Compute the marginal posterior distribution as
product of two terms



Forward terms:


Backward terms:


        Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   41
Belief propagation
•   Forward backward algorithm is a special case of a more
    general technique called belief propagation

•   Intermediate functions in forward and backward
    recursions are considered as messages conveying beliefs
    about the variables.

•   Well examine the Sum-Product algorithm.

•   The sum-product algorithm operates on factor graphs.



          Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   42
Sum product algorithm
•   Forward backward algorithm is a special case of a more
    general technique called belief propagation

•   Intermediate functions in forward and backward
    recursions are considered as messages conveying beliefs
    about the variables.

•   Well examine the Sum-Product algorithm.

•   The sum-product algorithm operates on factor graphs.



          Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   43
Factor graphs




• One node for each variable
• One node for each function relating variables

          Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   44
Sum product algorithm
Forward pass
   • Distribute evidence through the graph

Backward pass
   • Collates the evidence

Both phases involve passing messages between nodes:
   • The forward phase can proceed in any order as long
       as the outgoing messages are not sent until all
       incoming ones received
   • Backward phase proceeds in reverse order to forward


         Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   45
Sum product algorithm




Three kinds of message
   • Messages from unobserved variables to functions
   • Messages from observed variables to functions
   • Messages from functions to variables


          Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   46
Sum product algorithm
Message type 1:
  • Messages from unobserved variables z to function g



   • Take product of incoming messages
   • Interpretation: combining beliefs

Message type 2:
  • Messages from observed variables z to function g


   • Interpretation: conveys certain belief that observed
     values are true
          Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   47
Sum product algorithm
Message type 3:
  • Messages from a function g to variable z



    • Takes beliefs from all incoming variables except recipient
      and uses function g to a belief about recipient

Computing marginal distributions:
   • After forward and backward passes, we compute the
     marginal dists as the product of all incoming messages



            Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   48
Sum product: forward pass




Message from x1 to g1:

By rule 2:



             Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   49
Sum product: forward pass




Message from g1 to w1:

By rule 3:



             Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   50
Sum product: forward pass




Message from w1 to g1,2:

By rule 1:

(product of all incoming messages)
             Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   51
Sum product: forward pass




Message from g1,2 from w2:

By rule 3:



             Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   52
Sum product: forward pass




Messages from x2 to g2 and g2 to w2:




             Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   53
Sum product: forward pass




Message from w2 to g2,3:




                 The same recursion as in the forward backward algorithm
            Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   54
Sum product: forward pass




Message from w2 to g2,3:




            Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   55
Sum product: backward pass




Message from wN to gN,N-1:




            Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   56
Sum product: backward pass




Message from gN,N-1 to wN-1:




             Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   57
Sum product: backward pass




Message from gn,n-1 to wn-1:



     The same recursion as in the forward backward algorithm
             Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   58
Sum product: collating evidence

•   Marginal distribution is products of all messages
    at node




•   Proof:




         Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   59
Structure
•   Chain and tree models
•   MAP inference in chain models
•   MAP inference in tree models
•   Maximum marginals in chain models
•   Maximum marginals in tree models
•   Models with loops
•   Applications

          Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   60
Marginal posterior inference for trees




  Apply sum-product algorithm to the tree-structured
  graph.

        Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   61
Structure
•   Chain and tree models
•   MAP inference in chain models
•   MAP inference in tree models
•   Maximum marginals in chain models
•   Maximum marginals in tree models
•   Models with loops
•   Applications

          Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   62
Tree structured graphs




This graph contains loops                                   But the associated factor graph
                                                                 has structure of a tree

                                                             Can still use Belief Propagation

        Computer vision: models, learning and inference. ©2011 Simon J.D. Prince                63
Learning in chains and trees
Supervised learning (where we know world states wn) is
relatively easy.

Unsupervised learning (where we do not know world
states wn) is more challenging. Use the EM algorithm:

    •   E-step – compute posterior marginals over
        states
    •   M-step – update model parameters

For the chain model (hidden Markov model) this is
    known as the Baum-Welch algorithm.

        Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   64
Grid-based graphs




Often in vision, we have one observation associated with each
pixel in the image grid.

           Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   65
Why not dynamic programming?




When we trace back from the final node, the paths are not
guaranteed to converge.

          Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   66
Why not dynamic programming?




    Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   67
Why not dynamic programming?




But:


       Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   68
Approaches to inference for
              grid-based models




1. Prune the graph.

Remove edges until an edge remains


              Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   69
Approaches to inference for
                  grid-based models




2. Combine variables.

Merge variables to form compound variable with more states until what remains is a tree.
  Not practical for large grids

                Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   70
Approaches to inference for
                    grid-based models

3. Loopy belief propagation.

   Just apply belief propagation. It is not guaranteed to converge, but in practice
   it works well.

4. Sampling approaches

   Draw samples from the posterior (easier for directed models)

5. Other approaches

    • Tree-reweighted message passing
    • Graph cuts

                  Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   71
Structure
•   Chain and tree models
•   MAP inference in chain models
•   MAP inference in tree models
•   Maximum marginals in chain models
•   Maximum marginals in tree models
•   Models with loops
•   Applications

          Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   72
Gesture Tracking




Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   73
Stereo vision




•   Two image taken from slightly different positions
•   Matching point in image 2 is on same scanline as image 1
•   Horizontal offset is called disparity
•   Disparity is inversely related to depth
•   Goal – infer disparities wm,n at pixel m,n from images x(1) and x(2)

Use likelihood:




                  Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   74
Stereo vision




Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   75
Stereo vision




1. Independent pixels




                 Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   76
Stereo vision




2. Scanlines as chain model (hidden Markov model)




                 Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   77
Stereo vision




3. Pixels organized as tree (from Veksler 2005)




                   Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   78
Pictorial Structures




Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   79
Pictorial Structures




Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   80
Segmentation




Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   81
Conclusion
• For the special case of chains and trees we can perform
  MAP inference and compute marginal posteriors
  efficiently.

• Unfortunately, many vision problems are defined on pixel
  grid – this requires special methods




         Computer vision: models, learning and inference. ©2011 Simon J.D. Prince   82

More Related Content

Viewers also liked

Lecture14
Lecture14Lecture14
Lecture14zukun
 
Lecture27
Lecture27Lecture27
Lecture27zukun
 
Mit6870 orsu lecture12
Mit6870 orsu lecture12Mit6870 orsu lecture12
Mit6870 orsu lecture12zukun
 
18 cv mil_style_and_identity
18 cv mil_style_and_identity18 cv mil_style_and_identity
18 cv mil_style_and_identityzukun
 
16 cv mil_multiple_cameras
16 cv mil_multiple_cameras16 cv mil_multiple_cameras
16 cv mil_multiple_cameraszukun
 
Lecture24
Lecture24Lecture24
Lecture24zukun
 
Notebook review
Notebook reviewNotebook review
Notebook reviewrtaulbe1
 

Viewers also liked (7)

Lecture14
Lecture14Lecture14
Lecture14
 
Lecture27
Lecture27Lecture27
Lecture27
 
Mit6870 orsu lecture12
Mit6870 orsu lecture12Mit6870 orsu lecture12
Mit6870 orsu lecture12
 
18 cv mil_style_and_identity
18 cv mil_style_and_identity18 cv mil_style_and_identity
18 cv mil_style_and_identity
 
16 cv mil_multiple_cameras
16 cv mil_multiple_cameras16 cv mil_multiple_cameras
16 cv mil_multiple_cameras
 
Lecture24
Lecture24Lecture24
Lecture24
 
Notebook review
Notebook reviewNotebook review
Notebook review
 

Similar to 11 cv mil_models_for_chains_and_trees

Graphical Models for chains, trees and grids
Graphical Models for chains, trees and gridsGraphical Models for chains, trees and grids
Graphical Models for chains, trees and gridspotaters
 
17 cv mil_models_for_shape
17 cv mil_models_for_shape17 cv mil_models_for_shape
17 cv mil_models_for_shapezukun
 
20 cv mil_models_for_words
20 cv mil_models_for_words20 cv mil_models_for_words
20 cv mil_models_for_wordszukun
 
14 cv mil_the_pinhole_camera
14 cv mil_the_pinhole_camera14 cv mil_the_pinhole_camera
14 cv mil_the_pinhole_camerazukun
 
13 cv mil_preprocessing
13 cv mil_preprocessing13 cv mil_preprocessing
13 cv mil_preprocessingzukun
 
03 cv mil_probability_distributions
03 cv mil_probability_distributions03 cv mil_probability_distributions
03 cv mil_probability_distributionszukun
 
05 cv mil_normal_distribution
05 cv mil_normal_distribution05 cv mil_normal_distribution
05 cv mil_normal_distributionzukun
 
Introduction to Probability
Introduction to ProbabilityIntroduction to Probability
Introduction to ProbabilityLukas Tencer
 
19 cv mil_temporal_models
19 cv mil_temporal_models19 cv mil_temporal_models
19 cv mil_temporal_modelszukun
 
02 cv mil_intro_to_probability
02 cv mil_intro_to_probability02 cv mil_intro_to_probability
02 cv mil_intro_to_probabilityzukun
 
Common Probability Distibution
Common Probability DistibutionCommon Probability Distibution
Common Probability DistibutionLukas Tencer
 
06 cv mil_learning_and_inference
06 cv mil_learning_and_inference06 cv mil_learning_and_inference
06 cv mil_learning_and_inferencezukun
 
Mathematical Modeling for Practical Problems
Mathematical Modeling for Practical ProblemsMathematical Modeling for Practical Problems
Mathematical Modeling for Practical ProblemsLiwei Ren任力偉
 
Learning to Remember Patterns: Pattern Matching Memory Networks for Traffic F...
Learning to Remember Patterns: Pattern Matching Memory Networks for Traffic F...Learning to Remember Patterns: Pattern Matching Memory Networks for Traffic F...
Learning to Remember Patterns: Pattern Matching Memory Networks for Traffic F...ivaderivader
 
04 Fitting Probability Models ノート
04 Fitting Probability Models ノート04 Fitting Probability Models ノート
04 Fitting Probability Models ノートGen Sasaki
 
Unsupervised Learning (D2L6 2017 UPC Deep Learning for Computer Vision)
Unsupervised Learning (D2L6 2017 UPC Deep Learning for Computer Vision)Unsupervised Learning (D2L6 2017 UPC Deep Learning for Computer Vision)
Unsupervised Learning (D2L6 2017 UPC Deep Learning for Computer Vision)Universitat Politècnica de Catalunya
 
Housing Price Models
Housing Price ModelsHousing Price Models
Housing Price ModelsGaetan Lion
 
PMSCS 657_Parallel and Distributed processing
PMSCS 657_Parallel and Distributed processingPMSCS 657_Parallel and Distributed processing
PMSCS 657_Parallel and Distributed processingMd. Mashiur Rahman
 
Output Units and Cost Function in FNN
Output Units and Cost Function in FNNOutput Units and Cost Function in FNN
Output Units and Cost Function in FNNLin JiaMing
 

Similar to 11 cv mil_models_for_chains_and_trees (20)

Graphical Models for chains, trees and grids
Graphical Models for chains, trees and gridsGraphical Models for chains, trees and grids
Graphical Models for chains, trees and grids
 
17 cv mil_models_for_shape
17 cv mil_models_for_shape17 cv mil_models_for_shape
17 cv mil_models_for_shape
 
20 cv mil_models_for_words
20 cv mil_models_for_words20 cv mil_models_for_words
20 cv mil_models_for_words
 
14 cv mil_the_pinhole_camera
14 cv mil_the_pinhole_camera14 cv mil_the_pinhole_camera
14 cv mil_the_pinhole_camera
 
13 cv mil_preprocessing
13 cv mil_preprocessing13 cv mil_preprocessing
13 cv mil_preprocessing
 
03 cv mil_probability_distributions
03 cv mil_probability_distributions03 cv mil_probability_distributions
03 cv mil_probability_distributions
 
05 cv mil_normal_distribution
05 cv mil_normal_distribution05 cv mil_normal_distribution
05 cv mil_normal_distribution
 
Introduction to Probability
Introduction to ProbabilityIntroduction to Probability
Introduction to Probability
 
19 cv mil_temporal_models
19 cv mil_temporal_models19 cv mil_temporal_models
19 cv mil_temporal_models
 
02 cv mil_intro_to_probability
02 cv mil_intro_to_probability02 cv mil_intro_to_probability
02 cv mil_intro_to_probability
 
Common Probability Distibution
Common Probability DistibutionCommon Probability Distibution
Common Probability Distibution
 
06 cv mil_learning_and_inference
06 cv mil_learning_and_inference06 cv mil_learning_and_inference
06 cv mil_learning_and_inference
 
Mathematical Modeling for Practical Problems
Mathematical Modeling for Practical ProblemsMathematical Modeling for Practical Problems
Mathematical Modeling for Practical Problems
 
Learning to Remember Patterns: Pattern Matching Memory Networks for Traffic F...
Learning to Remember Patterns: Pattern Matching Memory Networks for Traffic F...Learning to Remember Patterns: Pattern Matching Memory Networks for Traffic F...
Learning to Remember Patterns: Pattern Matching Memory Networks for Traffic F...
 
Deep Learning Opening Workshop - Improving Generative Models - Junier Oliva, ...
Deep Learning Opening Workshop - Improving Generative Models - Junier Oliva, ...Deep Learning Opening Workshop - Improving Generative Models - Junier Oliva, ...
Deep Learning Opening Workshop - Improving Generative Models - Junier Oliva, ...
 
04 Fitting Probability Models ノート
04 Fitting Probability Models ノート04 Fitting Probability Models ノート
04 Fitting Probability Models ノート
 
Unsupervised Learning (D2L6 2017 UPC Deep Learning for Computer Vision)
Unsupervised Learning (D2L6 2017 UPC Deep Learning for Computer Vision)Unsupervised Learning (D2L6 2017 UPC Deep Learning for Computer Vision)
Unsupervised Learning (D2L6 2017 UPC Deep Learning for Computer Vision)
 
Housing Price Models
Housing Price ModelsHousing Price Models
Housing Price Models
 
PMSCS 657_Parallel and Distributed processing
PMSCS 657_Parallel and Distributed processingPMSCS 657_Parallel and Distributed processing
PMSCS 657_Parallel and Distributed processing
 
Output Units and Cost Function in FNN
Output Units and Cost Function in FNNOutput Units and Cost Function in FNN
Output Units and Cost Function in FNN
 

More from zukun

My lyn tutorial 2009
My lyn tutorial 2009My lyn tutorial 2009
My lyn tutorial 2009zukun
 
ETHZ CV2012: Tutorial openCV
ETHZ CV2012: Tutorial openCVETHZ CV2012: Tutorial openCV
ETHZ CV2012: Tutorial openCVzukun
 
ETHZ CV2012: Information
ETHZ CV2012: InformationETHZ CV2012: Information
ETHZ CV2012: Informationzukun
 
Siwei lyu: natural image statistics
Siwei lyu: natural image statisticsSiwei lyu: natural image statistics
Siwei lyu: natural image statisticszukun
 
Lecture9 camera calibration
Lecture9 camera calibrationLecture9 camera calibration
Lecture9 camera calibrationzukun
 
Brunelli 2008: template matching techniques in computer vision
Brunelli 2008: template matching techniques in computer visionBrunelli 2008: template matching techniques in computer vision
Brunelli 2008: template matching techniques in computer visionzukun
 
Modern features-part-4-evaluation
Modern features-part-4-evaluationModern features-part-4-evaluation
Modern features-part-4-evaluationzukun
 
Modern features-part-3-software
Modern features-part-3-softwareModern features-part-3-software
Modern features-part-3-softwarezukun
 
Modern features-part-2-descriptors
Modern features-part-2-descriptorsModern features-part-2-descriptors
Modern features-part-2-descriptorszukun
 
Modern features-part-1-detectors
Modern features-part-1-detectorsModern features-part-1-detectors
Modern features-part-1-detectorszukun
 
Modern features-part-0-intro
Modern features-part-0-introModern features-part-0-intro
Modern features-part-0-introzukun
 
Lecture 02 internet video search
Lecture 02 internet video searchLecture 02 internet video search
Lecture 02 internet video searchzukun
 
Lecture 01 internet video search
Lecture 01 internet video searchLecture 01 internet video search
Lecture 01 internet video searchzukun
 
Lecture 03 internet video search
Lecture 03 internet video searchLecture 03 internet video search
Lecture 03 internet video searchzukun
 
Icml2012 tutorial representation_learning
Icml2012 tutorial representation_learningIcml2012 tutorial representation_learning
Icml2012 tutorial representation_learningzukun
 
Advances in discrete energy minimisation for computer vision
Advances in discrete energy minimisation for computer visionAdvances in discrete energy minimisation for computer vision
Advances in discrete energy minimisation for computer visionzukun
 
Gephi tutorial: quick start
Gephi tutorial: quick startGephi tutorial: quick start
Gephi tutorial: quick startzukun
 
EM algorithm and its application in probabilistic latent semantic analysis
EM algorithm and its application in probabilistic latent semantic analysisEM algorithm and its application in probabilistic latent semantic analysis
EM algorithm and its application in probabilistic latent semantic analysiszukun
 
Object recognition with pictorial structures
Object recognition with pictorial structuresObject recognition with pictorial structures
Object recognition with pictorial structureszukun
 
Iccv2011 learning spatiotemporal graphs of human activities
Iccv2011 learning spatiotemporal graphs of human activities Iccv2011 learning spatiotemporal graphs of human activities
Iccv2011 learning spatiotemporal graphs of human activities zukun
 

More from zukun (20)

My lyn tutorial 2009
My lyn tutorial 2009My lyn tutorial 2009
My lyn tutorial 2009
 
ETHZ CV2012: Tutorial openCV
ETHZ CV2012: Tutorial openCVETHZ CV2012: Tutorial openCV
ETHZ CV2012: Tutorial openCV
 
ETHZ CV2012: Information
ETHZ CV2012: InformationETHZ CV2012: Information
ETHZ CV2012: Information
 
Siwei lyu: natural image statistics
Siwei lyu: natural image statisticsSiwei lyu: natural image statistics
Siwei lyu: natural image statistics
 
Lecture9 camera calibration
Lecture9 camera calibrationLecture9 camera calibration
Lecture9 camera calibration
 
Brunelli 2008: template matching techniques in computer vision
Brunelli 2008: template matching techniques in computer visionBrunelli 2008: template matching techniques in computer vision
Brunelli 2008: template matching techniques in computer vision
 
Modern features-part-4-evaluation
Modern features-part-4-evaluationModern features-part-4-evaluation
Modern features-part-4-evaluation
 
Modern features-part-3-software
Modern features-part-3-softwareModern features-part-3-software
Modern features-part-3-software
 
Modern features-part-2-descriptors
Modern features-part-2-descriptorsModern features-part-2-descriptors
Modern features-part-2-descriptors
 
Modern features-part-1-detectors
Modern features-part-1-detectorsModern features-part-1-detectors
Modern features-part-1-detectors
 
Modern features-part-0-intro
Modern features-part-0-introModern features-part-0-intro
Modern features-part-0-intro
 
Lecture 02 internet video search
Lecture 02 internet video searchLecture 02 internet video search
Lecture 02 internet video search
 
Lecture 01 internet video search
Lecture 01 internet video searchLecture 01 internet video search
Lecture 01 internet video search
 
Lecture 03 internet video search
Lecture 03 internet video searchLecture 03 internet video search
Lecture 03 internet video search
 
Icml2012 tutorial representation_learning
Icml2012 tutorial representation_learningIcml2012 tutorial representation_learning
Icml2012 tutorial representation_learning
 
Advances in discrete energy minimisation for computer vision
Advances in discrete energy minimisation for computer visionAdvances in discrete energy minimisation for computer vision
Advances in discrete energy minimisation for computer vision
 
Gephi tutorial: quick start
Gephi tutorial: quick startGephi tutorial: quick start
Gephi tutorial: quick start
 
EM algorithm and its application in probabilistic latent semantic analysis
EM algorithm and its application in probabilistic latent semantic analysisEM algorithm and its application in probabilistic latent semantic analysis
EM algorithm and its application in probabilistic latent semantic analysis
 
Object recognition with pictorial structures
Object recognition with pictorial structuresObject recognition with pictorial structures
Object recognition with pictorial structures
 
Iccv2011 learning spatiotemporal graphs of human activities
Iccv2011 learning spatiotemporal graphs of human activities Iccv2011 learning spatiotemporal graphs of human activities
Iccv2011 learning spatiotemporal graphs of human activities
 

11 cv mil_models_for_chains_and_trees

  • 1. Computer vision: models, learning and inference Chapter 11 Fitting probability models Please send errata to s.prince@cs.ucl.ac.uk
  • 2. Structure • Chain and tree models • MAP inference in chain models • MAP inference in tree models • Maximum marginals in chain models • Maximum marginals in tree models • Models with loops • Applications Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 2
  • 3. Chain and tree models • Given a set of measurements and world states , infer the world states from the measurements • Problem: if N is large then the model relating the two will have a very large number of parameters. • Solution: build sparse models where we only describe subsets of the relations between variables. Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 3
  • 4. Chain and tree models Chain model: only model connections between world variable and its predecessing and subsequent variables Tree model: connections between world variables are organized as a tree (no loops). Disregard directionality of connections for directed model Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 4
  • 5. Assumptions We’ll assume that – World states are discrete – Observed data variables for each world state – The nth data variable is conditionally independent of all of other data variables and world states given associated world state Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 5
  • 6. Gesture Tracking Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 6
  • 7. Directed model for chains (Hidden Markov model) Compatibility of measurement Compatibility of world state and and world state previous world state Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 7
  • 8. Undirected model for chains Compatibility of measurement Compatibility of world state and and world state previous world state Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 8
  • 9. Equivalence of chain models Directed: Undirected: Equivalence: Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 9
  • 10. Chain model for sign language application Observations are normally distributed but depend on sign k World state is categorically distributed, parameters depend on previous world state Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 10
  • 11. Structure • Chain and tree models • MAP inference in chain models • MAP inference in tree models • Maximum marginals in chain models • Maximum marginals in tree models • Models with loops • Applications Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 11
  • 12. MAP inference in chain model Directed model: MAP inference: Substituting in : Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 12
  • 13. MAP inference in chain model Takes the general form: Unary term: Pairwise term: Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 13
  • 14. Dynamic programming Maximizes functions of the form: Set up as cost for traversing graph – each path from left to right is one possible configuration of world states Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 14
  • 15. Dynamic programming Algorithm: 1. Work through graph computing minimum possible cost to reach each node 2. When we get to last column find minimum 3. Trace back to see how we got there Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 15
  • 16. Worked example Unary cost Pairwise costs 1. Zero cost to stay at same label 2. Cost of 2 to change label by 1 3. Infinite cost for changing by more than one (not shown) Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 16
  • 17. Worked example Minimum cost to reach first node is just unary cost Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 17
  • 18. Worked example Minimum cost is minimum of two possible routes to get here Route 1: 2.0+0.0+1.1 = 3.1 Route 2: 0.8+2.0+1.1 = 3.9 Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 18
  • 19. Worked example Minimum cost is minimum of two possible routes to get here Route 1: 2.0+0.0+1.1 = 3.1 -- this is the minimum – note this down Route 2: 0.5+2.0+1.1 = 3.6 Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 19
  • 20. Worked example General rule: Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 20
  • 21. Worked example Work through the graph, computing the minimum cost to reach each node Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 21
  • 22. Worked example Keep going until we reach the end of the graph Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 22
  • 23. Worked example Find the minimum possible cost to reach the final column Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 23
  • 24. Worked example Trace back the route that we arrived here by – this is the minimum configuration Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 24
  • 25. Structure • Chain and tree models • MAP inference in chain models • MAP inference in tree models • Maximum marginals in chain models • Maximum marginals in tree models • Models with loops • Applications Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 25
  • 26. MAP inference for trees Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 26
  • 27. MAP inference for trees Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 27
  • 28. Worked example Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 28
  • 29. Worked example Variables 1-4 proceed as for the chain example. Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 29
  • 30. Worked example At variable n=5 must consider all pairs of paths from into the current node. Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 30
  • 31. Worked example Variable 6 proceeds as normal. Then we trace back through the variables, splitting at the junction. Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 31
  • 32. Structure • Chain and tree models • MAP inference in chain models • MAP inference in tree models • Maximum marginals in chain models • Maximum marginals in tree models • Models with loops • Applications Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 32
  • 33. Marginal posterior inference • Start by computing the marginal distribution over the Nth variable • Then we`ll consider how to compute the other marginal distributions Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 33
  • 34. Computing one marginal distribution Compute the posterior using Bayes` rule: We compute this expression by writing the joint probability : Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 34
  • 35. Computing one marginal distribution Problem: Computing all NK states and marginalizing explicitly is intractable. Solution: Re-order terms and move summations to the right Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 35
  • 36. Computing one marginal distribution Define function of variable w1 (two rightmost terms) Then compute function of variables w2 in terms of previous function Leads to the recursive relation Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 36
  • 37. Computing one marginal distribution We work our way through the sequence using this recursion. At the end we normalize the result to compute the posterior Total number of summations is (N-1)K as opposed to KN for brute force approach. Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 37
  • 38. Forward-backward algorithm • We could compute the other N-1 marginal posterior distributions using a similar set of computations • However, this is inefficient as much of the computation is duplicated • The forward-backward algorithm computes all of the marginal posteriors at once Solution: ... and take products Compute all first term Compute all second using a recursion terms using a recursion Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 38
  • 39. Forward recursion Conditional probability rule Using conditional independence relations This is the same recursion as before Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 39
  • 40. Backward recursion Conditional probability rule Using conditional independence relations This is another recursion of the form Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 40
  • 41. Forward backward algorithm Compute the marginal posterior distribution as product of two terms Forward terms: Backward terms: Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 41
  • 42. Belief propagation • Forward backward algorithm is a special case of a more general technique called belief propagation • Intermediate functions in forward and backward recursions are considered as messages conveying beliefs about the variables. • Well examine the Sum-Product algorithm. • The sum-product algorithm operates on factor graphs. Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 42
  • 43. Sum product algorithm • Forward backward algorithm is a special case of a more general technique called belief propagation • Intermediate functions in forward and backward recursions are considered as messages conveying beliefs about the variables. • Well examine the Sum-Product algorithm. • The sum-product algorithm operates on factor graphs. Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 43
  • 44. Factor graphs • One node for each variable • One node for each function relating variables Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 44
  • 45. Sum product algorithm Forward pass • Distribute evidence through the graph Backward pass • Collates the evidence Both phases involve passing messages between nodes: • The forward phase can proceed in any order as long as the outgoing messages are not sent until all incoming ones received • Backward phase proceeds in reverse order to forward Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 45
  • 46. Sum product algorithm Three kinds of message • Messages from unobserved variables to functions • Messages from observed variables to functions • Messages from functions to variables Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 46
  • 47. Sum product algorithm Message type 1: • Messages from unobserved variables z to function g • Take product of incoming messages • Interpretation: combining beliefs Message type 2: • Messages from observed variables z to function g • Interpretation: conveys certain belief that observed values are true Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 47
  • 48. Sum product algorithm Message type 3: • Messages from a function g to variable z • Takes beliefs from all incoming variables except recipient and uses function g to a belief about recipient Computing marginal distributions: • After forward and backward passes, we compute the marginal dists as the product of all incoming messages Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 48
  • 49. Sum product: forward pass Message from x1 to g1: By rule 2: Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 49
  • 50. Sum product: forward pass Message from g1 to w1: By rule 3: Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 50
  • 51. Sum product: forward pass Message from w1 to g1,2: By rule 1: (product of all incoming messages) Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 51
  • 52. Sum product: forward pass Message from g1,2 from w2: By rule 3: Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 52
  • 53. Sum product: forward pass Messages from x2 to g2 and g2 to w2: Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 53
  • 54. Sum product: forward pass Message from w2 to g2,3: The same recursion as in the forward backward algorithm Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 54
  • 55. Sum product: forward pass Message from w2 to g2,3: Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 55
  • 56. Sum product: backward pass Message from wN to gN,N-1: Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 56
  • 57. Sum product: backward pass Message from gN,N-1 to wN-1: Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 57
  • 58. Sum product: backward pass Message from gn,n-1 to wn-1: The same recursion as in the forward backward algorithm Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 58
  • 59. Sum product: collating evidence • Marginal distribution is products of all messages at node • Proof: Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 59
  • 60. Structure • Chain and tree models • MAP inference in chain models • MAP inference in tree models • Maximum marginals in chain models • Maximum marginals in tree models • Models with loops • Applications Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 60
  • 61. Marginal posterior inference for trees Apply sum-product algorithm to the tree-structured graph. Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 61
  • 62. Structure • Chain and tree models • MAP inference in chain models • MAP inference in tree models • Maximum marginals in chain models • Maximum marginals in tree models • Models with loops • Applications Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 62
  • 63. Tree structured graphs This graph contains loops But the associated factor graph has structure of a tree Can still use Belief Propagation Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 63
  • 64. Learning in chains and trees Supervised learning (where we know world states wn) is relatively easy. Unsupervised learning (where we do not know world states wn) is more challenging. Use the EM algorithm: • E-step – compute posterior marginals over states • M-step – update model parameters For the chain model (hidden Markov model) this is known as the Baum-Welch algorithm. Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 64
  • 65. Grid-based graphs Often in vision, we have one observation associated with each pixel in the image grid. Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 65
  • 66. Why not dynamic programming? When we trace back from the final node, the paths are not guaranteed to converge. Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 66
  • 67. Why not dynamic programming? Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 67
  • 68. Why not dynamic programming? But: Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 68
  • 69. Approaches to inference for grid-based models 1. Prune the graph. Remove edges until an edge remains Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 69
  • 70. Approaches to inference for grid-based models 2. Combine variables. Merge variables to form compound variable with more states until what remains is a tree. Not practical for large grids Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 70
  • 71. Approaches to inference for grid-based models 3. Loopy belief propagation. Just apply belief propagation. It is not guaranteed to converge, but in practice it works well. 4. Sampling approaches Draw samples from the posterior (easier for directed models) 5. Other approaches • Tree-reweighted message passing • Graph cuts Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 71
  • 72. Structure • Chain and tree models • MAP inference in chain models • MAP inference in tree models • Maximum marginals in chain models • Maximum marginals in tree models • Models with loops • Applications Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 72
  • 73. Gesture Tracking Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 73
  • 74. Stereo vision • Two image taken from slightly different positions • Matching point in image 2 is on same scanline as image 1 • Horizontal offset is called disparity • Disparity is inversely related to depth • Goal – infer disparities wm,n at pixel m,n from images x(1) and x(2) Use likelihood: Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 74
  • 75. Stereo vision Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 75
  • 76. Stereo vision 1. Independent pixels Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 76
  • 77. Stereo vision 2. Scanlines as chain model (hidden Markov model) Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 77
  • 78. Stereo vision 3. Pixels organized as tree (from Veksler 2005) Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 78
  • 79. Pictorial Structures Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 79
  • 80. Pictorial Structures Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 80
  • 81. Segmentation Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 81
  • 82. Conclusion • For the special case of chains and trees we can perform MAP inference and compute marginal posteriors efficiently. • Unfortunately, many vision problems are defined on pixel grid – this requires special methods Computer vision: models, learning and inference. ©2011 Simon J.D. Prince 82