From Images to Layouts: Combining Deep Learning and Program - - PowerPoint PPT Presentation

from images to layouts
SMART_READER_LITE
LIVE PREVIEW

From Images to Layouts: Combining Deep Learning and Program - - PowerPoint PPT Presentation

From Images to Layouts: Combining Deep Learning and Program Synthesis Pavol Bielik , Marc Fischer, Martin Vechev Department of Computer Science ETH Zurich Big Code @ ETH Last 5 Years jsnice.org JavaScript Android C/C++ Binaries


slide-1
SLIDE 1

From Images to Layouts:

Combining Deep Learning and Program Synthesis

Pavol Bielik, Marc Fischer, Martin Vechev Department of Computer Science ETH Zurich

slide-2
SLIDE 2

Big Code @ ETH

Last 5 Years

slide-3
SLIDE 3

jsnice.org

slide-4
SLIDE 4

jsnice.org

JavaScript Android C/C++ Binaries

slide-5
SLIDE 5

www.deepcode.ai/

slide-6
SLIDE 6

www.deepcode.ai/

slide-7
SLIDE 7

Big Code: last 5 years @ ETH

Learning Over Programs

Deobfuscation Code Review Writing Code

PHOG

Probabilistic Higher Order Grammar Inferring Crypto API Rules from Code Changes. PLDI’18 Neural Code Comprehension: A Learnable Representation of Code Semantics. NIPS’18 Program Synthesis for Character Level Language Modeling. ICLR’17 Probabilistic Model for Code with Decision Trees. OOPSLA’16 Learning Programs from Noisy Data. POPL’16 Code Completion With Statistical Language Models. PLDI’14 Predicting Program Properties from “Big Code”. POPL’15, CACM’18 DEBIN: Predicting Debug Information in Stripped Binaries. CCS’18 Statistical Deobfuscation of Android Applications. CCS’16

http://plml.ethz.ch

slide-8
SLIDE 8

Big Code: last 5 years @ ETH

Learning Over Programs

Deobfuscation Code Review Writing Code

PHOG

Probabilistic Higher Order Grammar

Learning Programs

Static Analysis Solving SMT Formulas User Interface Layouts

function collect(val, idx, obj) { if (val >= this.threshold) { ... } } dat.filter( collect, ctx );

points-to

slide-9
SLIDE 9

Martin Vechev Veselin Raychev Pavol Bielik Svetoslav Karaivanov Christine Zeller Pascal Roos Benjamin Bischel Benjamin Mularczyk Mateo Panzacchi Petar Tsankov Timon Gehr

Big Code: last 5 years @ ETH

Marc Fischer

slide-10
SLIDE 10

picture created by

User Interface Design Today

[Credits: Radu Cristian]

Designer Developer

slide-11
SLIDE 11

Designer

slide-12
SLIDE 12

Materialize

GroundworkCSS 2

Cardinal

Developer

slide-13
SLIDE 13

User Interface Design Today

Designer Developer

slide-14
SLIDE 14

Our Goal

Designer Developer Tool

slide-15
SLIDE 15

Preventing Layout Errors

Nexus 4 Alcatel Pop 3

slide-16
SLIDE 16

Preventing Layout Errors

Nexus 4 Alcatel Pop 3

slide-17
SLIDE 17

Preventing Layout Errors

Centering Overlaying Views Out of Screen Asobimasu Amigo Candid

slide-18
SLIDE 18

Improving Performance

Layout #1 Layout #2

[Credits: Sriram Ramani]

Layout #3

Slow Fast

slide-19
SLIDE 19

Code Porting

Old / Deprecated

Linear Layout (horizontal) Linear Layout (vertical) Relative Layout Constraint Layout

>98% <2%

slide-20
SLIDE 20

picture created by

[Credits: Radu Cristian]

Designer Developer

Automating End-User Design

slide-21
SLIDE 21

Button Text Text Image

Component Detection

Button

Button Button

SIGN IN

Font Family Font Size Corner Radius Background Color Roboto 12 pt Shadow 0 dp Border Width 0 dp ...

Attribute Prediction

Attributes

Image Image Image Button Button Button Text Text

Layout Synthesis

Layout

slide-22
SLIDE 22

Button Text Text Image

Component Detection

Button

Button Button

SIGN IN

