Evaluating Multimodal Models on Diagram-to-Code Reconstruction

    This article breaks down diagram reconstruction in multimodal models, a task that requires generating compilable structured drawing code rather than describing an image. It defines four verifiable sub-capabilities—2D-to-3D structure inference, occlusion and layer ordering, coordinate and path generation, and drawing order with compilability—and explains how layered scoring, prompt design, and engineering support make evaluation more reliable than subjective "does it look right" judgments.

    1. The Core Problem: Reconstruction Is Not Image Captioning

    Before evaluating the multimodal model experience, the task itself needs a clear definition. The core scenario is this: given a schematic diagram, the model must output structured drawing code that can be compiled. This differs fundamentally from common tasks such as image description or visual question answering.

    • Image description only requires semantic restatement, leaving a large tolerance for error.
    • Diagram reconstruction requires precise geometric rebuilding. If any single element—coordinates, proportions, hierarchy, or drawing order—is wrong, the final result is visibly distorted.

    For this reason, evaluating such capabilities cannot stop at “does it look similar.” It must be broken down into several verifiable sub-capabilities.

    2. Four Key Sub-Capabilities

    2.1 Inferring Structure from 2D to 3D

    Schematic diagrams often use flat projections to represent three-dimensional objects. The model must determine which line segments represent visible outlines and which represent hidden edges that are occluded, then decide whether each line style should be solid or dashed. A typical failure at this step is drawing occluded edges as solid lines, or misjudging visible outlines as dashed lines, which collapses the overall sense of space.

    2.2 Determining Occlusion and Layer Relationships

    Complex diagrams contain multiple stacked layers. The model must infer what is in front and what is behind; otherwise filled regions will overlap each other, and colors and textures will become scrambled. In engineering practice, the model is usually required to output a layer list first, then the content of each layer. This “plan first, then draw” order can significantly reduce the error rate.

    2.3 Generating Coordinates and Paths in Structured Code

    Mapping visual information into drawing code requires handling details such as coordinate system orientation, unit conversion, path closure, and curve control points. A schematic representation:

    1. Layer order:
    2. layer_1 background fill
    3. layer_2 main outline (solid)
    4. layer_3 hidden edges (dashed)
    5. layer_4 annotations and leader lines

    Within each layer, generating in the order “path definition → fill → stroke” avoids later elements covering earlier ones.

    2.4 Drawing Order and Compilability

    The final output must be parsed correctly by a typesetting or drawing engine. Common problems include unclosed paths, out-of-bounds coordinates, and missing line style parameters. When evaluating, “whether it compiles on the first attempt” should be treated as a hard metric.

    3. Experience Differences Across Version Iterations

    From early experimental versions to later intermediate versions, the most visible changes concentrate in three areas:

    • More stable structure understanding: fewer clear misjudgments of occlusion relationships.
    • More standardized code: better path closure and parameter completeness, with less rework.
    • Better detail fidelity: solid and dashed lines, filled regions, and annotation positions are reproduced closer to the original diagram.

    It is worth emphasizing that these improvements belong to a general engineering evolution direction and should not be summarized with specific numbers. The actual experience still correlates strongly with input image complexity and prompt clarity.

    4. A Reusable Evaluation Method

    A layered scoring sheet is recommended to avoid subjective scoring:

    1. Structure layer: whether the 3D relationships and occlusion are correct.
    2. Geometry layer: whether coordinate proportions and path closure are reasonable.
    3. Style layer: whether line styles, fills, and annotations are complete.
    4. Engineering layer: whether the code compiles directly and can be generated repeatedly.

    Set a pass/fail judgment for each layer, then compute the overall pass rate. This is more reliable than a single “does it look similar” judgment.

    5. Prompt Design Recommendations

    • Explicitly require the model to output the layer list and drawing order first, then the code.
    • Specify the coordinate system and units to reduce ambiguity.
    • Provide separate rules for hidden edges and dashed lines.
    • Require the model to mark assumptions where it is uncertain, making manual review easier.

    6. Engineering Support for Production Use

    To integrate this capability into a production workflow, supporting components are typically needed: object storage to keep the original diagrams and outputs, a message queue to smooth traffic peaks, a container platform to host inference services, and logging services with monitoring and alerting to track failure rates. On Baidu AI Cloud, these capabilities can be combined by general category to form a closed loop of “input—inference—validation—archiving.”

    7. Conclusion

    The improvement in diagram reconstruction tasks is essentially the result of three things working together: structure understanding, code standardization, and engineering validation. Readers can use this to build their own evaluation baseline, replacing subjective impressions with layered metrics, so they can quickly judge whether the gains from each model iteration are real and usable.