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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
pinned: false
|
| 10 |
---
|
| 11 |
|
| 12 |
+
# Layout Validity
|
| 13 |
+
|
| 14 |
+
## Description
|
| 15 |
+
|
| 16 |
+
The Layout Validity metric evaluates the basic validity of layout elements by checking whether they meet minimum size requirements. A layout element is considered valid if its area within the canvas boundaries is greater than 0.1% of the total canvas area. This metric helps identify layouts with degenerate or nearly-invisible elements that don't contribute meaningfully to the design.
|
| 17 |
+
|
| 18 |
+
## What It Measures
|
| 19 |
+
|
| 20 |
+
This metric computes:
|
| 21 |
+
|
| 22 |
+
- **Valid element ratio**: Proportion of elements that meet minimum size requirements
|
| 23 |
+
- **Layout integrity**: Whether elements are large enough to be functional
|
| 24 |
+
- **Degenerate element detection**: Identifies layouts with overly small or nearly-invisible elements
|
| 25 |
+
|
| 26 |
+
Higher scores indicate better layout validity with fewer problematic elements.
|
| 27 |
+
|
| 28 |
+
## Metric Details
|
| 29 |
+
|
| 30 |
+
- Validity threshold: Element area > 0.1% of canvas area (after clamping to canvas bounds)
|
| 31 |
+
- Clamps element bounding boxes to canvas boundaries before computing area
|
| 32 |
+
- Filters out padding elements (label == 0)
|
| 33 |
+
- From PosterLayout (Hsu et al., CVPR 2023) for poster design evaluation
|
| 34 |
+
- Returns the ratio of valid elements to total non-padding elements
|
| 35 |
+
|
| 36 |
+
## Usage
|
| 37 |
+
|
| 38 |
+
### Installation
|
| 39 |
+
|
| 40 |
+
```bash
|
| 41 |
+
pip install evaluate
|
| 42 |
+
```
|
| 43 |
+
|
| 44 |
+
### Basic Example
|
| 45 |
+
|
| 46 |
+
```python
|
| 47 |
+
import evaluate
|
| 48 |
+
import numpy as np
|
| 49 |
+
|
| 50 |
+
# Load the metric with canvas dimensions
|
| 51 |
+
metric = evaluate.load(
|
| 52 |
+
"creative-graphic-design/layout-validity",
|
| 53 |
+
canvas_width=360,
|
| 54 |
+
canvas_height=504
|
| 55 |
+
)
|
| 56 |
+
|
| 57 |
+
# Prepare data (normalized ltrb coordinates)
|
| 58 |
+
predictions = np.random.rand(1, 25, 4)
|
| 59 |
+
gold_labels = np.random.randint(0, 4, size=(1, 25))
|
| 60 |
+
score = metric.compute(predictions=predictions, gold_labels=gold_labels)
|
| 61 |
+
print(score)
|
| 62 |
+
```
|
| 63 |
+
|
| 64 |
+
### Batch Processing Example
|
| 65 |
+
|
| 66 |
+
```python
|
| 67 |
+
import evaluate
|
| 68 |
+
import numpy as np
|
| 69 |
+
|
| 70 |
+
# Load the metric
|
| 71 |
+
metric = evaluate.load(
|
| 72 |
+
"creative-graphic-design/layout-validity",
|
| 73 |
+
canvas_width=360,
|
| 74 |
+
canvas_height=504
|
| 75 |
+
)
|
| 76 |
+
|
| 77 |
+
# Batch processing
|
| 78 |
+
batch_size = 128
|
| 79 |
+
predictions = np.random.rand(batch_size, 25, 4)
|
| 80 |
+
gold_labels = np.random.randint(0, 4, size=(batch_size, 25))
|
| 81 |
+
score = metric.compute(predictions=predictions, gold_labels=gold_labels)
|
| 82 |
+
print(score)
|
| 83 |
+
```
|
| 84 |
+
|
| 85 |
+
## Parameters
|
| 86 |
+
|
| 87 |
+
### Initialization Parameters
|
| 88 |
+
|
| 89 |
+
- **canvas_width** (`int`, required): Width of the canvas in pixels
|
| 90 |
+
- **canvas_height** (`int`, required): Height of the canvas in pixels
|
| 91 |
+
|
| 92 |
+
### Computation Parameters
|
| 93 |
+
|
| 94 |
+
- **predictions** (`list` of `lists` of `float`): Normalized bounding boxes in ltrb format (0.0 to 1.0)
|
| 95 |
+
- **gold_labels** (`list` of `lists` of `int`): Class labels for each element (0 = padding)
|
| 96 |
+
|
| 97 |
+
**Note**:
|
| 98 |
+
|
| 99 |
+
- Elements with `gold_labels == 0` are treated as padding and excluded from computation
|
| 100 |
+
- Element coordinates are clamped to [0, canvas_width] × [0, canvas_height] before area calculation
|
| 101 |
+
- Validity threshold: area > (canvas_width × canvas_height) / 1000
|
| 102 |
+
|
| 103 |
+
## Returns
|
| 104 |
+
|
| 105 |
+
Returns a `float` value representing the ratio of valid elements to total elements (range: 0.0 to 1.0).
|
| 106 |
+
|
| 107 |
+
## Interpretation
|
| 108 |
+
|
| 109 |
+
- **Higher is better** (range: 0.0 to 1.0)
|
| 110 |
+
- **Value of 1.0**: All elements are valid (ideal)
|
| 111 |
+
- **Value of 0.9-1.0**: Mostly valid layout with few problematic elements
|
| 112 |
+
- **Value of 0.7-0.9**: Some invalid elements, may need review
|
| 113 |
+
- **Value of 0.5-0.7**: Many invalid elements, layout quality concerns
|
| 114 |
+
- **Value < 0.5**: Significant validity issues, many degenerate elements
|
| 115 |
+
- **Value of 0.0**: All elements invalid (critical failure)
|
| 116 |
+
|
| 117 |
+
### Use Cases
|
| 118 |
+
|
| 119 |
+
- **Basic layout quality check**: Ensure generated layouts don't have degenerate elements
|
| 120 |
+
- **Generative model evaluation**: Detect models producing invalid element sizes
|
| 121 |
+
- **Layout post-processing**: Filter out layouts with validity issues
|
| 122 |
+
- **Sanity check**: Validate layout data before further evaluation
|
| 123 |
+
|
| 124 |
+
### Key Insights
|
| 125 |
+
|
| 126 |
+
- **Minimum requirement**: This is a basic quality check, not a comprehensive quality metric
|
| 127 |
+
- **Threshold choice**: 0.1% of canvas is quite permissive - very small but still visible elements pass
|
| 128 |
+
- **Canvas boundaries matter**: Elements extending beyond canvas are clamped, which can reduce their area
|
| 129 |
+
- **Foundation metric**: Pass validity check before evaluating other metrics
|
| 130 |
+
- **Model debugging**: Low validity scores indicate fundamental generation issues
|
| 131 |
+
|
| 132 |
+
### Common Causes of Invalidity
|
| 133 |
+
|
| 134 |
+
- **Collapsed bounding boxes**: Width or height near zero
|
| 135 |
+
- **Out-of-bounds elements**: Elements mostly outside canvas boundaries
|
| 136 |
+
- **Numerical errors**: Floating-point precision issues in generation
|
| 137 |
+
- **Model failure modes**: Generation model producing degenerate outputs
|
| 138 |
+
|
| 139 |
+
## Citations
|
| 140 |
+
|
| 141 |
+
```bibtex
|
| 142 |
+
@inproceedings{hsu2023posterlayout,
|
| 143 |
+
title={Posterlayout: A new benchmark and approach for content-aware visual-textual presentation layout},
|
| 144 |
+
author={Hsu, Hsiao Yuan and He, Xiangteng and Peng, Yuxin and Kong, Hao and Zhang, Qing},
|
| 145 |
+
booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition},
|
| 146 |
+
pages={6018--6026},
|
| 147 |
+
year={2023}
|
| 148 |
+
}
|
| 149 |
+
```
|
| 150 |
+
|
| 151 |
+
## References
|
| 152 |
+
|
| 153 |
+
- **Paper**: [PosterLayout (Hsu et al., CVPR 2023)](https://arxiv.org/abs/2303.15937)
|
| 154 |
+
- **Reference Implementation**: [PosterLayout eval.py](https://github.com/PKU-ICST-MIPL/PosterLayout-CVPR2023/blob/main/eval.py#L105-L127)
|
| 155 |
+
|
| 156 |
+
## Related Metrics
|
| 157 |
+
|
| 158 |
+
- [Layout Overlap](../layout_overlap/): Evaluates element spacing and collisions
|
| 159 |
+
- [Layout Alignment](../layout_alignment/): Measures spatial organization
|
| 160 |
+
- [Layout Non-Alignment](../layout_non_alignment/): Detects alignment violations
|
| 161 |
+
- [Layout Utility](../layout_utility/): Evaluates space utilization
|
layout-validity.py
CHANGED
|
@@ -4,6 +4,7 @@ import datasets as ds
|
|
| 4 |
import evaluate
|
| 5 |
import numpy as np
|
| 6 |
import numpy.typing as npt
|
|
|
|
| 7 |
|
| 8 |
_DESCRIPTION = r"""\
|
| 9 |
Computes the ratio of valid elements to all elements in the layout, where the area within the canvas of a valid element must be greater than 0.1% of the canvas.
|
|
@@ -24,6 +25,7 @@ _CITATION = """\
|
|
| 24 |
"""
|
| 25 |
|
| 26 |
|
|
|
|
| 27 |
class LayoutValidity(evaluate.Metric):
|
| 28 |
def __init__(
|
| 29 |
self,
|
|
|
|
| 4 |
import evaluate
|
| 5 |
import numpy as np
|
| 6 |
import numpy.typing as npt
|
| 7 |
+
from evaluate.utils.file_utils import add_start_docstrings
|
| 8 |
|
| 9 |
_DESCRIPTION = r"""\
|
| 10 |
Computes the ratio of valid elements to all elements in the layout, where the area within the canvas of a valid element must be greater than 0.1% of the canvas.
|
|
|
|
| 25 |
"""
|
| 26 |
|
| 27 |
|
| 28 |
+
@add_start_docstrings(_DESCRIPTION, _KWARGS_DESCRIPTION)
|
| 29 |
class LayoutValidity(evaluate.Metric):
|
| 30 |
def __init__(
|
| 31 |
self,
|
requirements.txt
CHANGED
|
@@ -1,89 +1,134 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
requests
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This file was autogenerated by uv via the following command:
|
| 2 |
+
# uv export --package layout_validity --no-dev --no-hashes --format requirements-txt
|
| 3 |
+
aiohappyeyeballs==2.6.1
|
| 4 |
+
# via aiohttp
|
| 5 |
+
aiohttp==3.13.2
|
| 6 |
+
# via fsspec
|
| 7 |
+
aiosignal==1.4.0
|
| 8 |
+
# via aiohttp
|
| 9 |
+
anyio==4.12.0
|
| 10 |
+
# via httpx
|
| 11 |
+
attrs==25.4.0
|
| 12 |
+
# via aiohttp
|
| 13 |
+
certifi==2025.11.12
|
| 14 |
+
# via
|
| 15 |
+
# httpcore
|
| 16 |
+
# httpx
|
| 17 |
+
# requests
|
| 18 |
+
charset-normalizer==3.4.4
|
| 19 |
+
# via requests
|
| 20 |
+
click==8.3.1
|
| 21 |
+
# via typer-slim
|
| 22 |
+
colorama==0.4.6 ; sys_platform == 'win32'
|
| 23 |
+
# via
|
| 24 |
+
# click
|
| 25 |
+
# tqdm
|
| 26 |
+
datasets==4.4.2
|
| 27 |
+
# via evaluate
|
| 28 |
+
dill==0.4.0
|
| 29 |
+
# via
|
| 30 |
+
# datasets
|
| 31 |
+
# evaluate
|
| 32 |
+
# multiprocess
|
| 33 |
+
evaluate==0.4.6
|
| 34 |
+
# via layout-validity
|
| 35 |
+
filelock==3.20.1
|
| 36 |
+
# via
|
| 37 |
+
# datasets
|
| 38 |
+
# huggingface-hub
|
| 39 |
+
frozenlist==1.8.0
|
| 40 |
+
# via
|
| 41 |
+
# aiohttp
|
| 42 |
+
# aiosignal
|
| 43 |
+
fsspec==2025.10.0
|
| 44 |
+
# via
|
| 45 |
+
# datasets
|
| 46 |
+
# evaluate
|
| 47 |
+
# huggingface-hub
|
| 48 |
+
h11==0.16.0
|
| 49 |
+
# via httpcore
|
| 50 |
+
hf-xet==1.2.0 ; platform_machine == 'AMD64' or platform_machine == 'aarch64' or platform_machine == 'amd64' or platform_machine == 'arm64' or platform_machine == 'x86_64'
|
| 51 |
+
# via huggingface-hub
|
| 52 |
+
httpcore==1.0.9
|
| 53 |
+
# via httpx
|
| 54 |
+
httpx==0.28.1
|
| 55 |
+
# via
|
| 56 |
+
# datasets
|
| 57 |
+
# huggingface-hub
|
| 58 |
+
huggingface-hub==1.2.3
|
| 59 |
+
# via
|
| 60 |
+
# datasets
|
| 61 |
+
# evaluate
|
| 62 |
+
idna==3.11
|
| 63 |
+
# via
|
| 64 |
+
# anyio
|
| 65 |
+
# httpx
|
| 66 |
+
# requests
|
| 67 |
+
# yarl
|
| 68 |
+
multidict==6.7.0
|
| 69 |
+
# via
|
| 70 |
+
# aiohttp
|
| 71 |
+
# yarl
|
| 72 |
+
multiprocess==0.70.18
|
| 73 |
+
# via
|
| 74 |
+
# datasets
|
| 75 |
+
# evaluate
|
| 76 |
+
numpy==2.2.6
|
| 77 |
+
# via
|
| 78 |
+
# datasets
|
| 79 |
+
# evaluate
|
| 80 |
+
# pandas
|
| 81 |
+
packaging==25.0
|
| 82 |
+
# via
|
| 83 |
+
# datasets
|
| 84 |
+
# evaluate
|
| 85 |
+
# huggingface-hub
|
| 86 |
+
pandas==2.3.3
|
| 87 |
+
# via
|
| 88 |
+
# datasets
|
| 89 |
+
# evaluate
|
| 90 |
+
propcache==0.4.1
|
| 91 |
+
# via
|
| 92 |
+
# aiohttp
|
| 93 |
+
# yarl
|
| 94 |
+
pyarrow==22.0.0
|
| 95 |
+
# via datasets
|
| 96 |
+
python-dateutil==2.9.0.post0
|
| 97 |
+
# via pandas
|
| 98 |
+
pytz==2025.2
|
| 99 |
+
# via pandas
|
| 100 |
+
pyyaml==6.0.3
|
| 101 |
+
# via
|
| 102 |
+
# datasets
|
| 103 |
+
# huggingface-hub
|
| 104 |
+
requests==2.32.5
|
| 105 |
+
# via
|
| 106 |
+
# datasets
|
| 107 |
+
# evaluate
|
| 108 |
+
shellingham==1.5.4
|
| 109 |
+
# via huggingface-hub
|
| 110 |
+
six==1.17.0
|
| 111 |
+
# via python-dateutil
|
| 112 |
+
tqdm==4.67.1
|
| 113 |
+
# via
|
| 114 |
+
# datasets
|
| 115 |
+
# evaluate
|
| 116 |
+
# huggingface-hub
|
| 117 |
+
typer-slim==0.21.0
|
| 118 |
+
# via huggingface-hub
|
| 119 |
+
typing-extensions==4.15.0
|
| 120 |
+
# via
|
| 121 |
+
# aiosignal
|
| 122 |
+
# anyio
|
| 123 |
+
# huggingface-hub
|
| 124 |
+
# typer-slim
|
| 125 |
+
tzdata==2025.3
|
| 126 |
+
# via pandas
|
| 127 |
+
urllib3==2.6.2
|
| 128 |
+
# via requests
|
| 129 |
+
xxhash==3.6.0
|
| 130 |
+
# via
|
| 131 |
+
# datasets
|
| 132 |
+
# evaluate
|
| 133 |
+
yarl==1.22.0
|
| 134 |
+
# via aiohttp
|