TaobaoTmall-AlgorithmProducts commited on
Commit
4daada3
·
verified ·
1 Parent(s): 43f4b89

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +269 -0
README.md ADDED
@@ -0,0 +1,269 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: cc-by-nc-nd-4.0
3
+ configs:
4
+ - config_name: general
5
+ data_files:
6
+ - split: train
7
+ path: CPI_general_benchmark/CPI_general_benchmark-*.parquet
8
+ - config_name: practical
9
+ data_files:
10
+ - split: train
11
+ path: CPI_practical_benchmark/CPI_practical_benchmark-*.parquet
12
+ - config_name: intelligent
13
+ data_files:
14
+ - split: train
15
+ path: CPI_intelligent_benchmark/CPI_intelligent_benchmark-*.parquet
16
+ ---
17
+
18
+
19
+ # CPI-Bench
20
+
21
+ [![Hugging Face Dataset](https://img.shields.io/badge/🤗-Dataset-yellow)](https://huggingface.co/datasets/TaobaoTmall-AlgorithmProducts/CPI-benchmark)
22
+ [![License](https://img.shields.io/badge/License-CC%20BY--NC--ND%204.0-lightgrey)](#license)
23
+
24
+ ## Introduction
25
+
26
+ CPI-Bench is a comprehensive suite of benchmarks designed to evaluate whether an image
27
+ generation/editing model is truly capable of handling diverse, real-world, and
28
+ knowledge-intensive tasks. It consists of four complementary subsets:
29
+
30
+ | Benchmark | Description | Data Files |
31
+ |---|---|---|
32
+ | **CPI-General-Benchmark** | General-purpose image editing tasks covering a wide range of task types | `CPI_general_benchmark/CPI_general_benchmark-*.parquet` |
33
+ | **CPI-Practical-Benchmark** | Image editing tasks grounded in everyday, real-life scenarios | `CPI_practical_benchmark/CPI_practical_benchmark-*.parquet` |
34
+ | **CPI-Intelligent-Benchmark** | Image editing tasks that require domain knowledge and multi-step reasoning, with reference input image(s) | `CPI_intelligent_benchmark-*.parquet` |
35
+ parquet` |
36
+
37
+ Each sample provides an editing/generation instruction (and, for image-editing tasks,
38
+ one or more reference images). Models are expected to produce an output image
39
+ accordingly, which is then scored by a VLM-as-Judge (e.g., Gemini) across multiple
40
+ quality dimensions.
41
+
42
+ ## ✨ Key Features
43
+
44
+ - **Four Complementary Subsets**: covers general-purpose editing, life-scenario
45
+ editing, and knowledge-intensive reasoning for both image-editing (i2i) and
46
+ text-to-image (t2i) settings.
47
+ - **Multi-Image Input Support**: `source` fields may contain one or multiple
48
+ reference images, supporting complex multi-image editing scenarios.
49
+ - **Bilingual Instructions**: Chinese and English instructions are provided for
50
+ every subset, enabling cross-lingual evaluation.
51
+ - **Reasoning-Aware Annotations**: the reasoning subsets additionally provide a
52
+ `rationale` field — a reference reasoning trace from instruction to expected
53
+ result, used as *guidance material* (not a hard ground truth) during scoring.
54
+ - **VLM-Driven Automatic Evaluation**: each subset ships with a ready-to-use,
55
+ multi-dimension VLM-as-Judge evaluation toolkit (see below).
56
+
57
+ ## ✨ Key Attributes
58
+
59
+ **CPI-General-Benchmark / CPI-Practical-Benchmark fields:**
60
+
61
+ | Field | Description |
62
+ |---|---|
63
+ | `id` | Unique sample ID |
64
+ | `task` | Task category, used to select the corresponding scoring prompt template |
65
+ | `a_to_b_instructions` | Editing instruction in Chinese |
66
+ | `a_to_b_instructions_eng` | Editing instruction in English |
67
+ | `target_resolution` | Target output resolution |
68
+ | `source` | `List[PIL.Image]` — one or more reference input images |
69
+
70
+ **CPI-Intelligent-Benchmark fields:**
71
+
72
+ | Field | Description |
73
+ |---|---|
74
+ | `id` | Unique sample ID |
75
+ | `expert_domain` | Domain category, formatted as `"<domain>-<subtask>"` |
76
+ | `a_to_b_instructions` | Editing instruction in Chinese |
77
+ | `a_to_b_instructions_eng` | Editing instruction in English |
78
+ | `rationale` | Reference reasoning trace (guidance material for scoring; may be empty) |
79
+ | `target_resolution` | Target output resolution |
80
+ | `source` | `List[PIL.Image]` — one or more reference input images |
81
+
82
+
83
+ ## Loading
84
+
85
+ ```python
86
+ from datasets import load_dataset
87
+
88
+ # Load a specific subset directly from the Hub (recommended)
89
+ dataset = load_dataset("TaobaoTmall-AlgorithmProducts/CPI-benchmark", "general", split="train")
90
+ print(dataset)
91
+ print(dataset[0])
92
+
93
+ # Other available configs: "practical", "intelligent"
94
+ dataset = load_dataset("TaobaoTmall-AlgorithmProducts/CPI-benchmark", "intelligent", split="train")
95
+
96
+ # Alternatively, download the repo manually and load from local parquet files
97
+ dataset = load_dataset(
98
+ "parquet",
99
+ data_files="/path/to/local/CPI_general_benchmark/CPI_general_benchmark-*.parquet",
100
+ split="train",
101
+ )
102
+ ```
103
+
104
+ ---
105
+
106
+ # CPI-Bench - Evaluation Toolkit
107
+
108
+ An automated evaluation toolkit for image generation/editing models, powered by
109
+ VLM-as-Judge (e.g., Gemini). Given a set of model outputs, the toolkit scores each
110
+ sample across multiple quality dimensions and produces an aggregated report.
111
+
112
+ The toolkit is located under [`bench_eval_code/`](bench_eval_code) and provides one
113
+ evaluation script per subset:
114
+
115
+ | Subset | Script | Prompt Config |
116
+ |---|---|---|
117
+ | CPI-General-Benchmark | `bench_eval_code/eval_general_practical.py --benchmark general` | `bench_eval_code/prompts/general_prompts.json` |
118
+ | CPI-Practical-Benchmark | `bench_eval_code/eval_general_practical.py --benchmark practical` | `bench_eval_code/prompts/practical_prompts.json` |
119
+ | CPI-Intelligent-Benchmark | `bench_eval_code/eval_intelligent.py` | `bench_eval_code/prompts/intelligent_prompts.json` |
120
+
121
+ ## Scoring Dimensions
122
+
123
+ **CPI-General-Benchmark / CPI-Practical-Benchmark**
124
+
125
+ Each `task` type is mapped to a task-specific scoring prompt template (defined in
126
+ `general_prompts.json` / `practical_prompts.json`). The judge VLM outputs a score for each
127
+ dimension in the format `DimensionName: score`, and the sample's final score is the
128
+ arithmetic mean across all dimensions returned for that task.
129
+
130
+ **CPI-Intelligent-Benchmark** — 3 dimensions, each scored 1.0–5.0:
131
+
132
+ | Dimension | Weight | What it measures |
133
+ |---|---|---|
134
+ | Knowledge Reasoning | 45% | Factual/domain-knowledge correctness, fused with `rationale` as reference guidance |
135
+ | Visual Quality | 30% | Overall visual/aesthetic quality of the generated result |
136
+ | Input Consistency | 25% | Consistency between the result and the reference input image(s) |
137
+
138
+ The final score is a weighted sum of the three dimensions above. If the Knowledge
139
+ Reasoning score is ≤ 2, the final score is additionally multiplied by 0.6 as a
140
+ penalty for factual/knowledge errors.
141
+
142
+
143
+ ## How It Works
144
+
145
+ - **General / Practical**: a single VLM call per sample — sends
146
+ `[reference image(s)..., result, scoring prompt]` and parses per-dimension scores
147
+ from the response.
148
+ - **Intelligent**: a split-call strategy — one VLM call per dimension
149
+ (Knowledge Reasoning, Visual Quality, and for i2i, Input Consistency), so the judge
150
+ can focus on one aspect at a time for more reliable scoring.
151
+
152
+ ## Input Format
153
+
154
+ First, generate your model's outputs for each sample. If you are not sure which row
155
+ corresponds to which image(s)/instruction, use the export helper first — it
156
+ auto-detects the dataset schema (image-editing vs. text-to-image) and works for all
157
+ four subsets:
158
+
159
+ ```bash
160
+ python bench_eval_code/export_samples.py \
161
+ --dataset_path "/path/to/CPI_general_benchmark/CPI_general_benchmark-*.parquet" \
162
+ --output_dir ./exported_general \
163
+ --lang eng \
164
+ --workers 16
165
+ ```
166
+
167
+ This produces:
168
+ - `source_images/` — reference input images per sample (skipped entirely for the t2i subset, which has no reference images)
169
+ - `samples.jsonl` — per-sample metadata: `sample_index`, `id`, `task`, `instruction`, `rationale` (if present)
170
+ - `result_template.jsonl` — a template result file; fill in the `result` field with your model's output path after inference
171
+
172
+ Then prepare a JSONL file mapping each benchmark sample index to your model's
173
+ generated result image:
174
+
175
+ ```jsonl
176
+ {"sample_index": 0, "result": "/path/to/result_0.png"}
177
+ {"sample_index": 1, "result": "/path/to/result_1.png"}
178
+ {"sample_index": 2, "result": "/path/to/result_2.png"}
179
+ ```
180
+
181
+ - `sample_index`: the 0-based row index into the loaded HF dataset
182
+ - `result`: path to your model's generated image for that sample
183
+
184
+ ## Usage
185
+
186
+ **CPI-General-Benchmark / CPI-Practical-Benchmark:**
187
+
188
+ ```bash
189
+ python bench_eval_code/eval_general_practical.py \
190
+ --benchmark general \
191
+ --dataset_path "/path/to/CPI_general_benchmark/CPI_general_benchmark-*.parquet" \
192
+ --result_jsonl "/path/to/my_results.jsonl" \
193
+ --prompts_json bench_eval_code/prompts/general_prompts.json \
194
+ --output_dir eval_output/my_model_general \
195
+ --api_key "YOUR_API_KEY" \
196
+ --lang eng \
197
+ --workers 8
198
+ ```
199
+
200
+ Use `--benchmark practical` and `bench_eval_code/prompts/practical_prompts.json` to evaluate
201
+ the Practical benchmark instead.
202
+
203
+ **CPI-Intelligent-Benchmark:**
204
+
205
+ ```bash
206
+ python bench_eval_code/eval_intelligent.py \
207
+ --dataset_path "/path/to/CPI_intelligent_benchmark/CPI_intelligent_benchmark-*.parquet" \
208
+ --result_jsonl "/path/to/my_results_i2i.jsonl" \
209
+ --prompts_json bench_eval_code/prompts/intelligent_prompts.json \
210
+ --output_dir eval_output/my_model_intelligent \
211
+ --api_key "YOUR_API_KEY" \
212
+ --lang eng \
213
+ --workers 8
214
+ ```
215
+
216
+
217
+ ## Output
218
+
219
+ Each script produces two files in `--output_dir`:
220
+
221
+ - **`cases.jsonl`** — per-sample scoring details (per-dimension scores + raw VLM responses)
222
+ - **`summary.json`** — aggregated scores, broken down by task type / domain / dimension
223
+
224
+ For the t2i subset, `summary.json` additionally includes:
225
+ - `overall_avg_score_pct` — the 1–5 score mapped to a 0–100 percentage scale
226
+ - `overall_perfect_rate` — the fraction of samples that achieve the maximum score (5) on both dimensions
227
+ - `by_domain` — scores aggregated by top-level domain (the part of `expert_domain` before the `-`)
228
+
229
+ ## Features
230
+
231
+ - **Resume support**: if evaluation is interrupted, re-running the same command
232
+ will skip already-scored samples (found in `cases.jsonl`) and continue from
233
+ where it left off. Use `--no_resume` to force a full re-run.
234
+ - **Multi-key rotation**: pass multiple API keys (comma-separated via `--api_key`)
235
+ to distribute requests across keys and avoid rate limits.
236
+ - **Concurrent scoring**: use `--workers` to control parallelism for faster evaluation.
237
+ - **Custom VLM endpoint**: any OpenAI-compatible API can be used via `--base_url`
238
+ and `--model`.
239
+
240
+ ## File Structure
241
+
242
+ ```
243
+ bench_eval_code/
244
+ ├── bench_utils.py # Shared utilities: API key pool, image helpers, retry-wrapped VLM caller
245
+ ├── eval_general_practical.py # Evaluation script for General / Practical benchmarks
246
+ ├── eval_intelligent.py # Evaluation script for Intelligent benchmark
247
+ ├── export_samples.py # Dataset export helper (auto-detects schema, multi-threaded)
248
+ └── prompts/
249
+ ├── general_prompts.json
250
+ ├── practical_prompts.json
251
+ └── intelligent_prompts.json
252
+ ```
253
+
254
+ ## License
255
+
256
+ CPI-Bench is released under the Creative Commons Attribution–NonCommercial–NoDerivatives
257
+ (CC BY-NC-ND 4.0) license.
258
+
259
+ - ✅ Free for academic research purposes only
260
+ - ❌ Commercial use is prohibited
261
+
262
+ By using this dataset, you agree to comply with the applicable license terms.
263
+
264
+ ## 🖊️ Citation
265
+
266
+ If you find CPI-Bench useful for your research, please consider citing:
267
+
268
+ ```bibtex
269
+ ```