Font Family Font Size Corner Radius Background Color Roboto 12 pt Shadow 0 dp Border Width 0 dp ...

Attribute Prediction

Attributes

Image Image Image Button Button Button Text Text

Layout Synthesis

Layout

slide-23
SLIDE 23

Machine Learning Approach

✘ Syntactically Incorrect ✘ No Formal Guarantees ✘ Robustness ✘ User Feedback Design Specification

Layout

</> Training

slide-24
SLIDE 24

Programming Languages Approach

Design Specification

Layout Formalization List of Devices Probabilistic Model User Feedback Robustness Properties

Layout

</>

Layout Synthesis

slide-25
SLIDE 25

Relational Layout Constraints

View

top baseline bottom

B A Align left of B to right of A

margin

B.left = A.right + margin

View

left right

slide-26
SLIDE 26

Relational Layout Constraints

View

top baseline bottom

View

left right

B A Align left of B to right of A

margin

B.left = A.right + 0

B A A B ✘

slide-27
SLIDE 27

Relational Layout Constraints

View

top baseline bottom

View

left right

B A Align left of B to right of A

margin

B A B A C Center B in between right of A and left of C A B ✘

B.left = A.right + margin

slide-28
SLIDE 28

Relational Layout Constraints

View

top baseline bottom

View

left right

B A Align left of B to right of A

margin

B A Center B in between right of A and left of C A B ✘

B.left = A.right + margin

B A C

margin

slide-29
SLIDE 29

Relational Layout Constraints

View

top baseline bottom

View

left right

B A Align left of B to right of A

margin

B A Center B in between right of A and left of C A B ✘

B.left = A.right + margin

B A C

mL bias = 0.25

slide-30
SLIDE 30

Relational Layout Constraints

View

top baseline bottom

View

left right

B A Align left of B to right of A

margin

B A Center B in between right of A and left of C A B ✘

B.left = A.right + margin

B A C

mL bias = 0.25

B A C

margin

Center B in between right of A and left of C (Dynamic Size)

slide-31
SLIDE 31

Relational Layout Constraints

View

top baseline bottom

View

left right

Center B in between right of A and left of C B A C

mL bias = 0.25

(1-b)*B.left + b*B.right = (1-b)*(A.right + mL) + b*(C.left - mR)

A B

r

α

Align Center of A to Center of B at an Angle + Distance B A C

margin

Center B in between right of A and left of C (Dynamic Size)

B.left = A.right + mL ∧ B.right = A.left + mR

B.left + B.right = 2r*sin(α) + A.left + A.right

slide-32
SLIDE 32

B.left + B.right = 2r*sin(α) + A.left + A.right

Relational Layout Constraints

View

top baseline bottom

View

left right

Center B in between right of A and left of C B A C

mL bias = 0.25

(1-b)*B.left + b*B.right = (1-b)*(A.right + mL) + b*(C.left - mR)

A B

r

α

Align Center of A to Center of B at an Angle + Distance B A C

margin

Center B in between right of A and left of C (Dynamic Size)

B.left = A.right + mL ∧ B.right = A.left + mR

Formalized 26 types of constraints used by the latest Android Constraint Layout

slide-33
SLIDE 33

Overview

Layout Formalization Robustness Properties User Feedback List of Devices Probabilistic Model

Design Specification

Layout

</>

Layout Synthesis

slide-34
SLIDE 34

Layout Solving

Goal Compute absolute position of all the views left right top bottom

slide-35
SLIDE 35

screen: Target Device c: Horizontal Position Constraints

Layout Solving

B A

40

B.left = A.right + 40 Goal Compute absolute position of all the views A.left = screen.left + 20

20

screen.left = 0 ∧ screen.right = 240 B.left = ? B.right = ? A.left = ? A.right = ? v: Absolute Horizontal Positions

slide-36
SLIDE 36

screen: Target Device c: Horizontal Position Constraints v: Absolute Horizontal Positions

Layout Solving

B A

40

B.left = A.right + 40 Goal Compute absolute position of all the views B.left = ? B.right = ? A.left = 20 A.right = ? A.left = 0 + 20

20

screen.left = 0 ∧ screen.right = 240

slide-37
SLIDE 37

Layout Solving

B A

40

Goal Compute absolute position of all the views B.left = 140 B.right = 220 A.left = 20 A.right = 100

