Text-to-Image Evaluation Guide: Measuring Text Rendering, Detail Fidelity, and Subject Consistency
This practical guide presents a reproducible framework for evaluating text-to-image models across three dimensions: text rendering accuracy, visual detail fidelity, and subject consistency across iterative edits. It covers experiment design, logging requirements, sample-size estimation, OCR calibration, image sharpness metrics, multi-round testing, and implementation examples in Python.
1. Standardize Logging Before Evaluation
Text-to-image models are often presented through a single example image. Engineering teams, however, need to answer three practical questions:
- Can the model reliably produce usable results?
- Is its latency compatible with the application workflow?
- Does the main subject remain consistent after multiple rounds of editing?
This guide divides evaluation into three measurable dimensions:
- Text rendering accuracy
- Detail fidelity
- Multi-round subject consistency
Each dimension includes a test design, metric definitions, runnable code, and evaluation guidance.
Before testing begins, standardize the logging format. Each request should record at least the following fields:
- Model name, version, and deployment environment, including the inference framework version;
- Prompt ID and complete prompt text;
- Random seed, sampling steps, guidance scale, and other sampling parameters;
- Output resolution;
- Request start time, end time, and elapsed time;
- File path and hash of the original output image, preferably using SHA-256;
- Request status and error details, if any.
With complete records, every result can be traced back to a specific configuration. After a model upgrade, the team can rerun the tests using the same logs and determine whether the two result sets are comparable.
2. Evaluation Preparation
2.1 Runtime Environment
The examples in this guide require Python 3.10 or later, Pillow, and NumPy. Lock dependency versions—for example, Pillow 10.x and NumPy 1.26.x—and write the versions to the evaluation logs.
After upgrading dependencies, recompute the scores for a set of baseline images first. Continue with the evaluation only after confirming that the results have not changed.
2.2 Pre-Evaluation Checklist
A single example can be heavily affected by randomness. Evaluation should meet all of the following conditions before conclusions are drawn:
- The prompt set is fixed, covers common scenarios and edge cases, and is saved as a versioned file;
- Each prompt is sampled with at least three different random seeds, with the mean and variation range recorded;
- The same test batch uses the same resolution and sampling steps; parameters should not be mixed across models;
- Automated metrics and blind human review are both used to cross-check one another;
- Each dimension includes at least 50 prompt-and-seed combinations. If the sample size is smaller, label the result as preliminary.
2.3 How to Determine the Sample Size
Fifty combinations is a starting minimum. The actual sample size depends on the variance of the target workload.
A team can begin with 20 to 30 samples in a pilot test, estimate the standard deviation σ of the per-sample score, and then use the following formula:
n ≈ (1.96 × σ ÷ E)²
Here, E is the acceptable margin of error.
For example, if the pilot test produces σ = 0.1 and the team wants to keep the mean error within ±0.02:
n ≈ (1.96 × 0.1 ÷ 0.02)² ≈ 96
Higher variance requires a larger sample size.
3. Dimension One: Text Rendering Accuracy
3.1 Background
Diffusion-based image generation models first use a text encoder to interpret the prompt and then gradually generate pixels. The alignment between text encoding and pixel generation is imperfect, so characters in the image can easily contain errors. These failures are often described as character collapse.
Common error types include:
| Type | Description | Example, with “牛肉面” as the target |
|---|---|---|
| Missing strokes | The glyph is incomplete | A stroke is missing from “肉” |
| Duplication | A character appears more than once or is overlaid | “牛牛肉面” |
| Substitution | An incorrect character replaces the intended one | “牛肉而” |
| Layout errors | Text is shifted, cropped, or wrapped incorrectly | Text touches the edge or is truncated |
During manual review, record these four error types separately. Do not include layout errors in character accuracy; assign them a separate manual score.
3.2 Test Method
Divide prompts into three categories:
- Short terms, such as store names and menu headings;
- Medium-length phrases, such as promotional copy;
- Text with style descriptions, such as chalk lettering, neon text, or metal engraving.
Use at least 100 prompts in each category.
Because OCR can make mistakes, calibrate an OCR baseline before evaluating generated images:
- Render approximately 100 text images using a standard font, matching the size of the test set. Use Noto Sans CJK SC Regular, a font size of 64 px, black text on a white background, a 1024 × 1024 canvas, and centered text. The image content should match the target text in the test set.
- Use the same OCR engine and version for all images—for example, a Chinese recognition model from PaddleOCR 2.x—and record the version in the logs. Calculate character accuracy for this set as the OCR baseline
B. - Apply exactly the same OCR configuration to model-generated images. Results with recognition confidence below 0.85 should be sent for manual review. The value 0.85 is only a starting point. Calibrate it on the baseline images so that the baseline false-positive rate remains below 5%.
- During manual review, inspect the image first and then compare it with the OCR result:
- If the visible text matches the target but OCR reads it incorrectly, classify it as an OCR error rather than a model error;
- If the visible text does not match the target, classify it as a model character error and include it in the text-rendering error;
- If the text is unreadable or its layout is incorrect, record these conditions separately and do not merge them into character accuracy.
- Report the model score
Mtogether with the baselineB, and calculate the differenceM − B.
3.3 Metric Calculation
Character accuracy is defined using edit distance:
Character accuracy = 1 − edit distance ÷ number of target characters
Edit distance is the minimum number of insertions, deletions, and substitutions required to transform one string into another. The following implementation uses only the Python standard library:
def edit_distance(a: str, b: str) -> int:# Compute edit distance with dynamic programming while retaining one row of state.m, n = len(a), len(b)dp = list(range(n + 1))for i in range(1, m + 1):prev, dp[0] = dp[0], ifor j in range(1, n + 1):cur = dp[j]if a[i - 1] == b[j - 1]:dp[j] = prevelse:dp[j] = 1 + min(prev, dp[j - 1], dp[j])prev = curreturn dp[n]def char_accuracy(target: str, recognized: str) -> float:# Filter empty targets before calling this function.if not target:return 0.0dist = edit_distance(target, recognized)# Clamp overlong recognition results to zero accuracy.return max(0.0, 1 - dist / len(target))if __name__ == "__main__":print(char_accuracy("招牌牛肉面", "招牌牛肉面")) # 1.0print(char_accuracy("招牌牛肉面", "招牌牛肉麵")) # 0.8print(char_accuracy("招牌牛肉面", "")) # 0.0
Boundary cases should be documented separately:
- If the recognition result is empty, the edit distance equals the target length and accuracy is 0;
- If the recognition result is much longer than the target, clamping the result to 0 can reduce the mean score. Report the number of clamped samples;
- Samples with an empty target should be filtered out before aggregation and excluded from the mean.
3.4 Acceptance Checklist
- Record the proportion of the image occupied by the text region. Small text is easily overlooked in thumbnails and is often more error-prone;
- Record the success rate across repeated samples for the same prompt. A single successful result does not demonstrate stability;
- Have human reviewers score layout properties—such as centering and menu-appropriate font sizing—from 1 to 5;
- Report the OCR baseline and model score separately, and calculate their difference.
4. Dimension Two: Detail Fidelity
4.1 Test Strategy
A high-resolution output does not necessarily contain high-quality details. A model may generate smooth textures at a large size while producing structural errors when the image is enlarged.
Choose subjects with regular structures and complex textures, such as:
- Compound insect eyes;
- Woven fabric;
- Building facades;
- Leaf veins.
Inspect these images at 100% pixel scale.
4.2 Sharpness Proxy Metric
The variance of the Laplacian response can roughly represent the amount of high-frequency information in an image. A higher variance generally indicates richer edges and textures. However, noise can also increase this value, so it should be treated only as a supporting metric and not as a standalone measure of image quality.
Runtime requirements:
- Pillow 9.1 or later, for the
Image.Resamplingenumeration; - NumPy is optional.
The resizing rule must be standardized. This guide uses the following procedure:
- Crop a centered 1:1 square from the image;
- Resize it to 512 × 512 using the LANCZOS filter.
Cropping may remove edge content, but applying the same rule to every sample keeps the results comparable. A size of 512 is a compromise between processing speed and texture retention. If more detail must be preserved, the team can use 1024, but the baseline must be recalibrated.
from PIL import Imagedef load_gray(path: str, size: int = 512):# Center-crop to a square, then resize with LANCZOS.# Apply the same rule to every sample.img = Image.open(path).convert("L")w, h = img.sizeside = min(w, h)left, top = (w - side) // 2, (h - side) // 2img = img.crop((left, top, left + side, top + side))img = img.resize((size, size), Image.Resampling.LANCZOS)pixels = list(img.getdata())return [pixels[y * size:(y + 1) * size] for y in range(size)]def laplacian_variance(gray):# gray: a two-dimensional list containing grayscale values from 0 to 255.h, w = len(gray), len(gray[0])values = []for y in range(1, h - 1):for x in range(1, w - 1):v = (gray[y - 1][x] + gray[y + 1][x]+ gray[y][x - 1] + gray[y][x + 1]- 4 * gray[y][x])values.append(v)if not values:return 0.0mean = sum(values) / len(values)return sum((v - mean) ** 2 for v in values) / len(values)def normalized_sharpness(path: str, size: int = 512):# Divide by the square of the mean brightness to reduce# the effect of overall image brightness.gray = load_gray(path, size)flat = [p for row in gray for p in row]mean_brightness = sum(flat) / len(flat)return laplacian_variance(gray) / (mean_brightness ** 2 + 1e-6)if __name__ == "__main__":print(normalized_sharpness("sample_insect_eye.png"))
For large image collections, pure Python loops may be slow. A NumPy implementation can be used instead. The two implementations produce equivalent results:
import numpy as npdef laplacian_variance_np(gray):g = np.asarray(gray, dtype=np.float64)lap = (g[:-2, 1:-1] + g[2:, 1:-1]+ g[1:-1, :-2] + g[1:-1, 2:]- 4 * g[1:-1, 1:-1])return float(lap.var())
Important considerations:
- Laplacian variance is sensitive to resolution. Resize every image using the same rule before calculation;
- The metric is sensitive to noise. Scores can vary across samples from the same model, so use the median of multiple images for each group;
- For cross-model comparisons, use the score of the same reference model at the same image size as the baseline. Report relative values rather than comparing absolute scores directly.
5. Dimension Three: Multi-Round Subject Consistency
5.1 Test Design
Multi-round editing is common in production workflows. For example, a team may first generate a character and then request a background change, a clothing-color adjustment, or a different camera angle.
The test should determine whether the subject after editing is still the same object.
Use the following process:
- Select at least 20 subjects, such as a specific mascot, product package, or character. Write one base prompt for each subject;
- Generate the subject image in round 0 and use it as the reference;
- In rounds 1 through 3, append an editing instruction to the previous round. Change only one attribute per round, such as “change the background to a snowy landscape”;
- Use at least three random seeds for each subject and record the output from every round.
5.2 Automated Metrics
Before evaluation, select an image-embedding model, lock its version, and record it in the logs. For example, use a …
