Evaluating Multimodal Models on Image-to-Vector-Drawing Code Generation

    Converting a 2D diagram into executable vector-drawing code is a compound task combining visual understanding, structural reasoning, and code generation. This article breaks down the five core capabilities required, proposes a layered evaluation set with quantitative metrics, analyzes improvements observed in internal testing of an intermediate model version, and presents an engineering pipeline based on structured intermediate representation, validation, and automated repair to make this capability production-ready.

    1. Background: From Image Understanding to Renderable Code Generation

    Multimodal models have matured on tasks like image captioning and visual question answering, but the difficulty rises sharply when the goal becomes “convert a 2D diagram into executable vector-drawing code.” The model must not only recognize what is in the image, but also understand spatial relationships between elements, front-to-back occlusion, layer ownership, and semantic structure—then map all of this visual information into coordinates, paths, stroke styles, filled regions, and drawing order.

    In recent internal testing of an intermediate model version, a clear trend emerged on the complex diagram-to-vector-code task: compared to earlier experimental versions, the model reconstructs 3D structural cues, occlusion relationships, and layering in 2D images more reliably, producing drawing instructions closer to renderable, editable results. This shift deserves systematic engineering analysis, because it signals that multimodal models are moving from “visual understanding assistance” toward “structured code generation assistance.”

    That said, improvement in a single demo does not mean production readiness. What developers actually care about is: Where are the capability boundaries? How should evaluations be designed? How can model output be integrated into a verifiable, repairable, and regressable engineering pipeline? This article addresses these questions.

    2. Task Decomposition: What the Model Must Learn

    Converting a diagram into vector-drawing code involves at least five categories of capability.

    2.1 Understanding 3D Structure in 2D Images

    Diagrams often express 3D structures through isometric views, perspective, or stacked rectangles. The model must infer depth relationships from 2D projections—for example, which face lies in front of another, which edge is occluded, and whether a region represents internal structure rather than an outer contour. Pure 2D element detection flattens these front-to-back relationships, causing incorrect layer ordering in the generated code.

    2.2 Inferring Occlusion and Layering

    Occlusion is a key semantic in vector graphics. When a rectangle is partially covered by another shape, the model must decide whether to draw the full rectangle and let an upper layer cover it, or to draw only the visible contour. The two strategies yield different editability and rendering outcomes. In engineering practice, preserving semantically complete objects and expressing occlusion through layer order is usually preferred—but this requires the model to output explicit hierarchy and z-order information.

    2.3 Coordinate Systems and Geometric Path Generation

    Mapping image pixel coordinates to drawing coordinates requires consistent canvas size, origin position, scale, and units. Generated paths must not only “look similar” but also satisfy basic geometric constraints: closure, continuity, and absence of self-intersection anomalies. Complex curves must be decomposed into line segments, Bézier curves, or multi-segment paths with properly connected endpoints.

    2.4 Stroke Styles, Dashed Lines, and Fill Semantics

    Solid, dashed, and dotted lines in diagrams often carry distinct meanings—visible edges, hidden edges, auxiliary lines, boundaries. Filled regions may represent solid faces, background areas, or highlights. The model must map visual stroke and fill styles into structured attributes rather than simply emitting a line that looks visually similar.

    2.5 Drawing Order and Editability

    Vector-drawing code executes sequentially; later elements cover earlier ones. The model must output a reasonable drawing order or explicit layering. Editability matters just as much: if everything is merged into one giant path, the render may look similar, but subsequent modification becomes extremely costly. Ideal output preserves object boundaries, grouping, naming, and hierarchy.

    3. Evaluation Set Design: Don’t Judge Only by “How Similar It Looks”

    For this task, we recommend building a layered evaluation set rather than judging quality from a handful of showcase examples.

    3.1 Sample Layers

    • Basic geometry layer: rectangles, circles, arrows, text placeholders, simple connectors.
    • Structural relationship layer: front-back occlusion, nested containers, group borders, cross-layer connections.
    • 3D-cue layer: isometric cubes, perspective boxes, stacked panels, cross-section diagrams.
    • Complex composite layer: multi-region fills, mixed solid/dashed strokes, interleaved labels and paths, long images with dense small elements.

    Assign different weights to each layer to avoid the trap where a model performs well on simple samples but is completely unusable on complex diagrams.

    3.2 Metric Design

    At minimum, include the following metrics:

    • Parse rate: whether the output can be parsed into a structured drawing description.
    • Render rate: whether the parsed output renders without errors.
    • Element recall and precision: whether major shapes, connectors, and filled regions are complete without over-generation.
    • Coordinate error: normalized error of key endpoints, corner points, and centers.
    • Layer-order accuracy: whether occlusion and z-order match the semantics of the original image.
    • Stroke-semantics consistency: whether solid, dashed, and fill styles are mapped correctly.
    • Human editability score: whether objects are grouped, names are meaningful, and paths are not over-merged.

    These metrics are independent of any specific product interface and can be implemented on general-purpose inference services.

    4. Observations: Where the Intermediate Version Improved

    In internal testing on complex samples, the improvement was not simply “drawing more like the original”—it was more complete structural understanding. Several specific patterns stood out.

    First, the model tended to establish layer hypotheses before generating paths. Facing occlusion, it attempted to preserve the full semantics of occluded objects and express front-to-back relationships through layering, rather than merely tracing visible contours. This is friendlier for downstream editing.

    Second, coordinates and paths were organized more systematically. In complex diagrams, the model separated background frames, main structures, connectors, and annotation regions into distinct outputs, with more continuous path commands and fewer fragmented line segments.

    Third, the semantic mapping of stroke styles and fills was more stable. Dashed lines were no longer treated as “lighter solid lines,” and filled regions showed fewer overflow or layer-misplacement issues.

    Fourth, drawing order better matched visual logic. The hierarchy of background, main body, foreground, and annotations was clearer, reducing basic errors like “background drawn last covering the subject.”

    However, boundaries remain: dense small elements, mixed text-and-path layouts, and strongly perspective hand-drawn diagrams can still cause coordinate drift, occlusion misjudgment, and path over-merging. Model output must therefore enter a validation-and-repair workflow.

    5. Engineering Implementation: A “Structured Output + Validation + Repair” Loop

    We recommend not having the model directly emit final drawing code. Instead, have it first produce a structured intermediate representation, then convert that into target drawing code. For example, a generic JSON description of the canvas, layers, and elements:

    1. {
    2. "canvas": {"width": 1000, "height": 700, "unit": "px"},
    3. "layers": [
    4. {"id": "background", "z": 0},
    5. {"id": "foreground", "z": 20}
    6. ],
    7. "elements": [
    8. {
    9. "id": "e1",
    10. "type": "path",
    11. "layer": "background",
    12. "commands": ["M 100 100", "L 300 100", "L 300 300", "Z"],
    13. "stroke": "solid",
    14. "fill": "none",
    15. "z": 5
    16. },
    17. {
    18. "id": "e2",
    19. "type": "path",
    20. "layer": "foreground",
    21. "commands": ["M 120 120", "C 180 80 260 80 320 120"],
    22. "stroke": "dashed",
    23. "fill": "region-a",
    24. "z": 30
    25. }
    26. ]
    27. }

    Then plug this into a four-step pipeline:

    1. 1. The model generates a structured drawing description
    2. 2. Parse and validate: field completeness, coordinate ranges, path closure, layer references
    3. 3. Render a preview and compare structure against the original image
    4. 4. If metrics fall below thresholds, trigger targeted repair: add missing elements, adjust layers, fix coordinates, split paths

    Prompts should also state explicit constraints: analyze layers before outputting elements; preserve semantically complete objects; express occlusion via layering; dashed and dotted lines must be explicitly labeled; filled regions must be closed; never merge all content into a single long path. For enterprise scenarios, also add sensitive-data redaction, output auditing, version management, and a regression evaluation set to prevent uncontrolled drift when models are upgraded.

    6. Conclusion

    Converting 2D diagrams into vector-drawing code is a classic compound task combining visual understanding, structural reasoning, and code generation. The improvements observed in internal testing of an intermediate model version show that the model is becoming more methodical in handling 3D structural cues, occlusion layering, and drawing order. But production deployment cannot rest on one-off demos—it requires a layered evaluation set, a structured intermediate representation, and an automated validation-and-repair loop. Only by turning “looks good” into “parseable, renderable, editable, and regressable” can this capability truly enter the daily workflows of developers and enterprise users.