File size: 4,920 Bytes
39628ce
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
---
title: Layout Average IoU
emoji: 📊
colorFrom: pink
colorTo: purple
sdk: gradio
sdk_version: 4.36.1
app_file: app.py
pinned: false
---

# Layout Average IoU

## Description

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.

## What It Measures

This metric implements two variants of average IoU that have been used in different layout generation research:

1. **VTN (Variational Transformer Networks)**: Standard geometric IoU calculation
2. **BLT (Bidirectional Layout Transformer)**: Perceptual IoU that considers the global union area on a discrete grid

Lower values generally indicate better layouts with less overlap between elements.

## Metric Details

- Computes IoU for all pairs of elements in a layout (excluding diagonal comparisons where elements would overlap with themselves)
- Only considers pairs with IoU > 0 (actual overlap)
- Returns the mean IoU across all overlapping pairs
- Returns 0.0 for layouts with 0 or 1 elements (no overlap possible)

## Usage

### Installation

```bash
pip install evaluate
```

### Basic Example

```python
import evaluate
import numpy as np

# Load the metric
metric = evaluate.load("creative-graphic-design/layout-average-iou")

# Single layout processing
num_samples, num_coordinates = 24, 4
layout = {
    "bboxes": np.random.rand(num_samples, num_coordinates),
    "categories": np.random.randint(0, num_coordinates, size=(num_samples,)),
}
metric.add(layouts=layout)
print(metric.compute())
```

### Batch Processing Example

```python
import evaluate
import numpy as np

# Load the metric
metric = evaluate.load("creative-graphic-design/layout-average-iou")

# Batch processing
batch_size, num_samples, num_coordinates = 512, 24, 4
layouts = [
    {
        "bboxes": np.random.rand(num_samples, num_coordinates),
        "categories": np.random.randint(0, num_coordinates, size=(num_samples,)),
    }
    for _ in range(batch_size)
]
metric.add_batch(layouts=layouts)
print(metric.compute())
```

## Parameters

### Initialization Parameters

This metric does not require any initialization parameters.

### Computation Parameters

- **layouts** (`list` of `dict`): A list of dictionaries representing layouts, where each dictionary contains:
  - **bboxes** (`list` of `float`): Bounding boxes in center-x, center-y, width, height (xywh) format
  - **categories** (`list` of `int`): Category labels for each element

## Returns

Returns a dictionary containing:

- **average-iou_BLT** (`float`): Average IoU using the perceptual IoU method from BLT
- **average-iou_VTN** (`float`): Average IoU using standard geometric IoU from VTN

## Interpretation

- **Lower values** indicate better layouts with less element overlap
- **Value of 0.0**: No overlapping elements (ideal for most layout types)
- **Higher values**: More overlap between elements, potentially indicating layout quality issues
- **Typical range**: 0.0 to 1.0

The two variants (BLT and VTN) may produce slightly different values due to their different calculation methods:

- **VTN** uses standard geometric IoU
- **BLT** uses perceptual IoU with discrete grid quantization (32x32)

## Citations

```bibtex
@inproceedings{arroyo2021variational,
  title={Variational transformer networks for layout generation},
  author={Arroyo, Diego Martin and Postels, Janis and Tombari, Federico},
  booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition},
  pages={13642--13652},
  year={2021}
}

@inproceedings{kong2022blt,
  title={BLT: bidirectional layout transformer for controllable layout generation},
  author={Kong, Xiang and Jiang, Lu and Chang, Huiwen and Zhang, Han and Hao, Yuan and Gong, Haifeng and Essa, Irfan},
  booktitle={European Conference on Computer Vision},
  pages={474--490},
  year={2022},
  organization={Springer}
}
```

## References

- **Paper**: [Variational Transformer Networks for Layout Generation (Arroyo et al., CVPR 2021)](https://arxiv.org/abs/2104.02416)
- **Paper**: [BLT: Bidirectional Layout Transformer for Controllable Layout Generation (Kong et al., ECCV 2022)](https://arxiv.org/abs/2112.05112)
- **Reference Implementation**: [layout-dm metric implementation](https://github.com/CyberAgentAILab/layout-dm/blob/main/src/trainer/trainer/helpers/metric.py#L399-L431)
- **Hugging Face Space**: [creative-graphic-design/layout-average-iou](https://huggingface.co/spaces/creative-graphic-design/layout-average-iou)

## Related Metrics

- [Layout Maximum IoU](../layout_maximum_iou/): Measures maximum IoU between two layout sets
- [Layout Overlap](../layout_overlap/): Alternative overlap metrics from various research works
- [Layout Alignment](../layout_alignment/): Measures spatial alignment of layout elements