Phospheneser commited on
Commit
906535b
·
0 Parent(s):

Release RealLayoutArena

Browse files
.gitattributes ADDED
@@ -0,0 +1 @@
 
 
1
+ *.parquet filter=lfs diff=lfs merge=lfs -text
.gitignore ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ __pycache__/
2
+ *.py[cod]
3
+ .venv/
4
+ .cache/
5
+ .pytest_cache/
6
+ images/
7
+ scores/
8
+ jobs*.jsonl
9
+ ratings*.jsonl
10
+ .env
11
+ *.log
CODE_LICENSE ADDED
@@ -0,0 +1,201 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
LICENSE.md ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ # License scope
2
+
3
+ ## Dataset
4
+
5
+ The dataset contains benchmark prompts and scoring rubrics.
6
+
7
+ ## Software
8
+
9
+ The inference-adapter and evaluation scripts are provided under Apache License 2.0, included in [CODE_LICENSE](CODE_LICENSE).
README.md ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - zh
4
+ task_categories:
5
+ - text-to-image
6
+ size_categories:
7
+ - n<1K
8
+ license: other
9
+ license_name: real-layout-arena-assets
10
+ license_link: LICENSE.md
11
+ pretty_name: RealLayoutArena
12
+ tags:
13
+ - benchmark
14
+ - layout
15
+ - text-rendering
16
+ configs:
17
+ - config_name: default
18
+ default: true
19
+ data_files:
20
+ - split: test
21
+ path: data/test.parquet
22
+ ---
23
+
24
+ # RealLayoutArena
25
+
26
+ **English** | [简体中文](README_zh.md)
27
+
28
+ RealLayoutArena (RLA) is a text-to-image benchmark from the [MOSS-Image](https://github.com/OpenMOSS/MOSS-Image) project, designed for subjective arena evaluation. It contains **61 tasks** covering interfaces, posters, and infographics.
29
+
30
+ ## Dataset
31
+
32
+ | Category | Tasks |
33
+ |---|---:|
34
+ | UI | 21 |
35
+ | Poster | 20 |
36
+ | Infographic | 20 |
37
+ | **Total** | **61** |
38
+
39
+ Each task provides a Chinese prompt and target image dimensions. Canvases contain approximately one megapixel, with width and height divisible by 16.
40
+
41
+ ## Load
42
+
43
+ ```bash
44
+ pip install datasets
45
+ ```
46
+
47
+ ```python
48
+ from datasets import load_dataset
49
+
50
+ ds = load_dataset("OpenMOSS-Team/RealLayoutArena", split="test")
51
+ prompt = ds[0]["prompt"]
52
+ width, height = ds[0]["width"], ds[0]["height"]
53
+ ```
54
+
55
+ The dataset contains one `test` split. `data/test.parquet` and `layout_arena.jsonl` provide the same 61 tasks.
56
+
57
+ | Fields | Meaning |
58
+ |---|---|
59
+ | `id`, `category`, `title` | Task identifier, category, and title |
60
+ | `prompt_language` | Prompt language (`zh`) |
61
+ | `width`, `height` | Target generation dimensions |
62
+ | `prompt` | Input prompt |
63
+
64
+ ## Arena evaluation
65
+
66
+ Generate images from the same prompts across models, then present them in anonymous pairs for human preference voting. Comparisons focus on overall visual quality, layout, and text presentation.
67
+
68
+ To export generation inputs:
69
+
70
+ ```bash
71
+ python evaluation/bench.py export --output jobs.jsonl --seed 42
72
+ ```
73
+
74
+ See [generation utilities](evaluation/README.md) for the inference adapter.
75
+
76
+ <details>
77
+ <summary>Additional scoring tools</summary>
78
+
79
+ The dataset also includes per-task annotations in `rubric`. The `judge-tasks` and `summarize` commands in `evaluation/bench.py` support creating and aggregating ratings.
80
+
81
+ </details>
82
+
83
+ ## Citation
84
+
85
+ If you use RealLayoutArena, please cite the [MOSS-Image technical report](https://arxiv.org/abs/2610.23374):
86
+
87
+ ```bibtex
88
+ @misc{ai2026mossimagetechnicalreport,
89
+ title={MOSS-Image Technical Report},
90
+ author={MOSI. AI},
91
+ year={2026},
92
+ eprint={2610.23374},
93
+ archivePrefix={arXiv},
94
+ primaryClass={cs.CV},
95
+ url={https://arxiv.org/abs/2610.23374},
96
+ }
97
+ ```
98
+
99
+ ## License
100
+
101
+ Code is provided under [Apache-2.0](CODE_LICENSE). See [LICENSE.md](LICENSE.md) for license scope.
README_zh.md ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # RealLayoutArena
2
+
3
+ [English](README.md) | **简体中文**
4
+
5
+ RealLayoutArena(RLA)是 [MOSS-Image](https://github.com/OpenMOSS/MOSS-Image) 项目用于主观评测竞技场的文生图基准,包含界面、海报和信息图三个类别的 **61 个任务**。
6
+
7
+ ## 数据集
8
+
9
+ | 类别 | 任务数 |
10
+ |---|---:|
11
+ | UI | 21 |
12
+ | 海报 | 20 |
13
+ | 信息图 | 20 |
14
+ | **合计** | **61** |
15
+
16
+ 每个任务提供一条中文提示词及目标生成尺寸。画布约为一百万像素,宽高均为 16 的倍数。
17
+
18
+ ## 加载数据
19
+
20
+ ```bash
21
+ pip install datasets
22
+ ```
23
+
24
+ ```python
25
+ from datasets import load_dataset
26
+
27
+ ds = load_dataset("OpenMOSS-Team/RealLayoutArena", split="test")
28
+ prompt = ds[0]["prompt"]
29
+ width, height = ds[0]["width"], ds[0]["height"]
30
+ ```
31
+
32
+ 数据集包含一个 `test` 划分。`data/test.parquet` 与 `layout_arena.jsonl` 提供相同的 61 个任务。
33
+
34
+ | 字段 | 含义 |
35
+ |---|---|
36
+ | `id`, `category`, `title` | 任务标识、类别和标题 |
37
+ | `prompt_language` | 提示词语言(`zh`) |
38
+ | `width`, `height` | 目标生成尺寸 |
39
+ | `prompt` | 输入提示词 |
40
+
41
+ ## 竞技场评测
42
+
43
+ 使用相同提示词生成不同模型的图像,以匿名成对展示的方式进行人工偏好投票,比较整体视觉质量、布局和文字呈现。
44
+
45
+ 导出生成任务:
46
+
47
+ ```bash
48
+ python evaluation/bench.py export --output jobs.jsonl --seed 42
49
+ ```
50
+
51
+ 推理适配器用法见[生成工具说明](evaluation/README.md)。
52
+
53
+ <details>
54
+ <summary>附加评分工具</summary>
55
+
56
+ 数据中的 `rubric` 字段提供各任务的评测标注。`evaluation/bench.py` 还提供 `judge-tasks` 和 `summarize` 命令,用于创建评分任务和汇总结果。
57
+
58
+ </details>
59
+
60
+ ## 引用
61
+
62
+ 使用 RealLayoutArena 时,请引用 [MOSS-Image 技术报告](https://arxiv.org/abs/2610.23374):
63
+
64
+ ```bibtex
65
+ @misc{ai2026mossimagetechnicalreport,
66
+ title={MOSS-Image Technical Report},
67
+ author={MOSI. AI},
68
+ year={2026},
69
+ eprint={2610.23374},
70
+ archivePrefix={arXiv},
71
+ primaryClass={cs.CV},
72
+ url={https://arxiv.org/abs/2610.23374},
73
+ }
74
+ ```
75
+
76
+ ## 许可证
77
+
78
+ 代码采用 [Apache-2.0](CODE_LICENSE) 许可证,许可范围见 [LICENSE.md](LICENSE.md)。
data/test.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:58d673ca6c5ef2db2bb2763a897932e229272b2f517ec67ec687e05f6fcf39a1
3
+ size 33944
evaluation/README.md ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Generation utilities
2
+
3
+ RealLayoutArena is used for subjective arena evaluation: generate images for the same tasks across models and compare them through anonymous human preference voting.
4
+
5
+ Run these commands from the repository root with Python 3.10+ and Pillow:
6
+
7
+ ```bash
8
+ python evaluation/bench.py export --output jobs.jsonl --seed 42
9
+ python evaluation/local_inference.py --adapter my_adapter:generate \
10
+ --jobs jobs.jsonl --images images
11
+ ```
12
+
13
+ Provide `generate(*, prompt, seed, width, height)` in `my_adapter.py`, returning a PIL image. The exported jobs contain the 61 prompts and their target dimensions. Images are saved as `images/<id>.png` for use in the arena.
evaluation/bench.py ADDED
@@ -0,0 +1,181 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Export generation jobs, inspect images, and aggregate completed rubric ratings."""
3
+ import argparse
4
+ from collections import defaultdict
5
+ import hashlib
6
+ import json
7
+ from pathlib import Path
8
+
9
+ ROOT = Path(__file__).resolve().parents[1]
10
+
11
+
12
+ def read_rows(path):
13
+ return [json.loads(line) for line in Path(path).read_text(encoding='utf-8').splitlines()
14
+ if line.strip()]
15
+
16
+
17
+ def require(condition, message):
18
+ if not condition:
19
+ raise ValueError(message)
20
+
21
+
22
+ def positive_integer(value):
23
+ return type(value) is int and value > 0
24
+
25
+
26
+ def load_data():
27
+ rows = read_rows(ROOT / 'layout_arena.jsonl')
28
+ require(len(rows) == 61 and len({r['id'] for r in rows}) == 61,
29
+ 'Dataset must contain 61 unique IDs')
30
+ for row in rows:
31
+ sid = row['id']
32
+ require(isinstance(sid, str) and sid not in ('.', '..') and '/' not in sid
33
+ and '\\' not in sid and bool(sid), f'Invalid sample ID: {sid}')
34
+ require(positive_integer(row['width']) and positive_integer(row['height']),
35
+ f'{sid}: invalid target size')
36
+ rubric = row['rubric']
37
+ digest = hashlib.sha256(row['prompt'].encode('utf-8')).hexdigest()
38
+ require(rubric['prompt_sha256'] == digest and rubric['prompt_field'] == 'prompt',
39
+ f'{sid}: prompt/rubric mismatch')
40
+ dimensions = rubric['dimensions']
41
+ require(len(dimensions) == 6 and len({d['id'] for d in dimensions}) == 6,
42
+ f'{sid}: expected six rubric dimensions')
43
+ require(all(positive_integer(d['weight']) for d in dimensions)
44
+ and sum(d['weight'] for d in dimensions) == 100, f'{sid}: invalid rubric weights')
45
+ return rows
46
+
47
+
48
+ def write_rows(path, rows):
49
+ path = Path(path)
50
+ path.parent.mkdir(parents=True, exist_ok=True)
51
+ with path.open('x', encoding='utf-8') as handle:
52
+ for row in rows:
53
+ handle.write(json.dumps(row, ensure_ascii=False) + '\n')
54
+
55
+
56
+ def inspect_images(rows, directory):
57
+ from PIL import Image
58
+
59
+ root = Path(directory).resolve()
60
+ images, errors = [], []
61
+ for row in rows:
62
+ path = root / f"{row['id']}.png"
63
+ try:
64
+ with Image.open(path) as image:
65
+ image.load()
66
+ width, height = image.size
67
+ except (OSError, ValueError) as exc:
68
+ errors.append(f"{row['id']}: {exc}")
69
+ continue
70
+ images.append({'id': row['id'], 'image_path': str(path),
71
+ 'actual_width': width, 'actual_height': height,
72
+ 'size_compliant': (width, height) == (row['width'], row['height'])})
73
+ require(not errors, 'Missing or unreadable images:\n' + '\n'.join(errors))
74
+ return images
75
+
76
+
77
+ def export(args, rows):
78
+ jobs = [{'id': row['id'], 'prompt': row['prompt'],
79
+ 'seed': args.seed + index, 'width': row['width'], 'height': row['height'],
80
+ 'output_relpath': f"{row['id']}.png"} for index, row in enumerate(rows)]
81
+ write_rows(args.output, jobs)
82
+ print(json.dumps({'jobs': len(jobs), 'output': args.output}))
83
+
84
+
85
+ def check(args, rows):
86
+ images = inspect_images(rows, args.images)
87
+ print(json.dumps({'n': len(images), 'complete': True,
88
+ 'size_compliant_images': sum(i['size_compliant'] for i in images),
89
+ 'images': images}, ensure_ascii=False, indent=2))
90
+
91
+
92
+ def judge_tasks(args, rows):
93
+ images = inspect_images(rows, args.images)
94
+ tasks = []
95
+ for row, image in zip(rows, images):
96
+ rubric = row['rubric']
97
+ tasks.append({'id': row['id'],
98
+ 'prompt': row['prompt'], 'prompt_sha256': rubric['prompt_sha256'],
99
+ 'image_path': image['image_path'], 'actual_width': image['actual_width'],
100
+ 'actual_height': image['actual_height'], 'rubric': rubric,
101
+ 'scores': {d['id']: {'score': None, 'reason': ''} for d in rubric['dimensions']}})
102
+ write_rows(args.output, tasks)
103
+ print(json.dumps({'tasks': len(tasks), 'output': args.output}))
104
+
105
+
106
+ def aggregate(results):
107
+ names = results[0]['scores']
108
+ return {'n': len(results), 'mean_total': sum(r['total'] for r in results) / len(results),
109
+ 'dimension_means': {name: sum(r['scores'][name]['score'] for r in results) / len(results)
110
+ for name in names},
111
+ 'size_compliant_images': sum(r['size_compliant'] for r in results)}
112
+
113
+
114
+ def summarize(args, rows):
115
+ ratings = read_rows(args.scores)
116
+ expected = {r['id']: r for r in rows}
117
+ by_id = {}
118
+ for rating in ratings:
119
+ sid = rating['id']
120
+ require(sid in expected, f'Unknown sample ID: {sid}')
121
+ require(sid not in by_id, f'Duplicate sample ID: {sid}')
122
+ by_id[sid] = rating
123
+ require(set(by_id) == set(expected), 'Missing ratings: ' + ', '.join(sorted(set(expected) - set(by_id))))
124
+ results, categories = [], defaultdict(list)
125
+ for row in rows:
126
+ sid = row['id']
127
+ rating = by_id[sid]
128
+ rubric = row['rubric']
129
+ require(rating['prompt_sha256'] == rubric['prompt_sha256'], f'{sid}: prompt hash mismatch')
130
+ require(rating['prompt'] == row['prompt'], f'{sid}: prompt changed')
131
+ require(rating['rubric'] == rubric, f'{sid}: rubric changed')
132
+ scores = rating['scores']
133
+ require(isinstance(scores, dict) and set(scores) == {d['id'] for d in rubric['dimensions']},
134
+ f'{sid}: dimension mismatch')
135
+ for name, entry in scores.items():
136
+ require(isinstance(entry, dict), f'{sid}/{name}: expected score and reason')
137
+ score, reason = entry.get('score'), entry.get('reason')
138
+ require(type(score) is int and 0 <= score <= 5, f'{sid}/{name}: score must be integer 0..5')
139
+ require(isinstance(reason, str) and bool(reason.strip()), f'{sid}/{name}: reason is required')
140
+ width, height = rating['actual_width'], rating['actual_height']
141
+ require(positive_integer(width) and positive_integer(height), f'{sid}: invalid actual size')
142
+ total = sum(scores[d['id']]['score'] * d['weight'] for d in rubric['dimensions']) / 5
143
+ result = {**rating, 'category': row['category'], 'total': total,
144
+ 'size_compliant': (width, height) == (row['width'], row['height'])}
145
+ results.append(result)
146
+ categories[row['category']].append(result)
147
+ summary = {'complete': True, **aggregate(results),
148
+ 'aggregation': 'Equal mean over 61 tasks',
149
+ 'categories': {name: aggregate(items) for name, items in sorted(categories.items())}}
150
+ output = Path(args.output)
151
+ require(not output.exists() or (output.is_dir() and not any(output.iterdir())),
152
+ 'Output directory must be new or empty')
153
+ output.mkdir(parents=True, exist_ok=True)
154
+ write_rows(output / 'results.jsonl', results)
155
+ (output / 'summary.json').write_text(json.dumps(summary, ensure_ascii=False, indent=2) + '\n', encoding='utf-8')
156
+ print(json.dumps(summary, ensure_ascii=False))
157
+
158
+
159
+ def main():
160
+ parser = argparse.ArgumentParser(description=__doc__)
161
+ commands = parser.add_subparsers(dest='command', required=True)
162
+ for name, handler in [('export', export), ('check', check), ('judge-tasks', judge_tasks), ('summarize', summarize)]:
163
+ command = commands.add_parser(name)
164
+ command.set_defaults(handler=handler)
165
+ if name in ('check', 'judge-tasks'):
166
+ command.add_argument('--images', required=True)
167
+ if name != 'check':
168
+ command.add_argument('--output', required=True)
169
+ if name == 'export':
170
+ command.add_argument('--seed', type=int, default=42)
171
+ if name == 'summarize':
172
+ command.add_argument('--scores', required=True)
173
+ args = parser.parse_args()
174
+ try:
175
+ args.handler(args, load_data())
176
+ except (OSError, ValueError, KeyError, TypeError) as exc:
177
+ parser.exit(1, f'Error: {exc}\n')
178
+
179
+
180
+ if __name__ == '__main__':
181
+ main()
evaluation/local_inference.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Adapt an existing inference function returning PIL.Image to the exported jobs."""
3
+ import argparse
4
+ import importlib
5
+ import json
6
+ from pathlib import Path
7
+ import sys
8
+
9
+ sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
10
+
11
+
12
+ def main():
13
+ parser = argparse.ArgumentParser(description=__doc__)
14
+ parser.add_argument("--adapter", required=True, help="importable module:function returning PIL.Image")
15
+ parser.add_argument("--jobs", required=True)
16
+ parser.add_argument("--images", required=True)
17
+ parser.add_argument("--num-shards", type=int, default=1)
18
+ parser.add_argument("--shard-index", type=int, default=0)
19
+ args = parser.parse_args()
20
+ if args.num_shards < 1 or not 0 <= args.shard_index < args.num_shards:
21
+ parser.error("require 0 <= shard-index < num-shards")
22
+ module, name = args.adapter.split(":", 1)
23
+ generate = getattr(importlib.import_module(module), name)
24
+ root = Path(args.images).resolve()
25
+ jobs = [json.loads(line) for line in Path(args.jobs).read_text(encoding="utf-8").splitlines() if line.strip()]
26
+ for index, job in enumerate(jobs):
27
+ if index % args.num_shards != args.shard_index:
28
+ continue
29
+ target = (root / job["output_relpath"]).resolve()
30
+ if not target.is_relative_to(root):
31
+ raise ValueError(f"Output path escapes image root: {target}")
32
+ target.parent.mkdir(parents=True, exist_ok=True)
33
+ image = generate(prompt=job["prompt"], seed=job["seed"], width=job["width"], height=job["height"])
34
+ image.save(target, format="PNG")
35
+ print(f"[{index + 1}/{len(jobs)}] {target}", flush=True)
36
+
37
+
38
+ if __name__ == "__main__":
39
+ main()
evaluation/requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ Pillow>=9.1
layout_arena.jsonl ADDED
The diff for this file is too large to render. See raw diff