20

s: Horizontal Size Constraints screen: Target Device c: Horizontal Position Constraints B.left = A.right + 40 A.left = 0 + 20 screen.left = 0 ∧ screen.right = 240 A.right - A.left = 80 B.right - B.left = 80 v ⊧ ψlayout(screen, c, s) v: Absolute Horizontal Positions

slide-38
SLIDE 38

Layout Solving vs Layout Synthesis

B A

40

Goal Compute absolute position of all the views B.left = ? B.right = ? A.left = ? A.right = ?

20

B.left = A.right + 40 A.left = screen.left + 20 screen.left = 0 ∧ screen.right = 240 A.right - A.left = 80 B.right - B.left = 80

B A

40

Goal Synthesize position and size constraints B.left = 120 B.right = 200 A.left = 0 A.right = 80

20

? ? screen.left = 0 ∧ screen.right = 240 ? ? v ⊧ ψlayout(screen, c, s) c ∧ s ⊧ ψsyn(screen, v)

slide-39
SLIDE 39

Layout Solving vs Layout Synthesis

B A

40

Goal Compute absolute position of all the views B.left = ? B.right = ? A.left = ? A.right = ?

20

B.left = A.right + 40 A.left = screen.left + 20 screen.left = 0 ∧ screen.right = 240 A.right - A.left = 80 B.right - B.left = 80

B A

40

Goal Synthesize position and size constraints B.left = 120 B.right = 200 A.left = 0 A.right = 80

20

? ? screen.left = 0 ∧ screen.right = 240 ? ? v ⊧ ψlayout(screen, c, s) c ∧ s ⊧ ψsyn(screen, v)

Approach

  • 1. Encode the synthesis program as a logical

formula ψsyn(screen, v)

  • 2. Find a satisfying assignment to

c ∧ s ⊧ ψsyn(screen, v)

slide-40
SLIDE 40

Ensure Constraints are Valid Constraints Encoding Input Specification

Layout Synthesis

ψsyn(screen, v) = φposition(screen, v) ∧ φconstraints(v) ∧ φvalid(v) ∧ φacyclic(v)

slide-41
SLIDE 41

Ensure Constraints are Valid Constraints Encoding Input Specification

Layout Synthesis

ψsyn(screen, v) = φposition(screen, v) ∧ φconstraints(v) ∧ φvalid(v) ∧ φacyclic(v) φposition ≝ screen.left = 0 ∧ screen.right = 240 ∧ A.left = 0 ∧ A.right = 80 ∧ B.left = 120 ∧ B.right = 200

slide-42
SLIDE 42

Ensure Constraints are Valid Constraints Encoding Input Specification

Layout Synthesis

ψsyn(screen, v) = φposition(screen, v) ∧ φconstraints(v) ∧ φvalid(v) ∧ φacyclic(v)

slide-43
SLIDE 43

Layout Synthesis

What are the possible constraints for view B? C(B, v, screen) = {cB, cB, cB, … , cB} C(B, v, screen) = {c1, c2, c3, … , cn}

slide-44
SLIDE 44

Layout Synthesis

B A What are the possible constraints for view B? B A B A C(B, v, screen) = {cB, cB, cB, … , cB} C(B, v, screen) = {c1, c2, c3, … , cn} B.left = A.right + mL (c1) (1-b)*B.left + b*B.right = (1-b)*(A.right + mL) + b*(screen.right - mR) (c3) O(|v|2) B.left = screen.right + mL (c2)

slide-45
SLIDE 45

Layout Synthesis

B A What are the possible constraints for view B? B A B A C(B, v, screen) = {cB, cB, cB, … , cB} C(B, v, screen) = {c1, c2, c3, … , cn} B.left = A.right + mL (c1) (1-b)*B.left + b*B.right = (1-b)*(A.right + mL) + b*(screen.right - mR) (c3) O(|v|2) Select exactly one constraint for each view B.left = screen.right + mL (c2)

slide-46
SLIDE 46

Layout Synthesis

What are the possible constraints for view B? C(B, v, screen) = {cB, cB, cB, … , cB} C(B, v, screen) = {c1, c2, c3, … , cn} g1 ⇒ (B.left = A.right + mL) (c1) g2 ⇒ (B.left = A.left + mL) (c2) … gn ⇒ ((1-b)*B.left + b*B.right = …) (cn) O(|v|2) Select exactly one constraint for each view Boolean variables denoting whether constraint was selected

