Evaluating Multimodal Models on Generating Drawing Code from Technical Diagrams: Methods and Practice

    This article explains how to evaluate multimodal models that read a technical diagram and output code to reproduce it. It splits the task into four stages, covers common occlusion and layering errors, and describes how to build a test set, define scoring dimensions, run an automated evaluation pipeline, perform regression testing across versions, and address production concerns.

    1. Background: Why Evaluate Image-to-Code Generation

    Many teams want a model to read a technical diagram and then output code that reproduces it. Typical examples include geometric figures, circuit structures, architecture topologies, and projections of 3D objects. This task combines visual understanding with structured generation, so it is clearly harder than image captioning or visual question answering.

    A diagram is a 2D plane, but the information it carries is 3D. The side of a cube may be hidden by another object. Two lines may cross on the image without intersecting in space. The model must first infer depth and occlusion, then map those relationships to coordinates, paths, line styles, and drawing order in the code. An error at any step can leave the final figure looking roughly right while its structure is wrong.

    For this reason, judging the final rendering alone does not reveal a model’s real capability. The evaluation needs to split the task and check each stage separately.

    2. Task Breakdown: Four Stages from Image to Code

    The process can be split into four stages:

    1. Element recognition: Find the basic objects in the figure, such as line segments, faces, arcs, text labels, and filled regions.
    2. Spatial relationship inference: Determine which objects are in front and which are behind, and which lines should be hidden or drawn as dashed lines.
    3. Coordinate and style mapping: Convert visual positions into drawing coordinates, and set color, line width, line style, transparency, and other styling properties.
    4. Drawing order: Output instructions from far to near, or from bottom layer to top layer, so that occlusion renders correctly.

    Each stage can have its own checks. Element recognition checks whether the count and types of objects are complete. Spatial inference checks whether occlusion judgments are correct. Coordinate mapping checks scale and position deviation. Drawing order directly determines whether the visual occlusion holds.

    This breakdown also helps during version updates. If a new version improves only one stage, the evaluation shows where the gain came from instead of producing a single total score.

    3. Common Failure Modes in Occlusion and Layering

    Occlusion and layering are the most error-prone parts of this task. Common failure modes include:

    • Reversed occlusion: A rear object is drawn over a front object, so the figure looks as if it passes through the front face.
    • Wrong line styles: An edge that should be hidden is still drawn as a solid line, or a visible edge is drawn as a dashed line.
    • Fill overflow: The vertices of a filled polygon are in the wrong order, so the color spills into adjacent faces.
    • Scale distortion: The relative positions of three points are correct, but the overall proportions are stretched, which affects angle judgments.
    • Missing drawing order: The code order does not match spatial depth, so the rendered result varies unpredictably.

    To address these failures, the test set can include dedicated samples for each type. For example, prepare images of two objects overlapping front to back to test occlusion direction. Prepare images of the same object drawn with solid and dashed lines to test line-style judgment. The sample count does not need to be large, but each category should cover several viewpoints and backgrounds.

    4. Evaluation Framework Design

    A usable evaluation framework usually has three parts: a test set, scoring rules, and an automated pipeline.

    4.1 Building the Test Set

    The test set should meet the following conditions:

    • Diverse sources: Include textbook-style standard diagrams as well as hand-drawn, low-resolution, and noisy images.
    • Difficulty levels: Grade samples as easy, medium, or hard based on object count, number of occlusion layers, and viewpoint complexity.
    • Complete annotations: Each image has a manually labeled object list, an occlusion relationship table, and a reference drawing order.
    • Fixed version: Once published, the test set should not change, so results remain comparable across model versions.

    4.2 Scoring Dimensions

    Score each sample on five dimensions, each with a maximum of 100 points.

    Dimension What is checked Scoring method
    Syntax validity Whether the output code can be parsed and compiled correctly Full score if it passes; points are deducted by failed stage
    Element completeness Whether the object count and types match the annotations Calculated from recall and precision
    Occlusion correctness Whether occlusion direction and line style match the annotations Judged item by item for each relationship pair
    Geometric accuracy Deviation of key-point coordinates from reference positions Average error after normalization
    Drawing order Whether the rendered result has the correct front-to-back relationships Compare the occluded regions of the rendered image and the reference image

    Syntax validity is a gate. If a sample fails this check, its other dimension scores are excluded from the total. This prevents a model from raising its average with plausible-looking output that cannot run.

    4.3 Automated Pipeline Example

    The pseudocode below outlines the main steps of the evaluation. It does not depend on any specific tool. In practice, the parser and renderer can be replaced with those your team already uses.

    1. for each test sample in test set:
    2. prompt = build_input(sample.image, fixed_prompt_template)
    3. output = call_model(prompt)
    4. if not parse_passes(output):
    5. record(sample.id, syntax_validity=0)
    6. continue
    7. scene = parse_to_object_list(output)
    8. rendered = render(scene)
    9. element_score = compare(scene.objects, sample.annotation.objects)
    10. occlusion_score = pairwise_compare(scene.occlusion_relations, sample.annotation.occlusion_relations)
    11. geometry_score = compute_keypoint_error(scene.coordinates, sample.annotation.coordinates)
    12. order_score = compare_occluded_regions(rendered, sample.reference_render)
    13. record(sample.id, scores_per_dimension)
    14. aggregate mean and standard deviation for each difficulty tier

    A few notes on this pipeline. First, the prompt template must stay fixed. Otherwise, differences between versions may come from changes in wording. Second, rendering comparison can use pixel-level masks that focus on occluded regions, rather than color differences across the whole image. Third, each difficulty tier should be aggregated separately, because an overall average can hide regressions on hard samples.

    5. Regression Testing Across Versions

    When a model or prompt is updated, the most useful question is which samples improved and which got worse. The following process helps answer it:

    1. Run both the old and new versions on the same test set. Save all outputs and per-dimension scores.
    2. Calculate the score change for each sample. List the samples with the largest gains and the largest drops.
    3. Review the samples that dropped. Determine whether the cause is the scoring rules, the annotations, or an actual regression in the model.
    4. Record confirmed regressions in the failure mode list, and track them during later training or prompt changes.

    Score fluctuations between runs can come from sampling randomness. If the model interface supports deterministic settings, use them. If it does not, run each sample several times, then report the mean and standard deviation.

    6. Production Considerations

    Several issues need attention when this capability is integrated into a real product:

    • Human review: For images with complex occlusion or high accuracy requirements, provide a way for people to review and edit the output before it reaches end users.
    • Fallback handling: When the syntax check fails, the system should show a clear error message and let users upload a new image or adjust their description.
    • Input quality checks: Blurry, tilted, or dark images significantly reduce recognition accuracy, so an image quality check can run at the input stage.
    • Result caching: Results for identical images and prompts can be cached to reduce cost and wait time.
    • Logging and privacy: Images may contain sensitive information. Logs should keep only necessary metadata, and original images should have access controls and retention limits.

    7. Summary

    Generating drawing code from an image requires both visual understanding and structured output. An evaluation should split the task into element recognition, spatial relationships, coordinate mapping, and drawing order, and design test samples and scoring dimensions for each stage. Occlusion and layering are the most error-prone parts, so they need their own test set. When versions change, per-sample regression comparison works better than a single total score, and human review and fallback handling should remain in place. With this approach, teams can see more clearly where the model is reliable and where it still needs human involvement.