Layoutganpp
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 | |
DatasetName ¶
Bases: StrEnum
Canonical dataset names supported by the shared label registry.
Source code in lib/laygen/src/laygen/common/labels.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | |
ConditionType ¶
Bases: StrEnum
Canonical condition names used by layout generation interfaces.
Source code in lib/laygen/src/laygen/common/conditions.py
9 10 11 12 13 14 15 16 17 18 19 20 21 | |
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
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 | |
__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
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 | |
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
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 | |
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
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 | |
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
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | |
OutputType ¶
Bases: StrEnum
Supported LayoutGAN++ generation output formats.
Source code in models/layoutganpp/src/layoutganpp/modeling_layoutganpp.py
58 59 60 61 62 | |
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_condition_type ¶
normalize_condition_type(
condition_type: ConditionType | str,
) -> ConditionType
Normalize condition aliases to a canonical ConditionType.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
condition_type
|
ConditionType | str
|
Canonical condition enum or a public/release alias. |
required |
Returns:
| Type | Description |
|---|---|
ConditionType
|
Canonical condition enum. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the condition type is unknown. |
Examples:
>>> str(normalize_condition_type("gen_t"))
'label'
>>> str(normalize_condition_type("gen_r"))
'relation'
Source code in lib/laygen/src/laygen/common/conditions.py
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 | |
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
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | |
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.
clip_normalized_xywh ¶
clip_normalized_xywh(
bbox: Float[Tensor, "... 4"],
) -> Float[torch.Tensor, "... 4"]
Clamp normalized box coordinates into the inclusive [0, 1] range.
Source code in lib/laygen/src/laygen/common/bbox.py
102 103 104 | |
ltrb_to_xywh ¶
ltrb_to_xywh(
bbox: Float[Tensor, "... 4"],
) -> Float[torch.Tensor, "... 4"]
Convert ltrb boxes to normalized center xywh boxes.
Source code in lib/laygen/src/laygen/common/bbox.py
75 76 77 78 79 80 81 82 83 | |
xywh_to_ltrb ¶
xywh_to_ltrb(
bbox: Float[Tensor, "... 4"],
) -> Float[torch.Tensor, "... 4"]
Convert normalized center xywh boxes to ltrb boxes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bbox
|
Float[Tensor, '... 4']
|
torch.Tensor with the last dimension ordered as center x, center y, width, and height. |
required |
Returns:
| Type | Description |
|---|---|
Float[Tensor, '... 4']
|
torch.Tensor with the same leading shape and last dimension ordered as left, |
Float[Tensor, '... 4']
|
top, right, and bottom. |
Examples:
>>> import torch
>>> xywh_to_ltrb(torch.tensor([[0.5, 0.5, 0.2, 0.4]])).shape
torch.Size([1, 4])
Source code in lib/laygen/src/laygen/common/bbox.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | |
layout_to_image ¶
layout_to_image(
bbox: Float[Tensor, "elements 4"],
labels: Int[Tensor, "elements"],
mask: Bool[Tensor, "elements"],
id2label: dict[int, str],
*,
ax: Axes | None = None,
canvas_size: tuple[int, int] = (1, 1),
colors: Iterable[str] | None = None,
) -> Axes
Render one layout on a Matplotlib axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bbox
|
Float[Tensor, 'elements 4']
|
Normalized center |
required |
labels
|
Int[Tensor, 'elements']
|
Integer labels for one sample. |
required |
mask
|
Bool[Tensor, 'elements']
|
Boolean valid-element mask for one sample. |
required |
id2label
|
dict[int, str]
|
Mapping from integer ids to label names. |
required |
ax
|
Axes | None
|
Optional Matplotlib axis. A new axis is created when omitted. |
None
|
canvas_size
|
tuple[int, int]
|
Canvas size as |
(1, 1)
|
colors
|
Iterable[str] | None
|
Optional color cycle. |
None
|
Returns:
| Type | Description |
|---|---|
Axes
|
Axis containing rectangle patches and label text. |
Examples:
>>> import torch
>>> ax = render_layout(
... torch.zeros(1, 4),
... torch.zeros(1, dtype=torch.long),
... torch.ones(1, dtype=torch.bool),
... {0: "text"},
... )
>>> ax is not None
True
Source code in lib/laygen/src/laygen/common/visualization.py
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 | |
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 | |
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
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | |
LayoutGANPPOutputDict ¶
Bases: TypedDict
Dictionary form of LayoutGAN++ public output.
Source code in models/layoutganpp/src/layoutganpp/modeling_layoutganpp.py
45 46 47 48 49 50 51 52 53 54 55 | |
OutputType ¶
Bases: StrEnum
Supported LayoutGAN++ generation output formats.
Source code in models/layoutganpp/src/layoutganpp/modeling_layoutganpp.py
58 59 60 61 62 | |
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
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 | |
__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
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 | |
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
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 | |
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
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 | |
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
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | |
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 | |