slide-47
SLIDE 47

View constraints

Layout Synthesis

What are the possible constraints for view B? C(B, v, screen) = {cB, cB, cB, … , cB} C(B, v, screen) = {c1, c2, c3, … , cn} g1 ⇒ (B.left = A.right + mL) (c1) g2 ⇒ (B.left = A.left + mL) (c2) … gn ⇒ ((1-b)*B.left + b*B.right = …) (cn) O(|v|2) Boolean variables denoting whether constraint was selected

φconstraints(screen, v) ≝ gk ⇒ ⟦ck⟧ ∧ g0 + … + g|C(B, v, screen)| = 1

k = 0 C(B, v, screen)

( )

Select exactly one constraint for each view

slide-48
SLIDE 48

View constraints Select exactly one constraint for each view

Layout Synthesis

What are the possible constraints for view B? C(B, v, screen) = {cB, cB, cB, … , cB} C(B, v, screen) = {c1, c2, c3, … , cn} g1 ⇒ (B.left = A.right + mL) (c1) g2 ⇒ (B.left = A.left + mL) (c2) … gn ⇒ ((1-b)*B.left + b*B.right = …) (cn) O(|v|2) Boolean variables denoting whether constraint was selected

φconstraints(screen, v) ≝ gk ⇒ ⟦ck⟧ ∧ g0 + … + g|C(v, v, screen)| = 1

k = 0 C(v, v, screen)

i = 0 |v|

( )

i i i i

i

i

slide-49
SLIDE 49

Ensure Constraints are Valid Constraints Encoding Input Specification

Layout Synthesis

ψsyn(screen, v) = φposition(screen, v) ∧ φconstraints(v) ∧ φvalid(v) ∧ φacyclic(v)

slide-50
SLIDE 50

Ensure Constraints are Valid Constraints Encoding Input Specification

Layout Synthesis

B A

ψsyn(screen, v) = φposition(screen, v) ∧ φconstraints(v) ∧ φvalid(v) ∧ φacyclic(v) φvalid(v) ≝ (mL ≥ 0) ∧ (mR ≥ 0) ∧ (0 ≤ b ≤ 1) ∧ (0 ≤ α < 360) ∧ (r ≥ 0) φacyclic(v) ≝

slide-51
SLIDE 51

Ensure Constraints are Valid Constraints Encoding Input Specification

Layout Synthesis

ψsyn(screen, v) = φposition(screen, v) ∧ φconstraints(v) ∧ φvalid(v) ∧ φacyclic(v)

c ∧ s ⊧ ψsyn(screen, v)

ψsyn(screen, v) Solver c ∧ s

slide-52
SLIDE 52

Ensure Constraints are Valid Constraints Encoding Input Specification

Layout Synthesis

ψsyn(screen, v) = φposition(screen, v) ∧ φconstraints(v) ∧ φvalid(v) ∧ φacyclic(v)

c ∧ s ⊧ ψsyn(screen, v)

ψsyn(screen, v) c ∧ s Are We Done? No Solver

slide-53
SLIDE 53

Ensure Constraints are Valid Constraints Encoding Input Specification

Layout Synthesis

ψsyn(screen, v) = φposition(screen, v) ∧ φconstraints(v) ∧ φvalid(v) ∧ φacyclic(v)

Are We Done? No

Scalability max 4 views Generalization

13%

Considers only Single Device

slide-54
SLIDE 54

Ensure Constraints are Valid Constraints Encoding Input Specification

Layout Synthesis

ψsyn(screen, v) = φposition(screen, v) ∧ φconstraints(v) ∧ φvalid(v) ∧ φacyclic(v)

Are We Done? No

Generalize to Multiple Devices Natural Layouts User Feedback Considers only Single Device

slide-55
SLIDE 55

Natural Layouts

ψsyn(screen, v) = φposition(screen, v) ∧ φconstraints(v) ∧ φvalid(v) ∧ φacyclic(v) synthesize any layout that satisfies the specification the most likely

log P(ci | screen, v)

i = 0 |c|

max

Probability of each selected constraint according to learned probabilistic model

ψsyn(screen, v) c ∧ s Solver

