Top Banner
Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees
82

Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Dec 25, 2015

Download

Documents

Whitney Oliver
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Computer vision: models, learning and inference

Chapter 11 Models for Chains and Trees

Page 2: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

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

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

Page 3: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

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.

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

Page 4: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Chain and tree models

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

Chain model: only model connections between a world variable and its 1 predeeding and 1 subsequent variables

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

Page 5: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Assumptions

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

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

Page 6: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

See also: Thad Starner’s work

Gesture Tracking

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

Page 7: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Directed model for chains(Hidden Markov model)

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

Compatibility of measurement and world state

Compatibility of world state and previous world state

Page 8: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Undirected model for chains

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

Compatibility of measurement and world state

Compatibility of world state and previous world state

Page 9: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Equivalence of chain models

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

Directed:

Undirected:

Equivalence:

Page 10: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Chain model for sign language application

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

Observations are normally distributed but depend on sign k

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

Page 11: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

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

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

Page 12: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

MAP inference in chain model

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

MAP inference:

Substituting in :

Directed model:

Page 13: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

MAP inference in chain model

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

Takes the general form:

Unary term:

Pairwise term:

Page 14: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Dynamic programming

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

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

Page 15: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Dynamic programming

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

Algorithm:

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

Page 16: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Worked example

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

Unary cost Pairwise costs: • Zero cost to stay at same label• Cost of 2 to change label by 1• Infinite cost for changing by more

than one (not shown)

Page 17: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Worked example

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

Minimum cost to reach first node is just unary cost

Page 18: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Worked example

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

Minimum cost is minimum of two possible routes to get here

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

Page 19: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Worked example

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

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 downRoute 2: 0.8+2.0+1.1 = 3.9

Page 20: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Worked example

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

General rule:

Page 21: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Worked example

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

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

Page 22: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Worked example

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

Keep going until we reach the end of the graph

Page 23: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Worked example

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

Find the minimum possible cost to reach the final column

Page 24: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Worked example

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

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

Page 25: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

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

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

Page 26: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

MAP inference for trees

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

Page 27: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

MAP inference for trees

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

Page 28: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Worked example

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

Page 29: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Worked example

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

Variables 1-4 proceed as for the chain example.

Page 30: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Worked example

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

At variable n=5 must consider all pairs of paths from into the current node.

Page 31: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Worked example

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

Variable 6 proceeds as normal.

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

Page 32: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

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

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

Page 33: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Marginal posterior inference

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

• Start by computing the marginal distribution over the Nth variable

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

Page 34: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Computing one marginal distribution

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

Compute the posterior using Bayes` rule:

We compute this expression by writing the joint probability :

Page 35: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Computing one marginal distribution

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

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

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

Page 36: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Computing one marginal distribution

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

Define function of variable w1 (two rightmost terms)

Then compute function of variables w2 in terms of previous function

Leads to the recursive relation

Page 37: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Computing one marginal distribution

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

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.

Page 38: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Forward-backward algorithm

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

• 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:

Compute all first term using a recursion

Compute all second terms using a recursion

... and take products

Page 39: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Forward recursion

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

Using conditional independence relations

Conditional probability rule

This is the same recursion as before

Page 40: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Backward recursion

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

Using conditional independence

relations

Conditional probability rule

This is another recursion of the form

Page 41: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Forward backward algorithm

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

Compute the marginal posterior distribution as product of two terms

Forward terms:

Backward terms:

Page 42: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Belief propagation

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

• 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.

• We’ll examine the Sum-Product algorithm.

• The sum-product algorithm operates on factor graphs.

Page 43: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Sum product algorithm

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

• 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.

• We’ll examine the Sum-Product algorithm.

• The sum-product algorithm operates on factor graphs.

Page 44: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Factor graphs

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

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

Page 45: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Sum product algorithm

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

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

Page 46: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Sum product algorithm

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

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

Page 47: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Sum product algorithm

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

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

Page 48: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Sum product algorithm

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

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

Page 49: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Sum product: forward pass

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

Message from x1 to g1:

By rule 2:

Page 50: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Sum product: forward pass

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

Message from g1 to w1:

By rule 3:

Page 51: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Sum product: forward pass

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

Message from w1 to g1,2:

By rule 1:

(product of all incoming messages)

Page 52: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Sum product: forward pass

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

Message from g1,2 from w2:

By rule 3:

Page 53: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Sum product: forward pass

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

Messages from x2 to g2 and g2 to w2:

Page 54: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Sum product: forward pass

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

Message from w2 to g2,3:

The same recursion as in the forward backward algorithm

Page 55: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Sum product: forward pass

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

Message from w2 to g2,3:

Page 56: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Sum product: backward pass

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

Message from wN to gN,N-1:

Page 57: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Sum product: backward pass

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

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

Page 58: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Sum product: backward pass

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

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

The same recursion as in the forward backward algorithm

Page 59: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Sum product: collating evidence

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

• Marginal distribution is products of all messages at node

• Proof:

Page 60: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

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

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

Page 61: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Marginal posterior inference for trees

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

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

Page 62: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

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

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

Page 63: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Tree structured graphs

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

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

Can still use Belief Propagation

Page 64: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Learning in chains and trees

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

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.

Page 65: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Grid-based graphs

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

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

Page 66: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Why not dynamic programming?

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

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

Page 67: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Why not dynamic programming?

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

Page 68: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Why not dynamic programming?

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

But:

Page 69: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Approaches to inference for grid-based models

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

1. Prune the graph.

Remove edges until an edge remains

Page 70: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

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

2. Combine variables.

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

Approaches to inference for grid-based models

Page 71: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

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

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

Page 72: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

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

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

Page 73: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

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

Gesture Tracking

Page 74: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Stereo vision

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

• 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:

Page 75: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Stereo vision

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

Page 76: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Stereo vision

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

1. Independent pixels

Page 77: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Stereo vision

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

2. Scanlines as chain model (hidden Markov model)

Page 78: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Stereo vision

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

3. Pixels organized as tree (from Veksler 2005)

Page 79: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Pictorial Structures

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

Page 80: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Pictorial Structures

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

Page 81: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Segmentation

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

Page 82: Computer vision: models, learning and inference Chapter 11 Models for Chains and Trees.

Conclusion

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

• 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