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 3 |
+
emoji: 📊
|
| 4 |
+
colorFrom: pink
|
| 5 |
+
colorTo: purple
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: 4.36.1
|
| 8 |
+
app_file: app.py
|
| 9 |
+
pinned: false
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
+
# Layout Average IoU
|
| 13 |
+
|
| 14 |
+
## Description
|
| 15 |
+
|
| 16 |
+
The Layout Average IoU metric computes the average Intersection over Union (IoU) for all pairs of overlapping elements in a layout. This metric evaluates how efficiently elements are arranged by measuring the degree of overlap between layout components.
|
| 17 |
+
|
| 18 |
+
## What It Measures
|
| 19 |
+
|
| 20 |
+
This metric implements two variants of average IoU that have been used in different layout generation research:
|
| 21 |
+
|
| 22 |
+
1. **VTN (Variational Transformer Networks)**: Standard geometric IoU calculation
|
| 23 |
+
2. **BLT (Bidirectional Layout Transformer)**: Perceptual IoU that considers the global union area on a discrete grid
|
| 24 |
+
|
| 25 |
+
Lower values generally indicate better layouts with less overlap between elements.
|
| 26 |
+
|
| 27 |
+
## Metric Details
|
| 28 |
+
|
| 29 |
+
- Computes IoU for all pairs of elements in a layout (excluding diagonal comparisons where elements would overlap with themselves)
|
| 30 |
+
- Only considers pairs with IoU > 0 (actual overlap)
|
| 31 |
+
- Returns the mean IoU across all overlapping pairs
|
| 32 |
+
- Returns 0.0 for layouts with 0 or 1 elements (no overlap possible)
|
| 33 |
+
|
| 34 |
+
## Usage
|
| 35 |
+
|
| 36 |
+
### Installation
|
| 37 |
+
|
| 38 |
+
```bash
|
| 39 |
+
pip install evaluate
|
| 40 |
+
```
|
| 41 |
+
|
| 42 |
+
### Basic Example
|
| 43 |
+
|
| 44 |
+
```python
|
| 45 |
+
import evaluate
|
| 46 |
+
import numpy as np
|
| 47 |
+
|
| 48 |
+
# Load the metric
|
| 49 |
+
metric = evaluate.load("creative-graphic-design/layout-average-iou")
|
| 50 |
+
|
| 51 |
+
# Single layout processing
|
| 52 |
+
num_samples, num_coordinates = 24, 4
|
| 53 |
+
layout = {
|
| 54 |
+
"bboxes": np.random.rand(num_samples, num_coordinates),
|
| 55 |
+
"categories": np.random.randint(0, num_coordinates, size=(num_samples,)),
|
| 56 |
+
}
|
| 57 |
+
metric.add(layouts=layout)
|
| 58 |
+
print(metric.compute())
|
| 59 |
+
```
|
| 60 |
+
|
| 61 |
+
### Batch Processing Example
|
| 62 |
+
|
| 63 |
+
```python
|
| 64 |
+
import evaluate
|
| 65 |
+
import numpy as np
|
| 66 |
+
|
| 67 |
+
# Load the metric
|
| 68 |
+
metric = evaluate.load("creative-graphic-design/layout-average-iou")
|
| 69 |
+
|
| 70 |
+
# Batch processing
|
| 71 |
+
batch_size, num_samples, num_coordinates = 512, 24, 4
|
| 72 |
+
layouts = [
|
| 73 |
+
{
|
| 74 |
+
"bboxes": np.random.rand(num_samples, num_coordinates),
|
| 75 |
+
"categories": np.random.randint(0, num_coordinates, size=(num_samples,)),
|
| 76 |
+
}
|
| 77 |
+
for _ in range(batch_size)
|
| 78 |
+
]
|
| 79 |
+
metric.add_batch(layouts=layouts)
|
| 80 |
+
print(metric.compute())
|
| 81 |
+
```
|
| 82 |
+
|
| 83 |
+
## Parameters
|
| 84 |
+
|
| 85 |
+
### Initialization Parameters
|
| 86 |
+
|
| 87 |
+
This metric does not require any initialization parameters.
|
| 88 |
+
|
| 89 |
+
### Computation Parameters
|
| 90 |
+
|
| 91 |
+
- **layouts** (`list` of `dict`): A list of dictionaries representing layouts, where each dictionary contains:
|
| 92 |
+
- **bboxes** (`list` of `float`): Bounding boxes in center-x, center-y, width, height (xywh) format
|
| 93 |
+
- **categories** (`list` of `int`): Category labels for each element
|
| 94 |
+
|
| 95 |
+
## Returns
|
| 96 |
+
|
| 97 |
+
Returns a dictionary containing:
|
| 98 |
+
|
| 99 |
+
- **average-iou_BLT** (`float`): Average IoU using the perceptual IoU method from BLT
|
| 100 |
+
- **average-iou_VTN** (`float`): Average IoU using standard geometric IoU from VTN
|
| 101 |
+
|
| 102 |
+
## Interpretation
|
| 103 |
+
|
| 104 |
+
- **Lower values** indicate better layouts with less element overlap
|
| 105 |
+
- **Value of 0.0**: No overlapping elements (ideal for most layout types)
|
| 106 |
+
- **Higher values**: More overlap between elements, potentially indicating layout quality issues
|
| 107 |
+
- **Typical range**: 0.0 to 1.0
|
| 108 |
+
|
| 109 |
+
The two variants (BLT and VTN) may produce slightly different values due to their different calculation methods:
|
| 110 |
+
|
| 111 |
+
- **VTN** uses standard geometric IoU
|
| 112 |
+
- **BLT** uses perceptual IoU with discrete grid quantization (32x32)
|
| 113 |
+
|
| 114 |
+
## Citations
|
| 115 |
+
|
| 116 |
+
```bibtex
|
| 117 |
+
@inproceedings{arroyo2021variational,
|
| 118 |
+
title={Variational transformer networks for layout generation},
|
| 119 |
+
author={Arroyo, Diego Martin and Postels, Janis and Tombari, Federico},
|
| 120 |
+
booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition},
|
| 121 |
+
pages={13642--13652},
|
| 122 |
+
year={2021}
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
@inproceedings{kong2022blt,
|
| 126 |
+
title={BLT: bidirectional layout transformer for controllable layout generation},
|
| 127 |
+
author={Kong, Xiang and Jiang, Lu and Chang, Huiwen and Zhang, Han and Hao, Yuan and Gong, Haifeng and Essa, Irfan},
|
| 128 |
+
booktitle={European Conference on Computer Vision},
|
| 129 |
+
pages={474--490},
|
| 130 |
+
year={2022},
|
| 131 |
+
organization={Springer}
|
| 132 |
+
}
|
| 133 |
+
```
|
| 134 |
+
|
| 135 |
+
## References
|
| 136 |
+
|
| 137 |
+
- **Paper**: [Variational Transformer Networks for Layout Generation (Arroyo et al., CVPR 2021)](https://arxiv.org/abs/2104.02416)
|
| 138 |
+
- **Paper**: [BLT: Bidirectional Layout Transformer for Controllable Layout Generation (Kong et al., ECCV 2022)](https://arxiv.org/abs/2112.05112)
|
| 139 |
+
- **Reference Implementation**: [layout-dm metric implementation](https://github.com/CyberAgentAILab/layout-dm/blob/main/src/trainer/trainer/helpers/metric.py#L399-L431)
|
| 140 |
+
- **Hugging Face Space**: [creative-graphic-design/layout-average-iou](https://huggingface.co/spaces/creative-graphic-design/layout-average-iou)
|
| 141 |
+
|
| 142 |
+
## Related Metrics
|
| 143 |
+
|
| 144 |
+
- [Layout Maximum IoU](../layout_maximum_iou/): Measures maximum IoU between two layout sets
|
| 145 |
+
- [Layout Overlap](../layout_overlap/): Alternative overlap metrics from various research works
|
| 146 |
+
- [Layout Alignment](../layout_alignment/): Measures spatial alignment of layout elements
|
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_average_iou --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-average-iou
|
| 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
|