slide-56
SLIDE 56

Natural Layouts

ψsyn(screen, v) = φposition(screen, v) ∧ φconstraints(v) ∧ φvalid(v) ∧ φacyclic(v)

log P(ci | screen, v)

i = 0 |c|

max

Probability of each selected constraint according to learned probabilistic model

75%

Generalization

13%

Scalability max 4 views

12 views

slide-57
SLIDE 57

Probabilistic Model

B A B A Learn a probabilistic model that predicts likelihood that a constraint is used

P(c | screen, v) ⟶ <0, 1>

B A Which constraint is most likely? ✔

slide-58
SLIDE 58

Probabilistic Model

B A B A Learn a probabilistic model that predicts likelihood that a constraint is used

P(c | screen, v) ⟶ <0, 1>

B A B A B A B A ✔ ✔

slide-59
SLIDE 59

Probabilistic Model

B A B A Learn a probabilistic model that predicts likelihood that a constraint is used

P(c | screen, v) ⟶ <0, 1>

B A B A B A B A B A B A B A ✔ ✔ ✔

slide-60
SLIDE 60

Probabilistic Model

fm Margins fb Bias

<mL, mR> b

fd Distance B A fo Orientation B A fs Size B ft Constraint Type B A fi Intersection B A

All Trained using Maximum Likelihood Estimation

fc Complexity

b == 0 mL == 0, mR == 0 1 Z(screen, v) P(c | screen, v) = Pf (c | fk(c, screen, v))

wk

slide-61
SLIDE 61

Generalize to Multiple Devices

Synthesis

Layout

</>

  • 1. Synthesize Layout Using Input Specification
  • 2. Render on Multiple Devices
  • 3. Check that Synthesized Layout Generalizes
slide-62
SLIDE 62

Generalize to Multiple Devices

c ∧ s ⊧ ψsyn(screen, v)

Layout

</>

  • 1. Synthesize Layout Using Input Specification
  • 2. Render on Multiple Devices
  • 3. Check that Synthesized Layout Generalizes

φpreserve_aspect_ratio(v, vd) ∧ φinside_screen(d, vd) ∧ φpixel_perfect(vd) ∧ φpreserve_order(v, vd) ∧ φpreserve_centering(v, vd) ∧ φpreserve_margins(v, vd)

Set of Robustness Properties

vd ⊧ ψlayout(d, v, c, s) All Steps Encoded as a Single Formula!

slide-63
SLIDE 63

User Feedback

Layout

</>

slide-64
SLIDE 64

User Feedback

Layout

</>

User Feedback φuser_feedback ≝ Bk.left = 120 ∧ Bk.right = 200

slide-65
SLIDE 65

Layout Synthesis

Design Specification

Layout Formalization List of Devices Probabilistic Model User Feedback Robustness Properties

Layout

</>

Layout Synthesis

slide-66
SLIDE 66

Evaluation

Top 500 Top 500

slide-67
SLIDE 67

Evaluation

Synthesis Success Ratio / Runtime [2, 4) [4, 8) [8, 12) [12, 16) 100%

37 ms

100%

59 ms

100%

129 ms

100%

519 ms Number of Views

Single Device 99%

44 ms

93%

95 ms

73%

314 ms

56%

3 s

Multi Device

Success Ratio Average Synthesis Time

slide-68
SLIDE 68

Layout

</>

View Generalization

13%

75%

+ Probabilistic Model

92%

+ Robustness Properties ψsingle_syn(screen, v) Percentage of Views That Correctly Generalize

slide-69
SLIDE 69

Layout

</>

User Feedback

63%

no feedback

25%

1 feedback

8%

2 feedbacks

4%

3+ feedbacks Number of User Feedbacks Required

slide-70
SLIDE 70

Layout Errors

¬φpreserve_aspect_ratio ¬φinside_screen ¬φpixel_perfect ¬φpreserve_order ¬φpreserve_centering ¬φpreserve_margins

21

(4%)

41

(8.5%)

4

(0.8%)

19

(4%)

24

(5%)

16

(3.3%)

slide-71
SLIDE 71

Button Text Text Image

Component Detection

Button

Image Image Image Button Button Button Text Text

Layout Synthesis

Layout

slide-72
SLIDE 72

Component Detection Button Object Detection Dog Ball Person Button Button TextView TextView Image

