Model Card for LayoutGAN++¶
This package ports LayoutGAN++, the Const-layout generator method, into a 🤗transformers-style package under the literature method name. The package includes training infrastructure and measured S0-S4 staged evidence for the cached Magazine fixture; S5 full-run reproduction is not claimed and remains a separate decision for all datasets.
Model Details¶
Model Description¶
LayoutGAN++ is a transformers-style wrapper around the Const-layout generator for RICO13, PubLayNet, and Magazine layouts. It generates element boxes from label prompts with the converted generator and processor while keeping original-implementation-specific label and coordinate handling behind the package boundary. Public outputs use normalized center xywh boxes in [0, 1], dataset-local integer labels, a valid-element mask, and id2label.
- Developed by: Kotaro Kikuchi et al.
- Shared by: creative-graphic-design.
- Model type: content-agnostic; task: single-task; conditioning: label.
- Language(s) (NLP): not applicable.
- License: agpl-3.0.
Model Sources¶
- Repository: Const-layout repository
- Paper: DOI 10.1145/3474085.3475497
Supported Checkpoints¶
| Checkpoint | Hub ID | Status |
|---|---|---|
| RICO13 | creative-graphic-design/layoutganpp-rico |
not-published |
| PubLayNet | creative-graphic-design/layoutganpp-publaynet |
not-published |
| Magazine | creative-graphic-design/layoutganpp-magazine |
not-published |
Uses¶
Direct Use¶
Use this package for research inference, conversion checks, and agreement checks against the original implementation for generated layouts.
Conditional generation accepts label prompts for the converted generator:
from layoutganpp import LayoutGANPPPipeline
pipe = LayoutGANPPPipeline.from_pretrained(
"creative-graphic-design/layoutganpp-publaynet"
)
out = pipe(labels=[["text", "figure"]], seed=0)
print(out.bbox, out.labels, out.mask)
Model/processor usage is also available for lower-level checks:
from layoutganpp import LayoutGANPPModel, LayoutGANPPProcessor
model = LayoutGANPPModel.from_pretrained(
"creative-graphic-design/layoutganpp-publaynet"
).eval()
processor = LayoutGANPPProcessor.from_pretrained(
"creative-graphic-design/layoutganpp-publaynet"
)
encoded = processor([["text", "figure"]])
out = model.generate(**encoded, seed=0)
print(processor.batch_decode(out.bbox, out.labels, out.mask))
Downstream Use¶
Generated layouts may feed rendering, design tooling, layout evaluation, or downstream content placement systems after task-specific validation.
Out-of-Scope Use¶
Do not treat generated layouts as production accessibility annotations, OCR output, semantic scene understanding, or license-cleared design assets without separate review.
Bias, Risks, and Limitations¶
The converted behavior follows the upstream checkpoints, prompt fixtures, and datasets. Dataset coverage, label vocabularies, and layout quality inherit the limits of those sources.
Recommendations¶
Re-run the agreement-check suite against the original implementation before publishing converted checkpoints or comparing new results.
How to Get Started with the Model¶
Install the package directly from this repository. The command includes shared packages when they are not published on PyPI.
pip install \
"laygen @ git+https://github.com/creative-graphic-design/design-generators.git#subdirectory=lib/laygen" \
"layoutganpp @ git+https://github.com/creative-graphic-design/design-generators.git#subdirectory=models/layoutganpp"
Clone this repository, install the workspace member, and run the download and conversion steps in REPRODUCING.md. Those steps create .cache/layoutganpp/converted/layoutganpp-rico.
git clone https://github.com/creative-graphic-design/design-generators.git
cd design-generators
uv sync --package layoutganpp
uv run --package layoutganpp python
from layoutganpp import LayoutGANPPPipeline
path = ".cache/layoutganpp/converted/layoutganpp-rico"
# After Hub publication: from_pretrained("creative-graphic-design/layoutganpp-rico")
pipe = LayoutGANPPPipeline.from_pretrained(path)
out = pipe(labels=[["Toolbar", "Image"]], seed=0)
print(out.bbox)
print(out.labels)
print(out.mask)
Training Details¶
Training Data¶
| Dataset | Dataset ID | Notes |
|---|---|---|
| RICO13 | creative-graphic-design/Rico |
ui-screenshots-and-hierarchies-with-semantic-annotations |
| PubLayNet | creative-graphic-design/PubLayNet |
default |
| Magazine | creative-graphic-design/magazine |
polygon-based train-only source |
The LayoutGAN++ rico checkpoint uses the original 13-class RICO label space (Toolbar, Image, Text, ...). The dataset badge and metadata point to creative-graphic-design/Rico because that is the canonical hosted source; the processor keeps the checkpoint-local RICO13 label mapping in id2label.
Training Procedure¶
This package ports released behavior and includes package-local training infrastructure. S0-S4 staged evidence is complete for the cached Magazine fixture; S5 full-run training and evaluation are not claimed.
Preprocessing¶
Inputs and outputs are normalized to the public layout schema at package boundaries. Boxes, tokens, prompts, or analog bits that follow the original implementation stay inside package adapters and fixtures used for agreement checks.
Training Hyperparameters¶
- Training regime: original upstream recipe represented by package-local configs; S0-S4 staged evidence is available for Magazine, while S5 full-run training is not claimed.
Speeds, Sizes, Times¶
Training-time and carbon measurements are unknown.
Evaluation¶
Testing Data, Factors & Metrics¶
Testing Data¶
Agreement checks use local-only generated fixtures and converted checkpoint directories. Large generated tensors, images, weights, and downloaded artifacts are not committed.
Factors¶
Agreement results are reported separately by dataset, checkpoint, condition mode, seed, or prompt fixture where the package has recorded evidence.
Metrics¶
Metrics are exact tensor equality, exact token or byte equality, or an explicitly stated numeric tolerance against the original implementation.
Parity Results¶
| Dataset | Compared artifact | Cases | Match criterion | Result |
|---|---|---|---|---|
| Rico | Original-implementation netG fixture vs. converted LayoutGANPPModel |
1 | (3, 9, 4) bbox; torch.testing.assert_close(atol=1e-6, rtol=1e-5) |
passed |
| PubLayNet | Original-implementation netG fixture vs. converted LayoutGANPPModel |
1 | (3, 9, 4) bbox; torch.testing.assert_close(atol=1e-6, rtol=1e-5) |
passed |
| Magazine | Original-implementation netG fixture vs. converted LayoutGANPPModel |
1 | (3, 33, 4) bbox; torch.testing.assert_close(atol=1e-6, rtol=1e-5) |
passed |
Reproducibility¶
See REPRODUCING.md for the commands that download original-implementation assets, generate reference outputs, run agreement checks, convert checkpoints, and smoke-test local loading.
Environmental Impact¶
No S5 full-run model training is claimed by this package. Conversion, staged training checks, and agreement-check costs depend on the selected dataset and local hardware.
Technical Specifications¶
Model Architecture and Objective¶
LayoutGAN++ loads the released Const-layout generator checkpoints and predicts element boxes from label prompts. The runtime surface covers generator inference and processor decoding only; the original latent optimization loop, training pipeline, rendered image generation, and dataset preprocessing code are outside this wrapper.
Compute Infrastructure¶
Agreement-check commands are intended for one explicitly selected GPU when the original implementation requires CUDA.
Hardware¶
CPU is sufficient for import and most smoke tests. CUDA is required for heavyweight agreement checks when the original implementation requires it.
Software¶
Use uv run --package layoutganpp ... from the repository root so workspace dependency sources and extras resolve correctly.
License¶
Repository wrapper code is Apache-2.0. The original implementation is released under GNU AGPLv3. Converted checkpoints and package metadata keep agpl-3.0 model-card metadata.
Citation¶
@inproceedings{Kikuchi2021,
title = {Constrained Graphic Layout Generation via Latent Optimization},
author = {Kotaro Kikuchi and Edgar Simo-Serra and Mayu Otani and Kota Yamaguchi},
booktitle = {ACM International Conference on Multimedia},
series = {MM '21},
year = {2021},
pages = {88--96},
doi = {10.1145/3474085.3475497}
}
API Reference¶
Transformers-style LayoutGAN++ package exports.
LayoutGANPPConfig ¶
Bases: PretrainedConfig
Configuration for the LayoutGAN++ generator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_name
|
DatasetName | str
|
Dataset key or alias used to resolve labels and sequence length. |
rico13
|
latent_size
|
int
|
Size of each per-element latent vector. |
4
|
num_labels
|
int | None
|
Optional label vocabulary size override. |
None
|
id2label
|
Id2LabelMapping | None
|
Optional mapping from label IDs to display labels. |
None
|
label2id
|
dict[str, int] | None
|
Optional mapping from display labels to label IDs. |
None
|
d_model
|
int
|
Transformer hidden size used by the generator. |
512
|
nhead
|
int
|
Number of transformer attention heads. |
8
|
num_layers
|
int
|
Number of transformer encoder layers. |
4
|
bbox_format
|
BoxFormat | str
|
Bounding-box format produced by the model. |
xywh
|
bbox_normalized
|
bool
|
Whether generated boxes are normalized to the canvas. |
True
|
max_position_embeddings
|
int | None
|
Maximum element count for generated layouts. |
None
|
**kwargs
|
LayoutGANPPConfigValue
|
Extra |
{}
|
Examples:
>>> config = LayoutGANPPConfig(dataset_name="rico")
>>> config.model_type
'layoutganpp'
Source code in models/layoutganpp/src/layoutganpp/configuration_layoutganpp.py
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 | |
__init__ ¶
__init__(
dataset_name: DatasetName | str = DatasetName.rico13,
latent_size: int = 4,
num_labels: int | None = None,
id2label: Id2LabelMapping | None = None,
label2id: dict[str, int] | None = None,
d_model: int = 512,
nhead: int = 8,
num_layers: int = 4,
bbox_format: BoxFormat | str = BoxFormat.xywh,
bbox_normalized: bool = True,
max_position_embeddings: int | None = None,
**kwargs: LayoutGANPPConfigValue,
) -> None
Initialize a LayoutGAN++ config.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_name
|
DatasetName | str
|
Dataset key or alias used to resolve labels and metadata. |
rico13
|
latent_size
|
int
|
Size of each latent vector passed to the generator. |
4
|
num_labels
|
int | None
|
Optional explicit label vocabulary size. |
None
|
id2label
|
Id2LabelMapping | None
|
Optional label ID to text mapping. |
None
|
label2id
|
dict[str, int] | None
|
Optional label text to ID mapping. |
None
|
d_model
|
int
|
Transformer hidden size. |
512
|
nhead
|
int
|
Number of attention heads. |
8
|
num_layers
|
int
|
Number of transformer encoder layers. |
4
|
bbox_format
|
BoxFormat | str
|
Format of generated bounding boxes. |
xywh
|
bbox_normalized
|
bool
|
Whether generated boxes are normalized. |
True
|
max_position_embeddings
|
int | None
|
Optional maximum layout length override. |
None
|
**kwargs
|
LayoutGANPPConfigValue
|
Extra |
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
>>> LayoutGANPPConfig(dataset_name="publaynet").num_labels
5
Source code in models/layoutganpp/src/layoutganpp/configuration_layoutganpp.py
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 | |
LayoutGANPPModel ¶
Bases: PreTrainedModel
Transformers-compatible LayoutGAN++ generator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
LayoutGANPPConfig
|
LayoutGAN++ model configuration. |
required |
Examples:
>>> config = LayoutGANPPConfig(num_labels=2, id2label={0: "a", 1: "b"})
>>> model = LayoutGANPPModel(config)
>>> model.config.model_type
'layoutganpp'
Source code in models/layoutganpp/src/layoutganpp/modeling_layoutganpp.py
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 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 | |
__init__ ¶
__init__(config: LayoutGANPPConfig) -> None
Initialize the LayoutGAN++ generator layers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
LayoutGANPPConfig
|
LayoutGAN++ model configuration. |
required |
Examples:
>>> model = LayoutGANPPModel(LayoutGANPPConfig())
>>> model.base_model_prefix
'layoutganpp'
Source code in models/layoutganpp/src/layoutganpp/modeling_layoutganpp.py
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 | |
forward ¶
forward(
latents: Float[Tensor, "batch elements latent"],
labels: Int[Tensor, "batch elements"],
attention_mask: Bool[Tensor, "batch elements"]
| None = None,
padding_mask: Bool[Tensor, "batch elements"]
| None = None,
return_dict: bool = True,
) -> (
LayoutGANPPModelOutput
| tuple[
Float[torch.Tensor, "batch elements 4"],
Int[torch.Tensor, "batch elements"],
Bool[torch.Tensor, "batch elements"],
]
)
Run a forward pass from latents and label IDs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
latents
|
Float[Tensor, 'batch elements latent']
|
Per-element latent vectors shaped |
required |
labels
|
Int[Tensor, 'batch elements']
|
Label IDs shaped |
required |
attention_mask
|
Bool[Tensor, 'batch elements'] | None
|
Optional mask where true values mark valid labels. |
None
|
padding_mask
|
Bool[Tensor, 'batch elements'] | None
|
Optional mask where true values mark padded labels. |
None
|
return_dict
|
bool
|
Whether to return a |
True
|
Returns:
| Type | Description |
|---|---|
LayoutGANPPModelOutput | tuple[Float[Tensor, 'batch elements 4'], Int[Tensor, 'batch elements'], Bool[Tensor, 'batch elements']]
|
Model output dataclass or tuple containing boxes, labels, and mask. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If labels or latents have invalid shape or label IDs. |
Examples:
>>> model = LayoutGANPPModel(LayoutGANPPConfig(num_labels=2))
>>> labels = torch.tensor([[0, 1]])
>>> latents = torch.zeros(1, 2, model.config.latent_size)
>>> tuple(model(latents=latents, labels=labels).bbox.shape)
(1, 2, 4)
Source code in models/layoutganpp/src/layoutganpp/modeling_layoutganpp.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | |
generate ¶
generate(
*,
batch_size: int = 1,
condition_type: ConditionType
| str = ConditionType.label,
bbox: Float[Tensor, "batch elements 4"] | None = None,
labels: Int[Tensor, "batch elements"] | None = None,
mask: Bool[Tensor, "batch elements"] | None = None,
attention_mask: Bool[Tensor, "batch elements"]
| None = None,
num_elements: int
| list[int]
| Int[Tensor, "batch"]
| None = None,
box_format: BoxFormat | str = BoxFormat.xywh,
normalized: bool = True,
canvas_size: tuple[int, int] | None = None,
seed: int | None = None,
generator: Generator | None = None,
num_inference_steps: int | None = None,
output_type: OutputType | str = OutputType.dataclass,
return_intermediates: bool = False,
latents: Float[Tensor, "batch elements latent"]
| None = None,
) -> LayoutGenerationOutput | LayoutGANPPOutputDict
Generate layouts from label conditions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch_size
|
int
|
Requested batch size; label shape determines the final value. |
1
|
condition_type
|
ConditionType | str
|
Condition type or alias. LayoutGAN++ supports label conditions. |
label
|
bbox
|
Float[Tensor, 'batch elements 4'] | None
|
Reserved compatibility argument. |
None
|
labels
|
Int[Tensor, 'batch elements'] | None
|
Required label IDs for generation. |
None
|
mask
|
Bool[Tensor, 'batch elements'] | None
|
Optional valid-element mask. |
None
|
attention_mask
|
Bool[Tensor, 'batch elements'] | None
|
Optional valid-element mask. |
None
|
num_elements
|
int | list[int] | Int[Tensor, 'batch'] | None
|
Reserved compatibility argument. |
None
|
box_format
|
BoxFormat | str
|
Reserved compatibility argument. |
xywh
|
normalized
|
bool
|
Reserved compatibility argument. |
True
|
canvas_size
|
tuple[int, int] | None
|
Reserved compatibility argument. |
None
|
seed
|
int | None
|
Optional random seed for latent sampling. |
None
|
generator
|
Generator | None
|
Optional PyTorch random generator. |
None
|
num_inference_steps
|
int | None
|
Reserved compatibility argument. |
None
|
output_type
|
OutputType | str
|
Return format, either |
dataclass
|
return_intermediates
|
bool
|
Whether to include generation intermediates. |
False
|
latents
|
Float[Tensor, 'batch elements latent'] | None
|
Optional fixed latent vectors. |
None
|
Returns:
| Type | Description |
|---|---|
LayoutGenerationOutput | LayoutGANPPOutputDict
|
A layout generation dataclass or dictionary. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If labels are missing, generation options are unsupported, or output type is invalid. |
Examples:
>>> model = LayoutGANPPModel(LayoutGANPPConfig(num_labels=2))
>>> out = model.generate(labels=torch.tensor([[0, 1]]), seed=0)
>>> tuple(out.bbox.shape)
(1, 2, 4)
Source code in models/layoutganpp/src/layoutganpp/modeling_layoutganpp.py
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 | |
LayoutGANPPModelOutput
dataclass
¶
Bases: ModelOutput
Raw LayoutGAN++ model output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bbox
|
Float[Tensor, 'batch elements 4']
|
Generated normalized |
required |
labels
|
Int[Tensor, 'batch elements'] | None
|
Optional label IDs used for generation. |
None
|
mask
|
Bool[Tensor, 'batch elements'] | None
|
Optional valid-element mask. |
None
|
latents
|
Float[Tensor, 'batch elements latent'] | None
|
Optional latent vectors used by the generator. |
None
|
Examples:
>>> out = LayoutGANPPModelOutput(bbox=torch.zeros(1, 1, 4))
>>> tuple(out.bbox.shape)
(1, 1, 4)
Source code in models/layoutganpp/src/layoutganpp/modeling_layoutganpp.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | |
OutputType ¶
Bases: StrEnum
Supported LayoutGAN++ generation output formats.
Source code in models/layoutganpp/src/layoutganpp/modeling_layoutganpp.py
59 60 61 62 63 | |
LayoutGANPPPipeline ¶
Bases: LayoutGenerationPipeline
Transformers pipeline for LayoutGAN++ label-conditioned generation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
LayoutGANPPModel
|
LayoutGAN++ model instance. |
required |
processor
|
LayoutGANPPProcessor | None
|
Optional processor for label encoding and decoding. |
None
|
config
|
LayoutGANPPConfig | None
|
Optional root pipeline config. Defaults to |
None
|
device
|
int | device | None
|
Optional torch device passed to the base pipeline. |
None
|
binary_output
|
bool
|
Whether the base pipeline should produce binary output. |
False
|
Examples:
>>> model = LayoutGANPPModel(LayoutGANPPConfig(num_labels=2))
>>> pipe = LayoutGANPPPipeline(model=model)
>>> pipe.model.config.model_type
'layoutganpp'
Source code in models/layoutganpp/src/layoutganpp/pipeline_layoutganpp.py
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 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 | |
__init__ ¶
__init__(
model: LayoutGANPPModel,
processor: LayoutGANPPProcessor | None = None,
config: LayoutGANPPConfig | None = None,
device: int | device | None = None,
binary_output: bool = False,
) -> None
Initialize a LayoutGAN++ pipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
LayoutGANPPModel
|
LayoutGAN++ model instance. |
required |
processor
|
LayoutGANPPProcessor | None
|
Optional processor for label encoding and decoding. |
None
|
config
|
LayoutGANPPConfig | None
|
Optional root pipeline config. |
None
|
device
|
int | device | None
|
Optional torch device passed to the base pipeline. |
None
|
binary_output
|
bool
|
Whether the base pipeline should produce binary output. |
False
|
Examples:
>>> pipe = LayoutGANPPPipeline(LayoutGANPPModel(LayoutGANPPConfig()))
>>> isinstance(pipe.processor, LayoutGANPPProcessor)
True
Source code in models/layoutganpp/src/layoutganpp/pipeline_layoutganpp.py
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 148 149 150 | |
preprocess ¶
preprocess(
input_: list[list[str | int]]
| list[str | int]
| Int[Tensor, "batch elements"]
| None = None,
**preprocess_parameters: LayoutGANPPPipelineKwarg,
) -> BatchEncoding
Encode pipeline inputs into model inputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_
|
list[list[str | int]] | list[str | int] | Int[Tensor, 'batch elements'] | None
|
Labels supplied as the positional pipeline input. |
None
|
**preprocess_parameters
|
LayoutGANPPPipelineKwarg
|
Keyword labels and generation arguments. |
{}
|
Returns:
| Type | Description |
|---|---|
BatchEncoding
|
Batch encoding containing label IDs, attention mask, and generation kwargs. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If labels are not supplied or cannot be encoded. |
Examples:
>>> pipe = LayoutGANPPPipeline(LayoutGANPPModel(LayoutGANPPConfig()))
>>> "labels" in pipe.preprocess(["Toolbar"])
True
Source code in models/layoutganpp/src/layoutganpp/pipeline_layoutganpp.py
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | |
postprocess ¶
postprocess(
model_outputs: LayoutGenerationOutput
| LayoutGANPPOutputDict,
**kwargs: LayoutGANPPPipelineKwarg,
) -> LayoutGenerationOutput | LayoutGANPPOutputDict
Return generated layouts from the pipeline output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_outputs
|
LayoutGenerationOutput | LayoutGANPPOutputDict
|
Output produced by |
required |
**kwargs
|
LayoutGANPPPipelineKwarg
|
Reserved post-processing keyword arguments. |
{}
|
Returns:
| Type | Description |
|---|---|
LayoutGenerationOutput | LayoutGANPPOutputDict
|
The generated layout output unchanged. |
Examples:
>>> output = LayoutGenerationOutput(bbox=torch.zeros(1, 1, 4))
>>> pipe = LayoutGANPPPipeline(LayoutGANPPModel(LayoutGANPPConfig()))
>>> pipe.postprocess(output) is output
True
Source code in models/layoutganpp/src/layoutganpp/pipeline_layoutganpp.py
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 | |
__call__ ¶
__call__(
labels: list[list[str | int]]
| list[str | int]
| Int[Tensor, "batch elements"]
| None = None,
*,
batch_size: int = 1,
condition_type: ConditionType
| str = ConditionType.label,
bbox: Float[Tensor, "batch elements 4"] | None = None,
mask: Bool[Tensor, "batch elements"] | None = None,
attention_mask: Bool[Tensor, "batch elements"]
| None = None,
num_elements: int
| list[int]
| Int[Tensor, "batch"]
| None = None,
box_format: BoxFormat | str = BoxFormat.xywh,
normalized: bool = True,
canvas_size: tuple[int, int] | None = None,
seed: int | None = None,
generator: Generator | None = None,
num_inference_steps: int | None = None,
output_type: OutputType | str = OutputType.dataclass,
return_intermediates: bool = False,
latents: Float[Tensor, "batch elements latent"]
| None = None,
) -> LayoutGenerationOutput | LayoutGANPPOutputDict
Generate LayoutGAN++ boxes from labels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
labels
|
list[list[str | int]] | list[str | int] | Int[Tensor, 'batch elements'] | None
|
Label strings or label IDs to condition on. |
None
|
batch_size
|
int
|
Reserved compatibility argument. |
1
|
condition_type
|
ConditionType | str
|
Condition type or alias. |
label
|
bbox
|
Float[Tensor, 'batch elements 4'] | None
|
Reserved compatibility argument. |
None
|
mask
|
Bool[Tensor, 'batch elements'] | None
|
Optional valid-element mask. |
None
|
attention_mask
|
Bool[Tensor, 'batch elements'] | None
|
Optional valid-element mask. |
None
|
num_elements
|
int | list[int] | Int[Tensor, 'batch'] | None
|
Reserved compatibility argument. |
None
|
box_format
|
BoxFormat | str
|
Reserved compatibility argument. |
xywh
|
normalized
|
bool
|
Reserved compatibility argument. |
True
|
canvas_size
|
tuple[int, int] | None
|
Reserved compatibility argument. |
None
|
seed
|
int | None
|
Optional random seed for latent sampling. |
None
|
generator
|
Generator | None
|
Optional PyTorch random generator. |
None
|
num_inference_steps
|
int | None
|
Reserved compatibility argument. |
None
|
output_type
|
OutputType | str
|
Return format, either |
dataclass
|
return_intermediates
|
bool
|
Whether to include generation intermediates. |
False
|
latents
|
Float[Tensor, 'batch elements latent'] | None
|
Optional fixed latent vectors. |
None
|
Returns:
| Type | Description |
|---|---|
LayoutGenerationOutput | LayoutGANPPOutputDict
|
A layout generation dataclass or dictionary. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If labels are missing or generation options are invalid. |
Examples:
>>> pipe = LayoutGANPPPipeline(LayoutGANPPModel(LayoutGANPPConfig()))
>>> out = pipe(labels=["Toolbar"], seed=0)
>>> tuple(out.bbox.shape)
(1, 1, 4)
Source code in models/layoutganpp/src/layoutganpp/pipeline_layoutganpp.py
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 | |
LayoutGANPPProcessor ¶
Bases: ProcessorMixin
Encode LayoutGAN++ labels and decode generated layouts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_name
|
DatasetName | str
|
Dataset key or alias. |
rico13
|
id2label
|
Id2LabelMapping | None
|
Optional label ID to text mapping. |
None
|
Examples:
>>> processor = LayoutGANPPProcessor(dataset_name="rico")
>>> processor.label2id["Toolbar"]
0
Source code in models/layoutganpp/src/layoutganpp/processing_layoutganpp.py
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 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 | |
__init__ ¶
__init__(
dataset_name: DatasetName | str = DatasetName.rico13,
id2label: Id2LabelMapping | None = None,
) -> None
Initialize a LayoutGAN++ processor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_name
|
DatasetName | str
|
Dataset key or alias. |
rico13
|
id2label
|
Id2LabelMapping | None
|
Optional label ID to text mapping. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the dataset name is unsupported. |
Examples:
>>> LayoutGANPPProcessor("publaynet").id2label[0]
'text'
Source code in models/layoutganpp/src/layoutganpp/processing_layoutganpp.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |
__call__ ¶
__call__(
labels: list[list[str | int]]
| list[str | int]
| Int[Tensor, "batch elements"],
*,
padding: bool = True,
return_tensors: Literal["pt"] = "pt",
) -> BatchEncoding
Encode label strings or IDs into tensors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
labels
|
list[list[str | int]] | list[str | int] | Int[Tensor, 'batch elements']
|
Label strings, label IDs, or a tensor of label IDs. |
required |
padding
|
bool
|
Whether to pad ragged batches. |
True
|
return_tensors
|
Literal['pt']
|
Tensor framework. Only |
'pt'
|
Returns:
| Type | Description |
|---|---|
BatchEncoding
|
Batch encoding with |
Raises:
| Type | Description |
|---|---|
ValueError
|
If labels are empty, ragged without padding, unknown,
or |
Examples:
>>> processor = LayoutGANPPProcessor()
>>> encoded = processor(["Toolbar", "Image"])
>>> tuple(encoded["labels"].shape)
(1, 2)
Source code in models/layoutganpp/src/layoutganpp/processing_layoutganpp.py
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 | |
batch_decode ¶
batch_decode(
bbox: Float[Tensor, "batch elements 4"],
labels: Int[Tensor, "batch elements"],
attention_mask: Bool[Tensor, "batch elements"]
| None = None,
) -> list[list[DecodedLayoutGANPPRecord]]
Decode generated boxes and label IDs into records.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bbox
|
Float[Tensor, 'batch elements 4']
|
Generated boxes shaped |
required |
labels
|
Int[Tensor, 'batch elements']
|
Label IDs shaped |
required |
attention_mask
|
Bool[Tensor, 'batch elements'] | None
|
Optional valid-element mask. |
None
|
Returns:
| Type | Description |
|---|---|
list[list[DecodedLayoutGANPPRecord]]
|
Nested records containing label text, label ID, and bounding box. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If a label ID is not known to this processor. |
Examples:
>>> processor = LayoutGANPPProcessor()
>>> records = processor.batch_decode(
... torch.zeros(1, 1, 4), torch.tensor([[0]])
... )
>>> records[0][0]["label"]
'Toolbar'
Source code in models/layoutganpp/src/layoutganpp/processing_layoutganpp.py
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 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | |
label2id_for_dataset ¶
label2id_for_dataset(
dataset_name: DatasetName | str,
) -> dict[str, int]
Return a label-to-ID mapping for a dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_name
|
DatasetName | str
|
Dataset key or alias. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, int]
|
Dictionary mapping label names to integer IDs. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the dataset name is unknown. |
Examples:
>>> label2id_for_dataset("rico")["Toolbar"]
0
Source code in models/layoutganpp/src/layoutganpp/datasets.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | |
labels_for_dataset ¶
labels_for_dataset(
dataset_name: DatasetName | str,
) -> tuple[StrEnum, ...]
Return labels for a LayoutGAN++ dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_name
|
DatasetName | str
|
Dataset key or alias. |
required |
Returns:
| Type | Description |
|---|---|
tuple[StrEnum, ...]
|
Label names in checkpoint order. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the dataset name is unknown. |
Examples:
>>> labels_for_dataset("publaynet")[0]
'text'
Source code in models/layoutganpp/src/layoutganpp/datasets.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
normalize_output_type ¶
normalize_output_type(
output_type: OutputType | str,
) -> OutputType
Normalize a public output type value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_type
|
OutputType | str
|
Output type enum or string. |
required |
Returns:
| Type | Description |
|---|---|
OutputType
|
Normalized output type enum. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
>>> str(normalize_output_type("dict"))
'dict'
Source code in models/layoutganpp/src/layoutganpp/modeling_layoutganpp.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | |
layoutganpp_model_card ¶
layoutganpp_model_card(
dataset: DatasetName | str,
) -> ModelCard
Build a Hugging Face model card for a LayoutGAN++ dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
DatasetName | str
|
Dataset key or alias for the converted checkpoint. |
required |
Returns:
| Type | Description |
|---|---|
ModelCard
|
A populated |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
>>> card = layoutganpp_model_card("rico")
>>> "layoutganpp-rico" in str(card)
True
Source code in models/layoutganpp/src/layoutganpp/model_card.py
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 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | |
write_layoutganpp_model_card ¶
write_layoutganpp_model_card(
output_dir: Path, dataset: DatasetName | str
) -> Path
Write a LayoutGAN++ model card to an output directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_dir
|
Path
|
Directory that will receive |
required |
dataset
|
DatasetName | str
|
Dataset key or alias for the converted checkpoint. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
Path to the written |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
>>> from tempfile import TemporaryDirectory
>>> with TemporaryDirectory() as tmp:
... path = write_layoutganpp_model_card(Path(tmp), "rico")
... path.name
'README.md'
Source code in models/layoutganpp/src/layoutganpp/model_card.py
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
bbox ¶
Bounding-box helpers re-exported for LayoutGAN++ users.
configuration_layoutganpp ¶
Configuration objects for LayoutGAN++ checkpoints.
LayoutGANPPConfig ¶
Bases: PretrainedConfig
Configuration for the LayoutGAN++ generator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_name
|
DatasetName | str
|
Dataset key or alias used to resolve labels and sequence length. |
rico13
|
latent_size
|
int
|
Size of each per-element latent vector. |
4
|
num_labels
|
int | None
|
Optional label vocabulary size override. |
None
|
id2label
|
Id2LabelMapping | None
|
Optional mapping from label IDs to display labels. |
None
|
label2id
|
dict[str, int] | None
|
Optional mapping from display labels to label IDs. |
None
|
d_model
|
int
|
Transformer hidden size used by the generator. |
512
|
nhead
|
int
|
Number of transformer attention heads. |
8
|
num_layers
|
int
|
Number of transformer encoder layers. |
4
|
bbox_format
|
BoxFormat | str
|
Bounding-box format produced by the model. |
xywh
|
bbox_normalized
|
bool
|
Whether generated boxes are normalized to the canvas. |
True
|
max_position_embeddings
|
int | None
|
Maximum element count for generated layouts. |
None
|
**kwargs
|
LayoutGANPPConfigValue
|
Extra |
{}
|
Examples:
>>> config = LayoutGANPPConfig(dataset_name="rico")
>>> config.model_type
'layoutganpp'
Source code in models/layoutganpp/src/layoutganpp/configuration_layoutganpp.py
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 | |
__init__ ¶
__init__(
dataset_name: DatasetName | str = DatasetName.rico13,
latent_size: int = 4,
num_labels: int | None = None,
id2label: Id2LabelMapping | None = None,
label2id: dict[str, int] | None = None,
d_model: int = 512,
nhead: int = 8,
num_layers: int = 4,
bbox_format: BoxFormat | str = BoxFormat.xywh,
bbox_normalized: bool = True,
max_position_embeddings: int | None = None,
**kwargs: LayoutGANPPConfigValue,
) -> None
Initialize a LayoutGAN++ config.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_name
|
DatasetName | str
|
Dataset key or alias used to resolve labels and metadata. |
rico13
|
latent_size
|
int
|
Size of each latent vector passed to the generator. |
4
|
num_labels
|
int | None
|
Optional explicit label vocabulary size. |
None
|
id2label
|
Id2LabelMapping | None
|
Optional label ID to text mapping. |
None
|
label2id
|
dict[str, int] | None
|
Optional label text to ID mapping. |
None
|
d_model
|
int
|
Transformer hidden size. |
512
|
nhead
|
int
|
Number of attention heads. |
8
|
num_layers
|
int
|
Number of transformer encoder layers. |
4
|
bbox_format
|
BoxFormat | str
|
Format of generated bounding boxes. |
xywh
|
bbox_normalized
|
bool
|
Whether generated boxes are normalized. |
True
|
max_position_embeddings
|
int | None
|
Optional maximum layout length override. |
None
|
**kwargs
|
LayoutGANPPConfigValue
|
Extra |
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
>>> LayoutGANPPConfig(dataset_name="publaynet").num_labels
5
Source code in models/layoutganpp/src/layoutganpp/configuration_layoutganpp.py
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 | |
conversion ¶
Conversion helpers for original LayoutGAN++ checkpoint metadata.
config_from_checkpoint_args ¶
config_from_checkpoint_args(
args: CheckpointArgs,
) -> LayoutGANPPConfig
Build a config from original LayoutGAN++ checkpoint arguments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
CheckpointArgs
|
Mapping or argparse-style namespace with upstream checkpoint fields. |
required |
Returns:
| Type | Description |
|---|---|
LayoutGANPPConfig
|
A |
Raises:
| Type | Description |
|---|---|
KeyError
|
If a required upstream field is missing. |
ValueError
|
If the dataset name is unsupported. |
Examples:
>>> config_from_checkpoint_args(
... {
... "dataset": "rico",
... "latent_size": 4,
... "G_d_model": 512,
... "G_nhead": 8,
... "G_num_layers": 4,
... }
... ).dataset_name
'rico'
Source code in models/layoutganpp/src/layoutganpp/conversion.py
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 | |
datasets ¶
Dataset metadata and label helpers for LayoutGAN++ checkpoints.
RicoLabel ¶
Bases: StrEnum
RICO label names in LayoutGAN++ checkpoint order.
Source code in models/layoutganpp/src/layoutganpp/datasets.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | |
DatasetAlias ¶
Bases: StrEnum
LayoutGAN++ dataset aliases accepted at public boundaries.
Source code in models/layoutganpp/src/layoutganpp/datasets.py
29 30 31 32 33 34 35 36 | |
DatasetMetadata ¶
Bases: TypedDict
Metadata for a LayoutGAN++ checkpoint dataset.
Source code in models/layoutganpp/src/layoutganpp/datasets.py
44 45 46 47 48 | |
normalize_dataset_name ¶
normalize_dataset_name(
dataset_name: DatasetName | str,
) -> DatasetName
Normalize a LayoutGAN++ dataset name or alias.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_name
|
DatasetName | str
|
Dataset key such as |
required |
Returns:
| Type | Description |
|---|---|
DatasetName
|
The canonical dataset key. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the dataset name is unknown. |
Examples:
>>> str(normalize_dataset_name("pub-laynet"))
'publaynet'
Source code in models/layoutganpp/src/layoutganpp/datasets.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | |
dataset_metadata ¶
dataset_metadata(
dataset_name: DatasetName | str,
) -> DatasetMetadata
Return metadata for a LayoutGAN++ dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_name
|
DatasetName | str
|
Dataset key or alias. |
required |
Returns:
| Type | Description |
|---|---|
DatasetMetadata
|
Metadata containing the canonical name, labels, and maximum element count. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the dataset name is unknown. |
Examples:
>>> max_elements_for_dataset("rico13")
9
Source code in models/layoutganpp/src/layoutganpp/datasets.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | |
labels_for_dataset ¶
labels_for_dataset(
dataset_name: DatasetName | str,
) -> tuple[StrEnum, ...]
Return labels for a LayoutGAN++ dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_name
|
DatasetName | str
|
Dataset key or alias. |
required |
Returns:
| Type | Description |
|---|---|
tuple[StrEnum, ...]
|
Label names in checkpoint order. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the dataset name is unknown. |
Examples:
>>> labels_for_dataset("publaynet")[0]
'text'
Source code in models/layoutganpp/src/layoutganpp/datasets.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
id2label_for_dataset ¶
id2label_for_dataset(
dataset_name: DatasetName | str,
) -> dict[int, str]
Return an ID-to-label mapping for a dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_name
|
DatasetName | str
|
Dataset key or alias. |
required |
Returns:
| Type | Description |
|---|---|
dict[int, str]
|
Dictionary mapping integer IDs to label names. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the dataset name is unknown. |
Examples:
>>> id2label_for_dataset("magazine")[1]
'image'
Source code in models/layoutganpp/src/layoutganpp/datasets.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | |
label2id_for_dataset ¶
label2id_for_dataset(
dataset_name: DatasetName | str,
) -> dict[str, int]
Return a label-to-ID mapping for a dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_name
|
DatasetName | str
|
Dataset key or alias. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, int]
|
Dictionary mapping label names to integer IDs. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the dataset name is unknown. |
Examples:
>>> label2id_for_dataset("rico")["Toolbar"]
0
Source code in models/layoutganpp/src/layoutganpp/datasets.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | |
evaluation ¶
Evaluation helpers for normalized LayoutGAN++ outputs.
out_of_bounds_counts ¶
out_of_bounds_counts(
values: list[
tuple[
Float[ndarray, "elements 4"],
Int[ndarray, "elements"],
]
],
) -> dict[str, int]
Count boxes and layouts outside the normalized xywh frame.
Source code in models/layoutganpp/src/layoutganpp/evaluation.py
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 | |
model_card ¶
Model card builders for LayoutGAN++ checkpoint packages.
CheckpointKey ¶
Bases: StrEnum
Dataset suffixes used in LayoutGAN++ checkpoint and Hub IDs.
Source code in models/layoutganpp/src/layoutganpp/model_card.py
15 16 17 18 19 20 | |
ParityMetricKey ¶
Bases: StrEnum
Internal parity metric keys used in LayoutGAN++ model-card text.
Source code in models/layoutganpp/src/layoutganpp/model_card.py
23 24 25 26 27 | |
ParityMetricText ¶
Bases: TypedDict
Model-card parity text snippets for a converted checkpoint.
Source code in models/layoutganpp/src/layoutganpp/model_card.py
30 31 32 33 34 | |
layoutganpp_model_card ¶
layoutganpp_model_card(
dataset: DatasetName | str,
) -> ModelCard
Build a Hugging Face model card for a LayoutGAN++ dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
DatasetName | str
|
Dataset key or alias for the converted checkpoint. |
required |
Returns:
| Type | Description |
|---|---|
ModelCard
|
A populated |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
>>> card = layoutganpp_model_card("rico")
>>> "layoutganpp-rico" in str(card)
True
Source code in models/layoutganpp/src/layoutganpp/model_card.py
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 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | |
write_layoutganpp_model_card ¶
write_layoutganpp_model_card(
output_dir: Path, dataset: DatasetName | str
) -> Path
Write a LayoutGAN++ model card to an output directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_dir
|
Path
|
Directory that will receive |
required |
dataset
|
DatasetName | str
|
Dataset key or alias for the converted checkpoint. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
Path to the written |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
>>> from tempfile import TemporaryDirectory
>>> with TemporaryDirectory() as tmp:
... path = write_layoutganpp_model_card(Path(tmp), "rico")
... path.name
'README.md'
Source code in models/layoutganpp/src/layoutganpp/model_card.py
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
modeling_layoutganpp ¶
PyTorch model wrapper for the LayoutGAN++ generator.
LayoutGANPPModelOutput
dataclass
¶
Bases: ModelOutput
Raw LayoutGAN++ model output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bbox
|
Float[Tensor, 'batch elements 4']
|
Generated normalized |
required |
labels
|
Int[Tensor, 'batch elements'] | None
|
Optional label IDs used for generation. |
None
|
mask
|
Bool[Tensor, 'batch elements'] | None
|
Optional valid-element mask. |
None
|
latents
|
Float[Tensor, 'batch elements latent'] | None
|
Optional latent vectors used by the generator. |
None
|
Examples:
>>> out = LayoutGANPPModelOutput(bbox=torch.zeros(1, 1, 4))
>>> tuple(out.bbox.shape)
(1, 1, 4)
Source code in models/layoutganpp/src/layoutganpp/modeling_layoutganpp.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | |
LayoutGANPPOutputDict ¶
Bases: TypedDict
Dictionary form of LayoutGAN++ public output.
Source code in models/layoutganpp/src/layoutganpp/modeling_layoutganpp.py
46 47 48 49 50 51 52 53 54 55 56 | |
OutputType ¶
Bases: StrEnum
Supported LayoutGAN++ generation output formats.
Source code in models/layoutganpp/src/layoutganpp/modeling_layoutganpp.py
59 60 61 62 63 | |
LayoutGANPPModel ¶
Bases: PreTrainedModel
Transformers-compatible LayoutGAN++ generator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
LayoutGANPPConfig
|
LayoutGAN++ model configuration. |
required |
Examples:
>>> config = LayoutGANPPConfig(num_labels=2, id2label={0: "a", 1: "b"})
>>> model = LayoutGANPPModel(config)
>>> model.config.model_type
'layoutganpp'
Source code in models/layoutganpp/src/layoutganpp/modeling_layoutganpp.py
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 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 | |
__init__ ¶
__init__(config: LayoutGANPPConfig) -> None
Initialize the LayoutGAN++ generator layers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
LayoutGANPPConfig
|
LayoutGAN++ model configuration. |
required |
Examples:
>>> model = LayoutGANPPModel(LayoutGANPPConfig())
>>> model.base_model_prefix
'layoutganpp'
Source code in models/layoutganpp/src/layoutganpp/modeling_layoutganpp.py
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 | |
forward ¶
forward(
latents: Float[Tensor, "batch elements latent"],
labels: Int[Tensor, "batch elements"],
attention_mask: Bool[Tensor, "batch elements"]
| None = None,
padding_mask: Bool[Tensor, "batch elements"]
| None = None,
return_dict: bool = True,
) -> (
LayoutGANPPModelOutput
| tuple[
Float[torch.Tensor, "batch elements 4"],
Int[torch.Tensor, "batch elements"],
Bool[torch.Tensor, "batch elements"],
]
)
Run a forward pass from latents and label IDs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
latents
|
Float[Tensor, 'batch elements latent']
|
Per-element latent vectors shaped |
required |
labels
|
Int[Tensor, 'batch elements']
|
Label IDs shaped |
required |
attention_mask
|
Bool[Tensor, 'batch elements'] | None
|
Optional mask where true values mark valid labels. |
None
|
padding_mask
|
Bool[Tensor, 'batch elements'] | None
|
Optional mask where true values mark padded labels. |
None
|
return_dict
|
bool
|
Whether to return a |
True
|
Returns:
| Type | Description |
|---|---|
LayoutGANPPModelOutput | tuple[Float[Tensor, 'batch elements 4'], Int[Tensor, 'batch elements'], Bool[Tensor, 'batch elements']]
|
Model output dataclass or tuple containing boxes, labels, and mask. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If labels or latents have invalid shape or label IDs. |
Examples:
>>> model = LayoutGANPPModel(LayoutGANPPConfig(num_labels=2))
>>> labels = torch.tensor([[0, 1]])
>>> latents = torch.zeros(1, 2, model.config.latent_size)
>>> tuple(model(latents=latents, labels=labels).bbox.shape)
(1, 2, 4)
Source code in models/layoutganpp/src/layoutganpp/modeling_layoutganpp.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | |
generate ¶
generate(
*,
batch_size: int = 1,
condition_type: ConditionType
| str = ConditionType.label,
bbox: Float[Tensor, "batch elements 4"] | None = None,
labels: Int[Tensor, "batch elements"] | None = None,
mask: Bool[Tensor, "batch elements"] | None = None,
attention_mask: Bool[Tensor, "batch elements"]
| None = None,
num_elements: int
| list[int]
| Int[Tensor, "batch"]
| None = None,
box_format: BoxFormat | str = BoxFormat.xywh,
normalized: bool = True,
canvas_size: tuple[int, int] | None = None,
seed: int | None = None,
generator: Generator | None = None,
num_inference_steps: int | None = None,
output_type: OutputType | str = OutputType.dataclass,
return_intermediates: bool = False,
latents: Float[Tensor, "batch elements latent"]
| None = None,
) -> LayoutGenerationOutput | LayoutGANPPOutputDict
Generate layouts from label conditions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch_size
|
int
|
Requested batch size; label shape determines the final value. |
1
|
condition_type
|
ConditionType | str
|
Condition type or alias. LayoutGAN++ supports label conditions. |
label
|
bbox
|
Float[Tensor, 'batch elements 4'] | None
|
Reserved compatibility argument. |
None
|
labels
|
Int[Tensor, 'batch elements'] | None
|
Required label IDs for generation. |
None
|
mask
|
Bool[Tensor, 'batch elements'] | None
|
Optional valid-element mask. |
None
|
attention_mask
|
Bool[Tensor, 'batch elements'] | None
|
Optional valid-element mask. |
None
|
num_elements
|
int | list[int] | Int[Tensor, 'batch'] | None
|
Reserved compatibility argument. |
None
|
box_format
|
BoxFormat | str
|
Reserved compatibility argument. |
xywh
|
normalized
|
bool
|
Reserved compatibility argument. |
True
|
canvas_size
|
tuple[int, int] | None
|
Reserved compatibility argument. |
None
|
seed
|
int | None
|
Optional random seed for latent sampling. |
None
|
generator
|
Generator | None
|
Optional PyTorch random generator. |
None
|
num_inference_steps
|
int | None
|
Reserved compatibility argument. |
None
|
output_type
|
OutputType | str
|
Return format, either |
dataclass
|
return_intermediates
|
bool
|
Whether to include generation intermediates. |
False
|
latents
|
Float[Tensor, 'batch elements latent'] | None
|
Optional fixed latent vectors. |
None
|
Returns:
| Type | Description |
|---|---|
LayoutGenerationOutput | LayoutGANPPOutputDict
|
A layout generation dataclass or dictionary. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If labels are missing, generation options are unsupported, or output type is invalid. |
Examples:
>>> model = LayoutGANPPModel(LayoutGANPPConfig(num_labels=2))
>>> out = model.generate(labels=torch.tensor([[0, 1]]), seed=0)
>>> tuple(out.bbox.shape)
(1, 2, 4)
Source code in models/layoutganpp/src/layoutganpp/modeling_layoutganpp.py
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 | |
normalize_output_type ¶
normalize_output_type(
output_type: OutputType | str,
) -> OutputType
Normalize a public output type value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_type
|
OutputType | str
|
Output type enum or string. |
required |
Returns:
| Type | Description |
|---|---|
OutputType
|
Normalized output type enum. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
>>> str(normalize_output_type("dict"))
'dict'
Source code in models/layoutganpp/src/layoutganpp/modeling_layoutganpp.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | |
pipeline_layoutganpp ¶
Pipeline interface for LayoutGAN++ layout generation.
LayoutGANPPPipeline ¶
Bases: LayoutGenerationPipeline
Transformers pipeline for LayoutGAN++ label-conditioned generation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
LayoutGANPPModel
|
LayoutGAN++ model instance. |
required |
processor
|
LayoutGANPPProcessor | None
|
Optional processor for label encoding and decoding. |
None
|
config
|
LayoutGANPPConfig | None
|
Optional root pipeline config. Defaults to |
None
|
device
|
int | device | None
|
Optional torch device passed to the base pipeline. |
None
|
binary_output
|
bool
|
Whether the base pipeline should produce binary output. |
False
|
Examples:
>>> model = LayoutGANPPModel(LayoutGANPPConfig(num_labels=2))
>>> pipe = LayoutGANPPPipeline(model=model)
>>> pipe.model.config.model_type
'layoutganpp'
Source code in models/layoutganpp/src/layoutganpp/pipeline_layoutganpp.py
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 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 | |
__init__ ¶
__init__(
model: LayoutGANPPModel,
processor: LayoutGANPPProcessor | None = None,
config: LayoutGANPPConfig | None = None,
device: int | device | None = None,
binary_output: bool = False,
) -> None
Initialize a LayoutGAN++ pipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
LayoutGANPPModel
|
LayoutGAN++ model instance. |
required |
processor
|
LayoutGANPPProcessor | None
|
Optional processor for label encoding and decoding. |
None
|
config
|
LayoutGANPPConfig | None
|
Optional root pipeline config. |
None
|
device
|
int | device | None
|
Optional torch device passed to the base pipeline. |
None
|
binary_output
|
bool
|
Whether the base pipeline should produce binary output. |
False
|
Examples:
>>> pipe = LayoutGANPPPipeline(LayoutGANPPModel(LayoutGANPPConfig()))
>>> isinstance(pipe.processor, LayoutGANPPProcessor)
True
Source code in models/layoutganpp/src/layoutganpp/pipeline_layoutganpp.py
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 148 149 150 | |
preprocess ¶
preprocess(
input_: list[list[str | int]]
| list[str | int]
| Int[Tensor, "batch elements"]
| None = None,
**preprocess_parameters: LayoutGANPPPipelineKwarg,
) -> BatchEncoding
Encode pipeline inputs into model inputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_
|
list[list[str | int]] | list[str | int] | Int[Tensor, 'batch elements'] | None
|
Labels supplied as the positional pipeline input. |
None
|
**preprocess_parameters
|
LayoutGANPPPipelineKwarg
|
Keyword labels and generation arguments. |
{}
|
Returns:
| Type | Description |
|---|---|
BatchEncoding
|
Batch encoding containing label IDs, attention mask, and generation kwargs. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If labels are not supplied or cannot be encoded. |
Examples:
>>> pipe = LayoutGANPPPipeline(LayoutGANPPModel(LayoutGANPPConfig()))
>>> "labels" in pipe.preprocess(["Toolbar"])
True
Source code in models/layoutganpp/src/layoutganpp/pipeline_layoutganpp.py
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | |
postprocess ¶
postprocess(
model_outputs: LayoutGenerationOutput
| LayoutGANPPOutputDict,
**kwargs: LayoutGANPPPipelineKwarg,
) -> LayoutGenerationOutput | LayoutGANPPOutputDict
Return generated layouts from the pipeline output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_outputs
|
LayoutGenerationOutput | LayoutGANPPOutputDict
|
Output produced by |
required |
**kwargs
|
LayoutGANPPPipelineKwarg
|
Reserved post-processing keyword arguments. |
{}
|
Returns:
| Type | Description |
|---|---|
LayoutGenerationOutput | LayoutGANPPOutputDict
|
The generated layout output unchanged. |
Examples:
>>> output = LayoutGenerationOutput(bbox=torch.zeros(1, 1, 4))
>>> pipe = LayoutGANPPPipeline(LayoutGANPPModel(LayoutGANPPConfig()))
>>> pipe.postprocess(output) is output
True
Source code in models/layoutganpp/src/layoutganpp/pipeline_layoutganpp.py
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 | |
__call__ ¶
__call__(
labels: list[list[str | int]]
| list[str | int]
| Int[Tensor, "batch elements"]
| None = None,
*,
batch_size: int = 1,
condition_type: ConditionType
| str = ConditionType.label,
bbox: Float[Tensor, "batch elements 4"] | None = None,
mask: Bool[Tensor, "batch elements"] | None = None,
attention_mask: Bool[Tensor, "batch elements"]
| None = None,
num_elements: int
| list[int]
| Int[Tensor, "batch"]
| None = None,
box_format: BoxFormat | str = BoxFormat.xywh,
normalized: bool = True,
canvas_size: tuple[int, int] | None = None,
seed: int | None = None,
generator: Generator | None = None,
num_inference_steps: int | None = None,
output_type: OutputType | str = OutputType.dataclass,
return_intermediates: bool = False,
latents: Float[Tensor, "batch elements latent"]
| None = None,
) -> LayoutGenerationOutput | LayoutGANPPOutputDict
Generate LayoutGAN++ boxes from labels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
labels
|
list[list[str | int]] | list[str | int] | Int[Tensor, 'batch elements'] | None
|
Label strings or label IDs to condition on. |
None
|
batch_size
|
int
|
Reserved compatibility argument. |
1
|
condition_type
|
ConditionType | str
|
Condition type or alias. |
label
|
bbox
|
Float[Tensor, 'batch elements 4'] | None
|
Reserved compatibility argument. |
None
|
mask
|
Bool[Tensor, 'batch elements'] | None
|
Optional valid-element mask. |
None
|
attention_mask
|
Bool[Tensor, 'batch elements'] | None
|
Optional valid-element mask. |
None
|
num_elements
|
int | list[int] | Int[Tensor, 'batch'] | None
|
Reserved compatibility argument. |
None
|
box_format
|
BoxFormat | str
|
Reserved compatibility argument. |
xywh
|
normalized
|
bool
|
Reserved compatibility argument. |
True
|
canvas_size
|
tuple[int, int] | None
|
Reserved compatibility argument. |
None
|
seed
|
int | None
|
Optional random seed for latent sampling. |
None
|
generator
|
Generator | None
|
Optional PyTorch random generator. |
None
|
num_inference_steps
|
int | None
|
Reserved compatibility argument. |
None
|
output_type
|
OutputType | str
|
Return format, either |
dataclass
|
return_intermediates
|
bool
|
Whether to include generation intermediates. |
False
|
latents
|
Float[Tensor, 'batch elements latent'] | None
|
Optional fixed latent vectors. |
None
|
Returns:
| Type | Description |
|---|---|
LayoutGenerationOutput | LayoutGANPPOutputDict
|
A layout generation dataclass or dictionary. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If labels are missing or generation options are invalid. |
Examples:
>>> pipe = LayoutGANPPPipeline(LayoutGANPPModel(LayoutGANPPConfig()))
>>> out = pipe(labels=["Toolbar"], seed=0)
>>> tuple(out.bbox.shape)
(1, 1, 4)
Source code in models/layoutganpp/src/layoutganpp/pipeline_layoutganpp.py
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 | |
processing_layoutganpp ¶
Processor for LayoutGAN++ label encoding and output decoding.
DecodedLayoutGANPPRecord ¶
Bases: TypedDict
One decoded LayoutGAN++ layout element.
Source code in models/layoutganpp/src/layoutganpp/processing_layoutganpp.py
16 17 18 19 20 21 | |
LayoutGANPPProcessor ¶
Bases: ProcessorMixin
Encode LayoutGAN++ labels and decode generated layouts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_name
|
DatasetName | str
|
Dataset key or alias. |
rico13
|
id2label
|
Id2LabelMapping | None
|
Optional label ID to text mapping. |
None
|
Examples:
>>> processor = LayoutGANPPProcessor(dataset_name="rico")
>>> processor.label2id["Toolbar"]
0
Source code in models/layoutganpp/src/layoutganpp/processing_layoutganpp.py
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 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 | |
__init__ ¶
__init__(
dataset_name: DatasetName | str = DatasetName.rico13,
id2label: Id2LabelMapping | None = None,
) -> None
Initialize a LayoutGAN++ processor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_name
|
DatasetName | str
|
Dataset key or alias. |
rico13
|
id2label
|
Id2LabelMapping | None
|
Optional label ID to text mapping. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the dataset name is unsupported. |
Examples:
>>> LayoutGANPPProcessor("publaynet").id2label[0]
'text'
Source code in models/layoutganpp/src/layoutganpp/processing_layoutganpp.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |
__call__ ¶
__call__(
labels: list[list[str | int]]
| list[str | int]
| Int[Tensor, "batch elements"],
*,
padding: bool = True,
return_tensors: Literal["pt"] = "pt",
) -> BatchEncoding
Encode label strings or IDs into tensors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
labels
|
list[list[str | int]] | list[str | int] | Int[Tensor, 'batch elements']
|
Label strings, label IDs, or a tensor of label IDs. |
required |
padding
|
bool
|
Whether to pad ragged batches. |
True
|
return_tensors
|
Literal['pt']
|
Tensor framework. Only |
'pt'
|
Returns:
| Type | Description |
|---|---|
BatchEncoding
|
Batch encoding with |
Raises:
| Type | Description |
|---|---|
ValueError
|
If labels are empty, ragged without padding, unknown,
or |
Examples:
>>> processor = LayoutGANPPProcessor()
>>> encoded = processor(["Toolbar", "Image"])
>>> tuple(encoded["labels"].shape)
(1, 2)
Source code in models/layoutganpp/src/layoutganpp/processing_layoutganpp.py
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 | |
batch_decode ¶
batch_decode(
bbox: Float[Tensor, "batch elements 4"],
labels: Int[Tensor, "batch elements"],
attention_mask: Bool[Tensor, "batch elements"]
| None = None,
) -> list[list[DecodedLayoutGANPPRecord]]
Decode generated boxes and label IDs into records.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bbox
|
Float[Tensor, 'batch elements 4']
|
Generated boxes shaped |
required |
labels
|
Int[Tensor, 'batch elements']
|
Label IDs shaped |
required |
attention_mask
|
Bool[Tensor, 'batch elements'] | None
|
Optional valid-element mask. |
None
|
Returns:
| Type | Description |
|---|---|
list[list[DecodedLayoutGANPPRecord]]
|
Nested records containing label text, label ID, and bounding box. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If a label ID is not known to this processor. |
Examples:
>>> processor = LayoutGANPPProcessor()
>>> records = processor.batch_decode(
... torch.zeros(1, 1, 4), torch.tensor([[0]])
... )
>>> records[0][0]["label"]
'Toolbar'
Source code in models/layoutganpp/src/layoutganpp/processing_layoutganpp.py
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 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | |
processor_for_dataset ¶
processor_for_dataset(
dataset_name: DatasetName | str,
) -> LayoutGANPPProcessor
Create a processor with the default labels for a dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_name
|
DatasetName | str
|
Dataset key or alias. |
required |
Returns:
| Type | Description |
|---|---|
LayoutGANPPProcessor
|
Processor initialized with the dataset's default label mapping. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the dataset name is unknown. |
Examples:
>>> processor_for_dataset("magazine").dataset_name
'magazine'
Source code in models/layoutganpp/src/layoutganpp/processing_layoutganpp.py
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | |
training ¶
Training utilities for LayoutGAN++.
LayoutGANPPDataModule ¶
Bases: LightningDataModule
Load local reference-shaped rows or deterministic smoke-test rows.
Source code in models/layoutganpp/src/layoutganpp/training/datamodule.py
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 | |
__init__ ¶
__init__(
*,
dataset_name: str,
data_root: str | None = None,
batch_size: int,
num_workers: int,
synthetic_size: int = 64,
seed: int = 0,
shuffle_train: bool = True,
) -> None
Initialize the package-local training data module.
Source code in models/layoutganpp/src/layoutganpp/training/datamodule.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | |
setup ¶
setup(stage: str | None = None) -> None
Create deterministic train, validation, and test datasets.
Source code in models/layoutganpp/src/layoutganpp/training/datamodule.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |
train_dataloader ¶
train_dataloader() -> DataLoader[LayoutRow]
Return the training data loader.
Source code in models/layoutganpp/src/layoutganpp/training/datamodule.py
63 64 65 66 67 68 69 70 71 72 73 74 | |
val_dataloader ¶
val_dataloader() -> DataLoader[LayoutRow]
Return the validation data loader.
Source code in models/layoutganpp/src/layoutganpp/training/datamodule.py
76 77 78 79 80 81 82 83 84 85 86 | |
test_dataloader ¶
test_dataloader() -> DataLoader[LayoutRow]
Return the test data loader.
Source code in models/layoutganpp/src/layoutganpp/training/datamodule.py
88 89 90 91 92 93 94 95 96 97 98 | |
LayoutGANPPTrainingModule ¶
Bases: LightningModule
Train the package generator and discriminator in reference update order.
Source code in models/layoutganpp/src/layoutganpp/training/lightning_module.py
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 | |
__init__ ¶
__init__(
*,
dataset_name: str,
latent_size: int,
generator_d_model: int,
generator_nhead: int,
generator_num_layers: int,
discriminator_d_model: int,
discriminator_nhead: int,
discriminator_num_layers: int,
learning_rate: float,
discriminator_max_elements: int = 50,
) -> None
Initialize the package generator and discriminator.
Source code in models/layoutganpp/src/layoutganpp/training/lightning_module.py
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 | |
configure_optimizers ¶
configure_optimizers() -> OptimizerLRScheduler
Create generator and discriminator Adam optimizers.
Source code in models/layoutganpp/src/layoutganpp/training/lightning_module.py
62 63 64 65 66 67 68 69 70 | |
training_step ¶
training_step(
batch: dict[str, Shaped[Tensor, "..."] | list[str]],
batch_idx: int,
) -> Shaped[torch.Tensor, "..."]
Run one manually ordered generator/discriminator update.
Source code in models/layoutganpp/src/layoutganpp/training/lightning_module.py
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 | |
datamodule ¶
Lightning data module for LayoutGAN++ training.
LayoutGANPPDataModule ¶
Bases: LightningDataModule
Load local reference-shaped rows or deterministic smoke-test rows.
Source code in models/layoutganpp/src/layoutganpp/training/datamodule.py
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 | |
__init__ ¶
__init__(
*,
dataset_name: str,
data_root: str | None = None,
batch_size: int,
num_workers: int,
synthetic_size: int = 64,
seed: int = 0,
shuffle_train: bool = True,
) -> None
Initialize the package-local training data module.
Source code in models/layoutganpp/src/layoutganpp/training/datamodule.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | |
setup ¶
setup(stage: str | None = None) -> None
Create deterministic train, validation, and test datasets.
Source code in models/layoutganpp/src/layoutganpp/training/datamodule.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |
train_dataloader ¶
train_dataloader() -> DataLoader[LayoutRow]
Return the training data loader.
Source code in models/layoutganpp/src/layoutganpp/training/datamodule.py
63 64 65 66 67 68 69 70 71 72 73 74 | |
val_dataloader ¶
val_dataloader() -> DataLoader[LayoutRow]
Return the validation data loader.
Source code in models/layoutganpp/src/layoutganpp/training/datamodule.py
76 77 78 79 80 81 82 83 84 85 86 | |
test_dataloader ¶
test_dataloader() -> DataLoader[LayoutRow]
Return the test data loader.
Source code in models/layoutganpp/src/layoutganpp/training/datamodule.py
88 89 90 91 92 93 94 95 96 97 98 | |
dataset ¶
Training datasets and deterministic layout collation for LayoutGAN++.
LayoutRow
dataclass
¶
One normalized layout row before padding.
Source code in models/layoutganpp/src/layoutganpp/training/dataset.py
25 26 27 28 29 30 31 32 33 | |
LayoutGANPPDataset ¶
Bases: Dataset[LayoutRow]
Dataset with reference-compatible sorting and split behavior.
Source code in models/layoutganpp/src/layoutganpp/training/dataset.py
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 | |
__init__ ¶
__init__(
*,
dataset_name: str,
split: str,
data_root: str | Path | None,
synthetic_size: int,
seed: int,
) -> None
Initialize a dataset from a local root or synthetic rows.
Source code in models/layoutganpp/src/layoutganpp/training/dataset.py
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 | |
__len__ ¶
__len__() -> int
Return the number of rows.
Source code in models/layoutganpp/src/layoutganpp/training/dataset.py
387 388 389 | |
__getitem__ ¶
__getitem__(index: int) -> LayoutRow
Return one normalized layout row.
Source code in models/layoutganpp/src/layoutganpp/training/dataset.py
391 392 393 | |
load_rows ¶
load_rows(
dataset_name: str, data_root: str | Path, split: str
) -> list[LayoutRow]
Load rows with the original split and preprocessing rules.
Source code in models/layoutganpp/src/layoutganpp/training/dataset.py
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 | |
synthetic_rows ¶
synthetic_rows(
dataset_name: str, size: int, seed: int
) -> list[LayoutRow]
Build deterministic rows for network-free wiring checks.
Source code in models/layoutganpp/src/layoutganpp/training/dataset.py
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 | |
collate_layoutganpp ¶
collate_layoutganpp(
rows: list[LayoutRow],
) -> dict[
str,
Float[torch.Tensor, "batch elements 4"]
| Int[torch.Tensor, "batch elements"]
| Bool[torch.Tensor, "batch elements"]
| list[str],
]
Pad a list of variable-length layouts into a training batch.
Source code in models/layoutganpp/src/layoutganpp/training/dataset.py
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 | |
lightning_module ¶
Lightning training module for LayoutGAN++.
LayoutGANPPTrainingModule ¶
Bases: LightningModule
Train the package generator and discriminator in reference update order.
Source code in models/layoutganpp/src/layoutganpp/training/lightning_module.py
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 | |
__init__ ¶
__init__(
*,
dataset_name: str,
latent_size: int,
generator_d_model: int,
generator_nhead: int,
generator_num_layers: int,
discriminator_d_model: int,
discriminator_nhead: int,
discriminator_num_layers: int,
learning_rate: float,
discriminator_max_elements: int = 50,
) -> None
Initialize the package generator and discriminator.
Source code in models/layoutganpp/src/layoutganpp/training/lightning_module.py
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 | |
configure_optimizers ¶
configure_optimizers() -> OptimizerLRScheduler
Create generator and discriminator Adam optimizers.
Source code in models/layoutganpp/src/layoutganpp/training/lightning_module.py
62 63 64 65 66 67 68 69 70 | |
training_step ¶
training_step(
batch: dict[str, Shaped[Tensor, "..."] | list[str]],
batch_idx: int,
) -> Shaped[torch.Tensor, "..."]
Run one manually ordered generator/discriminator update.
Source code in models/layoutganpp/src/layoutganpp/training/lightning_module.py
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 | |
modeling ¶
Package-local discriminator used by LayoutGAN++ training.
TransformerWithToken ¶
Bases: Module
Transformer encoder with a learned layout-summary token.
Source code in models/layoutganpp/src/layoutganpp/training/modeling.py
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 | |
__init__ ¶
__init__(
*,
d_model: int,
nhead: int,
dim_feedforward: int,
num_layers: int,
) -> None
Initialize the encoder and its learned summary token.
Source code in models/layoutganpp/src/layoutganpp/training/modeling.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | |
forward ¶
forward(
hidden: Float[Tensor, "elements batch hidden"],
padding_mask: Bool[Tensor, "batch elements"],
) -> Float[
torch.Tensor, "elements_plus_token batch hidden"
]
Encode layout elements together with the summary token.
Source code in models/layoutganpp/src/layoutganpp/training/modeling.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 | |
LayoutGANPPDiscriminator ¶
Bases: Module
Discriminator matching the original LayoutGAN++ topology.
Source code in models/layoutganpp/src/layoutganpp/training/modeling.py
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 | |
__init__ ¶
__init__(
*,
num_labels: int,
d_model: int,
nhead: int,
num_layers: int,
max_elements: int,
) -> None
Initialize the layout discriminator layers.
Source code in models/layoutganpp/src/layoutganpp/training/modeling.py
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 | |
forward ¶
forward(
bbox: Float[Tensor, "batch elements 4"],
labels: Int[Tensor, "batch elements"],
padding_mask: Bool[Tensor, "batch elements"],
reconst: bool = False,
) -> (
Float[torch.Tensor, "batch"]
| tuple[
Float[torch.Tensor, "batch"],
Float[torch.Tensor, "valid_elements labels"],
Float[torch.Tensor, "valid_elements 4"],
]
)
Return adversarial logits and optional reconstruction predictions.
Source code in models/layoutganpp/src/layoutganpp/training/modeling.py
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 | |
step ¶
One package-local LayoutGAN++ generator/discriminator iteration.
gan_forward_trace ¶
gan_forward_trace(
generator: Module,
discriminator: Module,
batch: dict[str, Shaped[Tensor, "..."] | list[str]],
*,
detach: bool = True,
) -> dict[str, Shaped[torch.Tensor, "..."]]
Capture one GAN forward trace without mutating model or optimizer state.
Source code in models/layoutganpp/src/layoutganpp/training/step.py
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 | |
run_gan_iteration ¶
run_gan_iteration(
generator: Module,
discriminator: Module,
batch: dict[str, Shaped[Tensor, "..."] | list[str]],
optimizer_g: Optimizer,
optimizer_d: Optimizer,
*,
backward: Callable[[Float[Tensor, "..."]], None]
| None = None,
) -> dict[str, Shaped[torch.Tensor, "..."]]
Run the original generator-then-discriminator update order.
Source code in models/layoutganpp/src/layoutganpp/training/step.py
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | |