Engineering Sketch Generation For Computer-Aided Design
Engineering Sketch Generation For Computer-Aided Design
Engineering Sketch Generation For Computer-Aided Design
Karl D.D. Willis Pradeep Kumar Jayaraman Joseph G. Lambourne Hang Chu Yewen Pu
Autodesk Research
Engineering Sketch
Generator
Figure 1: We tackle the problem of learning based engineering sketch generation as a first step towards synthesis and com-
position of solid models with an editable parametric CAD history.
Turtle Graphics Representation The Turtle Graphics where p(·) are probability distributions. Figure 3 illus-
representation uses a sequence of drawing commands, trates the two step generation process starting with the ver-
which can be executed to form an engineering sketch in the tex model (left) and then the curve model (right). The fi-
hypergraph representation. Intuitively, the turtle represen- nal stage of recovering the curve primitives from the hyper-
tation can be thought of as a sequence of pen-up, pen-move edges is done as a post-process. We use the vertex model di-
actions, which iteratively draws the engineering sketch one rectly from PolyGen with 2D vertex coordinates and adapt
loop at a time. It is used by Ellis et al. [8] to generate com- our curve model from the PolyGen face model to work with
positional and symmetric sketches. Specifically, the draw- 2D curves. We use 3 Transformer blocks in the vertex de-
ing commands of turtle graphics are specified by the follow- coder, curve encoder, and curve decoder Transformer mod-
ing grammar: els [33]. Each block includes a multihead attention with
8 heads, layer normalization and a 2-layer multilayer per-
T urtle ⊢ [ Loop ]
ceptron (MLP) with 512D hidden, and 128D output dimen-
Loop ⊢ LoopStart [Draw]
sions. Dropout with rates 0.2 and 0.5 are applied in each
Draw ⊢ Line | Arc | Circle
block of the vertex and curve models, respectively, right af-
LoopStart ⊢ loopstart(∆)
ter the MLP. The vertex and curve models are both trained
Line ⊢ line(∆)
by negative log likelihood loss against the ground truth data.
Arc ⊢ arc(∆, ∆)
Once the neural network is trained, we perform nucleus
Circle ⊢ circle(∆, ∆, ∆, ∆)
sampling [14] to directly generate samples in the hyper-
∆ ⊢ (int, int)
graph sketch representation. We refer the reader to Nash
et al. [23] for further details.
Here, a T urtle program consists of a sequence of Loops,
each loop consists of a start command LoopStart, followed
by a sequence of [Draw] commands. The pen initially 3.2.2 TurtleGen
starts at (0, 0). The LoopStart command starts a new loop The neural network for generating a program in the Turtle
by lifting the current pen, displacing/teleporting it by ∆ and representation is a sequence generator. The sequence of tur-
putting it back down. The Draw command can be one of tle commands are encoded as a sequence of discrete valued
three primitives Line, Arc, and Circle, each parameterized tokens, where each of the commands loopstart, line, arc,
by a different number of ∆ displacements, which extend the circle, along with two tokens for sequence start and end,
current loop without lifting the pen, displacing it relative are represented as 1-hot vectors. The quantized integer co-
to the current pen location. After a loop is completed, the ordinates are encoded as two 1-hot vectors for x and y each.
pen returns/teleports back to (0, 0). As with the hypergraph For any given sketch in the hypergraph representation, we
representation, ∆ values are quantized to a 256×256 grid. randomize the turtle sequence generation by randomly se-
The loops are ordered so that ones closest to (0, 0), where lecting the loop order, loop’s starting vertex, and the direc-
distance is measured between the loop’s closest vertex to tion of drawing the loop. We discard long sequences over
(0, 0), are drawn first. We provide an example program in 100 turtle commands.
Section A.1 of the Supplementary Material. The neural network is a simple 9-layer Transformer with
512D hidden and 128D output dimensions. The network
3.2. Generative Models
has seven linear branches of input and output, where the
We design and compare two different neural architec- first branch corresponds to the type of command, and the
tures on the task of engineering sketch generation: Curve- remaining six branches correspond to three x and y coor-
Gen and TurtleGen. dinates. Commands with less than three points are padded
(y,x) (y,x)
PREDICTION
Next
Curve
Vertex Transformer Vertex Transformer Curve Transformer Curve Transformer Curve Transformer Curve Transformer
CONDITIONING
(y,x)
Figure 3: CurveGen, our variant of the PolyGen [23] architecture, first generates sketch vertices (left), and then generates
sketch curves conditioned on the vertices (right).
with zeros. The input branches are concatenated and added curves. We use the official training split and after filtering
with the conventional positional embedding after a linear have 1,106,328 / 39,407 / 39,147 sketches for the train, val-
layer, before they are fed into the Transformer network. The idation, and test sets respectively.
output branches are connected to the Transformer encod-
ing at the previous sequence step. We store the first three 4.2. Experiment Setup
ground-truth turtle steps from the training set as a fixed dic- We train the CurveGen model on the SketchGraphs train-
tionary, which we randomly sample from to precondition ing set. Unlike the ShapeNet dataset used to train the orig-
the auto-regressive model at sampling time. Each sampled inal Polygen model, the SketchGraphs data does not have
sequence is then executed to recover the sketch hypergraph any notion of classes and represents a more challenging,
representation, and define the geometry and topology. but realistic scenario where human annotated labels are un-
available. We train for 2 million iterations with a batch size
4. Results of 8 using 4 Nvidia V100 GPUs. We use the Adam opti-
mizer with learning rate 5e-4, and apply to the curve model
We now present quantitative and qualitative results data a jitter augmentation with the amount sampled from a
on the task of engineering sketch generation, comparing truncated normal distribution with mean 0, variance 0.1 and
the CurveGen and TurtleGen generative models with the truncated by the bounding box of the sketch vertices. Train-
SketchGraphs [27] generative model. ing time takes approximately 48 hours. We save the model
with the lowest overall validation loss for evaluation.
4.1. Data Preparation
We train the TurtleGen model on the same data. To en-
We use the pre-filtered version of the SketchGraphs [27] sure fair comparison, we train the model with a batch size
dataset that contains 9.8 million engineering sketches with of 128 for a total of 0.5 million iterations, which exposes
16 or fewer curves. We remove duplicates from the dataset the model to the same number of training data samples as
to promote data diversity during training, and ensure evalua- CurveGen. Training is done with a single Nvidia V100
tion on unseen data at test time. We consider two sketches to GPU and takes around 48 hours. We use the Adam opti-
be duplicates if they have identical topology and similar ge- mizer with a learning rate of 5e-4, as well as a learning rate
ometry. To detect similar geometry, sketches are uniformly scheduler that decreases the learning rate by a factor of 0.5
scaled and the coordinates are quantized into a 9×9 grid. when the validation loss plateaus. Validation is conducted
Vertices are considered identical if they lie in the same grid once every 500 training iterations. We save the model with
square. The same quantization is also applied to the radii the lowest overall validation loss for evaluation.
of circles and arcs. Lines are considered identical if the end We train the SketchGraphs generative model using the
points are identical. Arcs additionally check for an identical official implementation with and without duplicates. We
quantized radius. Circles check the center point and radius. train for 150 epochs, as in the original paper, on a single
We do not consider a sketch unique if both the topology and Quadro RTX 6000 GPU. Training time takes approximately
geometry match, but curve or vertex order is different. Us- 27 hours. Following the advice of the SketchGraphs au-
ing this approach we find that duplicates make up 87.01% thors, we adjust the learning rate scheduler to reduce the
of the SketchGraphs data. We remove all duplicates, invalid learning rate at epochs 50 and 100. All other hyperparam-
data (e.g. sketches with only points) and omit construction eters and settings follow the official implementation, in-
Table 1: Quantitative sketch generation results. Bits per Vertex and Bits per Sketch are the negative log-likelihood calculated
over the test set; both are not directly comparable and reported separately for the vertex/curve models used in CurveGen.
Unique, Valid, and Novel are calculated over 1000 generated sketches.
Model Parameters Bits per Vertex Bits per Sketch Unique % Valid % Novel %
CurveGen 2,155,542 1.75 / 0.20 176.69 / 30.64 99.90 81.50 90.90
TurtleGen 2,690,310 2.27 54.54 86.40 42.90 80.60
SketchGraphs 18,621,560 - 99.38 76.20 65.80 69.10
SketchGraphs (w/ Duplicates) 18,621,560 - 94.30 58.70 74.00 49.70
cluding the prediction of numerical node features. These sketches from SketchGraphs are commonly due to arcs of
provide improved geometry initialization before the data is near zero length. For the novel metric, it is reasonable to ex-
passed to the OnShape constraint solver. pect generative models to produce some identical sketches
to those in the training data, such as simple circles, rect-
4.3. Quantitative Results angles, and combinations thereof. The low percentage of
4.3.1 Metrics novel sketches generated by SketchGraphs when trained on
the dataset with duplicates suggests that the model memo-
For quantitative evaluation we report the following met- rizes sketches which are duplicated in the training data. Re-
rics. Bits per Vertex is the negative log-likelihood of test moving duplicates from the data helps improve variety in
examples averaged per-vertex and converted from nats to the output. For the remainder of the paper we report results
bits; lower is better. Bits per Sketch is the negative log- from all models trained without duplicates.
likelihood of test examples averaged per-sketch as a whole
in bits; lower is better. For CurveGen we report the bits for 4.4. Perceptual Evaluation
both the vertex and curve models. Unique is the percentage
To understand how engineering sketches generated by
of unique sketches generated within the sample set. We use
each model compare to human designed sketches, we per-
the duplicate detection method described in Section 4.1 to
form a perceptual evaluation using human subjects. In our
find the percentage of unique sketches. A lower value indi-
two-alternative forced choice study, each participant is pre-
cates the model outputs more duplicate sketches. Valid is
sented with one human designed and one generated engi-
the percentage of valid sketches generated. Invalid sketches
neering sketch and asked: “Which sketch is more realis-
include curve fitting failures, curves generated with >4 ver-
tic?". Brief instructions are provided, including an illustra-
tices, or identical vertices within a curve. Novel is the per-
tion of an engineering sketch used in context, similar to Fig-
centage of novel sketches generated that are not identical
ure 1. We evaluate 1000 unique generative sketches from
to sketches in the training set. We again use the duplicate
each model, with a consistent set of 1000 human designed
detection method described in Section 4.1. We evaluate
sketches from the SketchGraphs test set. For each pair of
the bits per vertex/sketch metrics on the withheld test set.
sketches, we log the responses of three human subjects and
All other metrics are evaluated on 1000 generated samples.
We include non-Valid sketches, which often contain valid
curves, when calculating the Unique and Novel metrics. 50% 80%
Indistinguishable from Human Design
Realistic Sketch % vs. Human Designed
70%
40%
60%
Inter-rater Agreement %
Figure 5: Qualitative sketch generation results. From left to right: human designed sketches from the SketchGraphs dataset,
randomly selected sketches generated using the CurveGen, TurtleGen, and SketchGraphs generative models.
Figure 6: Examples of 3D geometry produced by extruding the closed profiles of sketches generated from CurveGen.
use the majority answer. We conduct the study using work- SketchGraphs generative models. We observe that Curve-
ers from Amazon Mechanical Turk. Figure 4, left shows Gen in particular is able to consistently produce sketches
the percentage of generated sketches classed as more real- with closed loops, symmetrical features, perpendicular
istic than human designed sketches; higher values are bet- lines, and parallel lines. We provide additional qualitative
ter. A value of 50% indicates the generated sketches are results in Section A.2 of the supplementary material.
indistinguishable from human design. Figure 4, right shows
the inter-rater agreement calculated as a percentage between Sketch to Solid CAD Models A key motivation of the
each of the three human subjects. A lower value indicates current work is to enable the synthesis and composition of
there is more confusion between the generated and human solid CAD models. In Figure 6 we demonstrate how engi-
designed sketches. The study results show that human sub- neering sketches generated by CurveGen with closed loop
jects find CurveGen output to be the most realistic of the profiles can be lifted into 3D using the extrude modeling
generated engineering sketches. operation in a procedural manner.
5. Conclusion
Auto-constrained