Component Detection

slide-73
SLIDE 73

? ? ? ? ? ? ? ? ?

Image Classification

slide-74
SLIDE 74

Image Classification

Dog Ball Person ... 85% 12% 1% Low level Medium level High level Feature Visualization [Zeiler & Fergus 2013]

slide-75
SLIDE 75

Feature Extraction

Dog Ball Person ... 85% 12% 1% Trainable Classifier Image Features

slide-76
SLIDE 76

Component Detection

Features Object Class classification TextView EditView Button Image ... 71% 18% 9% 2% 360 50 200 40 Object Position regression x y width height

slide-77
SLIDE 77

Component Detection

How to detect regions containing objects? Check all of the possible locations on the screen

Sliding window Aspect Ratio & Size

a lot

slide-78
SLIDE 78

Region Proposal Network

Object? Object Position classification regression x y width height Yes No 71% 29% 360 50 200 40 Features Filtering & Merging

slide-79
SLIDE 79

Component Detection: Putting it Together

End-to-end Trainable Neural Network

Faster R-CNN. Shaoqing Ren, Kaiming He, Ross Girshick, Jian Sun. NIPS’15

Region Proposal Network Object Class Object Position Features

slide-80
SLIDE 80

Evaluation

8 000

Screenshots

100 000

Views

15

Classes

4 days

Training

0.23 s

Query

slide-81
SLIDE 81

Evaluation

8 000

Screenshots

Ads Web View / Images Screen Overlay

Button

Obfuscation

aa bc x

100 000

Views

15

Classes Significant part of the dataset was removed due to:

slide-82
SLIDE 82

REMAUI: Reverse Engineering Mobile Application User Interfaces

Tuan Anh Nguyen, Christoph Csallner. ASE’15

Input Edges Dilated Edges Contours Container Hierarchy OCR Invalid Words Merge Words Components

slide-83
SLIDE 83

Evaluation

Pixel Precision Pixel Recall Ground Truth Prediction Ambiguity

Component Our Work REMAUI TextView Precision 89% 75% Recall 86% 26% Image Precision 94% 30% Recall 95% 10%

slide-84
SLIDE 84

Button Text Text Image

Component Detection

Button

Button Button

SIGN IN

Font Family Font Size Corner Radius Background Color Roboto 12 pt Shadow 0 dp Border Width 0 dp ...

Attribute Prediction

Attributes

Image Image Image Button Button Button Text Text

Layout Synthesis

Layout

slide-85
SLIDE 85

Button Attributes

Font Family Font Size Text Gravity Lobster Cav

11pt

14pt left right Border Color Border Width Border Radius purple gray 0 dp 4 dp 15 dp 6 dp Background Color Padding Shadow purple blue bottom right 0 dp 10 dp

slide-86
SLIDE 86

Attribute Prediction

Border Radius 4 dp Border Width Background Color Shadow 0 dp #F87541 0 dp Font Family Font Size Text Gravity Roboto 6 dp center Input Image

SIGN IN

Rendered Image

slide-87
SLIDE 87

Future Designs

Training Dataset

Brand Designs Common Designs

slide-88
SLIDE 88

Design Over the Years

2016 2014 2009 2010 2011 2012 2013 2015

[credits: Wojciech Dobry]

slide-89
SLIDE 89

Synthetic Dataset

Font Family Font Size Border Width Border Radius Border Color Background Color Text Color ... Cav Roboto Lobster

10 pt

14 pt

12 pt

SIGN IN

Sample Rescaling Position

SIGN IN SIGN IN SIGN IN SIGN IN SIGN IN SIGN IN

slide-90
SLIDE 90

Evaluation

Border Width Border Radius Synthetic Dataset Real Dataset 0.1 px 0.63 px 1.37 px 2.84 px Average Error in Pixels

Less than 3px typically not noticable

Training on Synthetic Datasets Leads to Good Generalization

Font Family Font Size Border Radius Background Color Roboto 12 pt

slide-91
SLIDE 91

Button Text Text Image

Component Detection

Button

Button Button

SIGN IN

Font Family Font Size Corner Radius Background Color Roboto 12 pt Shadow 0 dp Border Width 0 dp ...

Attribute Prediction

Attributes

Image Image Button Button Button Text Text

Layout Synthesis

Layout