Transcript Sketch Recognition for Digital Circuit Diagrams in the Classroom Christine Alvarado
Sketch Recognition for Digital Circuit Diagrams in the Classroom Christine Alvarado Harvey Mudd College March 26, 2007 Joint work with the HMC Sketchers group:
Aaron Wolin
,
Ned Burns
, Jason Fennell, Max Pfleuger, Devin Smith, Paul Wais, Howard Chen, Matt Weiner, Prof. Sarah Harris
Sketching In Education Digital Circuit Design
Educational Technologies "Most of the time the lab was more about battling Xilinx than actually learning anything useful" –HMC, E85 student
Problem: Design a 1-bit full adder
Cin 0 0 0 0 1 1 1 1 B 0 0 1 1 0 0 1 1 A 0 1 0 1 0 1 0 1 Cout 0 0 0 1 0 1 1 1 Sum 0 1 1 0 1 0 0 0
AND-2
Correct!
AND-2 OR-2 XOR-2 XOR-2
Goals Build a sketch-based circuit simulation tool that: – is robust enough for real use – allows students to sketch as freely as possible – is easier to use than current software We need: – An integrated circuit simulation system – Improved free-sketch recognition algorithms – An understanding of user interface issues
Integrated System Overview Front End hand-drawn sketch Circuit Recognition and Translation Verilog file Simulation (Xilinx)
Integrated System Overview Front End hand-drawn sketch User Interface Design Recognize Symbols Construct Circuit Translate to Verilog Free-sketch Recognition Diagram Parsing Verilog file Simulation (Xilinx)
Sketch Recognition Subtasks Stroke Fragmentation
NOR
Symbol Recognition Stroke Grouping
A Typical Approach to Recognition Stroke Fragmentation Stroke Grouping Symbol Recognition
A Typical Approach to Recognition: Problem incorrect grouping
Why is Grouping Hard?
• No clear boundaries in space…
Why is Grouping Hard?
• No clear boundaries in space or time Same Shape New Shape 4500 4000 3500 3000 2500 2000 1500 1000 500 0 0 1 2 3 4 5 6 7 User ID 8 9 10 11 12 13
A Typical Approach to Recognition: Problem ???
Stroke Grouping cannot be done without recognition (But recognition cannot be done without stroke grouping)
Our Approach Stroke Fragmentation Single-Stroke Recognition Stroke Grouping Symbol Recognition
Our Approach Stroke Fragmentation Single-Stroke Recognition Stroke Grouping Symbol Recognition
Single-Stroke Recognition • Goal: Label each stroke as WIRE, GATE or SIGNAL gate gate wire gate signal wire gate wire • Method: Conditional Random Field Approach based on Yuan Qi, Martin Szummer, Thomas P. Minka.
Diagram Structure Recognition by Bayesian Conditional Random Fields
June 2005
Proc Comp. Vision Pattern Recogn. (CVPR)
C. Schmid and S. Soatto and C. Tomasi 191--196
Conditional Random Field (CRF) • Determines P(
y
|
x
) –
y
: vector of labels ( wire fragment (stroke) or gate ), one for each –
x
: set of all observations (stroke features)
Single-Stroke Classification Demo
Training the CRF: Data Collection and Labeling
Data Collection • Goal: Free sketching in engineering education • Method: – Distributed Tablet Computers to ~35 students in HMC E85 (digital circuit design) and E84 (analog circuit design) – Collected sketches from notes, homeworks, and labs But what about labeling?
Labeling Tasks • Stroke Fragmentation • Stroke Grouping and Labeling
Labeler Demo
Designing the UI • User Study to examine: – Recognition Triggers (button, gesture, pause) – Feedback mechanisms (color, symbol, text) – Error Rates and Types • Preliminary Results – Users prefer active recognition trigger – Trigger must be reliable – Users rarely trigger recognition
(Some Immediate) Future Work Stroke Fragmentation Single-Stroke Recognition Stroke Grouping Multi-class recognition wire vs. gate vs. signal Symbol Recognition
Conclusion • Single-stroke recognition grouping + recognition Improved • Direct manipulation labeling more complete datasets • Robust free-sketch recognition lower barriers to learning
Extra Slides
Nodes for every stroke (fragment)
Edges between related fragments
Example of a label set
CRF Probability Distribution
P
(
y
The probability of a set of labels given data Want to maximize P(y|x) |
x
) 1
Z
( )
i
V e
v
g i
(
x
) {
i
,
j
}
E e
w
f
i
,
j
(
x
) Normalizing term Local compatibility with labels Compatibility based on context Normalize by sum over all possible label sets. Nasty term
Z
( )
y
i
V e
v
g i
(
x
) {
i
,
j
}
E e
w
f
i
,
j
(
x
) Need approximation to make this computationally feasible
Feature functions P(
y
|
x
) What are these observations?
• CRF cannot use raw stroke data • Feature functions extract useful numerical data • Vector of data extracted for each node and pair of adjacent nodes
Parameters • Relative usefulness of features for classification needs to be accounted for • Parameters act as weights for individual features • Weighted features combined with a sum • Represented with a dot product
i a i b i
a
b
Site Potentials • Measure compatibility between labels and a node • The exponential makes the math nicer • All potentials combined with a product
i
V
weight vector
v
e
g i
(
x
feature function ) Site Potential
Interaction Potentials • Where the CRF gets its power • Uses context by measuring compatibility between pairs of adjacent nodes and pairs of labels • Mathematically, same story as site potentials {
i
,
j
} weight vector
w
E e f
i
,
j
( feature function
x
) Interaction Potential
What does a CRF need?
• Gather data on the sketch and individual strokes ( feature functions ) • Determine weights ( training ) • Maximize P(
y
|
x
) in a computationally feasible way ( inference ) – Not going to talk about this
Feature Functions • Can’t pass stroke data directly into the CRF • Feature functions translate raw stroke data into simple linear values that the CRF can act on • We required returned values to be in the range of [-1, 1] – In theory other ranges work, but we had problems with them
Mathematical Limitations • The CRF must respond linearly to the values returned by feature functions
P
(
y
|
x
) 1
Z
( )
i
V e
v
g i
(
x
) {
i
,
j
}
E e
w
f
i
,
j
(
x
) • This can be problematic if the returned value has physical meaning, like the length of a stroke – To deal with features like length we created a couple of different features for whether the length was within a certain range
Site Feature: Turning • Calculates the total quantity of rotation in a stroke • After calculating the value of Turning, we returned four different values for different regions • To see why we need to do this, consider the red, blue, and green strokes below
Interaction Feature: T-Junction • Detects whether two strokes are configured in a T-Junction with each other – Might occur where a wire meets a gate • Note that this function is non-symmetric – We have to differentiate the cross from the stem of a T-Junction – We use two identical versions of this function with the arguments reversed
Parameters • We still need a list of weights or parameters relating every site feature to every label, and every interaction feature to every pair of labels
P
(
y
|
x
) 1
Z
( )
i
V e
v
g i
(
x
) {
i
,
j
}
E e
w
f
i
,
j
(
x
) • Must
learn
parameters from labeled data
Likelihood function • The likelihood function is a representation of how well a given set of parameters classifies a given data set
P
x
,
y
(-log(likelihood))
log
x
,
y
to make the math simpler • Training allows us to find arg min log
P
w w
,
v x
,
y
Training: Idea • How can we minimize log
P
x
,
y
?
– Take the derivative and set it to 0?
• Equation is too complicated – Gradient descent: Locally follow the gradient down to the lowest point (hopefully!) log
P
[evaluated on
x
, training data]
y
[w,v] optimal parameters
Future Work • More / better feature functions • Computational issues – Numerical under- and overflow • Multi-Pass CRFs – Find Gates and Wires – Train the CRF again on the gates, distinguishing the type of gate • Circuit understanding, interface with Xilinx