Model Card for DS-GAN¶
This package ports DS-GAN, the content-aware poster layout generator from PosterLayout, into a 🤗transformers-style package.
Model Details¶
Model Description¶
DS-GAN is a content-aware poster layout generator that predicts text, logo, and underlay element geometry from an RGB poster canvas plus saliency maps. The package wraps the released generator as DSGANModel, DSGANProcessor, and DSGANPipeline; public outputs use normalized center xywh boxes in [0, 1], dataset-local integer labels, a valid-element mask, and id2label.
- Developed by: HsiaoYuan Hsu, Xiangteng He, Yuxin Peng, Hao Kong, and Qing Zhang.
- Shared by: creative-graphic-design.
- Model type: content-aware; task: single-task; conditioning: none.
- Language(s) (NLP): not applicable.
- License: upstream license review needed before publishing converted weights.
Model Sources¶
- Repository: PosterLayout-CVPR2023 repository
- Paper: PosterLayout: A New Benchmark and Approach for Content-Aware Visual-Textual Presentation Layout
Supported Checkpoints¶
| Checkpoint | Hub ID | Status |
|---|---|---|
| PKU PosterLayout DS-GAN Epoch 300 | creative-graphic-design/ds-gan-pku-posterlayout |
not-published |
Uses¶
Direct Use¶
Use this package for research inference, conversion checks, and agreement checks against the original implementation for content-aware poster layout generation.
Conditional generation accepts an RGB content image plus one saliency map, or PFPNet and BASNet saliency maps that are merged before resizing:
from ds_gan import DSGANPipeline
pipe = DSGANPipeline.from_pretrained(
"creative-graphic-design/ds-gan-pku-posterlayout"
)
out = pipe(images=image, saliency=saliency, seed=0)
print(out.bbox, out.labels, out.mask)
Model/processor usage is also available for lower-level checks:
from ds_gan import DSGANModel, DSGANProcessor
model = DSGANModel.from_pretrained(
"creative-graphic-design/ds-gan-pku-posterlayout"
).eval()
processor = DSGANProcessor.from_pretrained(
"creative-graphic-design/ds-gan-pku-posterlayout"
)
encoded = processor(images=image, saliency=saliency)
out = model(**encoded)
decoded = processor.decode(class_probs=out.class_probs, bbox=out.bbox)
print(decoded.bbox, decoded.labels, decoded.mask)
Downstream Use¶
Generated layouts may feed rendering, design tooling, layout evaluation, or downstream poster composition 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 checkpoint, saliency preprocessing path, and PosterLayout data release. Dataset coverage, visual style, label vocabulary, and layout quality inherit the limits of those sources. The upstream repository does not include a top-level redistribution license.
Recommendations¶
Re-run the agreement-check suite against the original implementation before publishing converted checkpoints or comparing new results. Review generated layouts before downstream use and evaluate separately for each target poster domain.
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" \
"posgen @ git+https://github.com/creative-graphic-design/design-generators.git#subdirectory=lib/posgen" \
"ds-gan @ git+https://github.com/creative-graphic-design/design-generators.git#subdirectory=models/ds-gan"
Clone this repository, install the workspace member, and run the download and conversion steps in REPRODUCING.md. Those steps create .cache/ds-gan/converted/ds-gan-pku-posterlayout.
git clone https://github.com/creative-graphic-design/design-generators.git
cd design-generators
uv sync --package ds-gan
uv run --package ds-gan python
import torch
from ds_gan import DSGANPipeline
path = ".cache/ds-gan/converted/ds-gan-pku-posterlayout"
# After Hub publication: from_pretrained("creative-graphic-design/ds-gan-pku-posterlayout")
pipe = DSGANPipeline.from_pretrained(path, local_files_only=True)
out = pipe(pixel_values=torch.zeros(1, 4, 350, 240), seed=0)
print(out.bbox)
print(out.labels)
print(out.mask)
Training Details¶
Training Data¶
| Dataset | Dataset ID | Notes |
|---|---|---|
| PKU-PosterLayout | creative-graphic-design/PKU-PosterLayout |
PKU release agreement; box_elem stores pixel ltrb boxes and cls_elem includes text, logo, underlay, and INVALID |
Training Procedure¶
This package ports released behavior and does not retrain the method in this repository.
Preprocessing¶
Inputs and outputs are normalized to the public layout schema at package boundaries. RGB canvases and saliency maps are resized to (350, 240). PFPNet and BASNet saliency are merged by native-resolution pixelwise max before resize. The original class id 0 represents no object and becomes mask=False.
Training Hyperparameters¶
- Training regime: original upstream training; not rerun in this repository.
Speeds, Sizes, Times¶
Training-time and carbon measurements are unknown.
Evaluation¶
Testing Data, Factors & Metrics¶
Testing Data¶
Agreement checks use local-only generated fixtures from the released DS-GAN checkpoint and PosterLayout test canvases. Large generated tensors, images, weights, and downloaded artifacts are not committed.
Factors¶
Agreement checks are scoped to the PKU PosterLayout DS-GAN generator, fixed seed 0, content-image conditioning, and 905 test canvases.
Metrics¶
Metrics are exact tensor equality for model outputs, exact processor pixel-value equality against the regenerated original-implementation fixture, and exact public postprocessing equality for bbox, labels, and mask.
Parity Results¶
| Check | Cases | Match criterion | Result |
|---|---|---|---|
| Original-implementation DS-GAN class probabilities | 905 canvases x 32 slots x 4 classes | rtol=0, atol=0, max_abs=0.0, mismatched=0 |
passed |
| Original-implementation DS-GAN boxes | 905 canvases x 32 slots x 4 values | rtol=0, atol=0, max_abs=0.0, mismatched=0 |
passed |
Processor pixel_values |
905 canvases x 4 x 350 x 240 pixels | max_abs=0.0, mismatched=0 against regenerated fixture |
passed |
| Public postprocessing | bbox, labels, and mask for 905 decoded layouts |
exact equality against decoded original-implementation fixture | 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 new model training is performed by this conversion package. Conversion and agreement-check costs depend on local hardware and the selected checkpoint.
Technical Specifications¶
Model Architecture and Objective¶
DS-GAN loads the released PosterLayout generator checkpoint. A four-channel ResNet-FPN image encoder initializes a bidirectional LSTM over an initial layout tensor shaped (B, 32, 2, 4). The generator predicts original-implementation class probabilities over no_object, text, logo, and underlay, plus normalized center xywh boxes.
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 smoke tests. CUDA is recommended for heavyweight agreement checks against the original implementation and released checkpoint.
Software¶
Use uv run --package ds-gan ... from the repository root so workspace dependency sources and extras resolve correctly.
License¶
Repository wrapper code is Apache-2.0. The upstream PosterLayout repository does not include a top-level redistribution license; converted weights and Hub model repositories are held until license and release terms are reviewed.
Citation¶
@inproceedings{hsu2023posterlayout,
title = {PosterLayout: A New Benchmark and Approach for Content-Aware Visual-Textual Presentation Layout},
author = {Hsu, HsiaoYuan and He, Xiangteng and Peng, Yuxin and Kong, Hao and Zhang, Qing},
booktitle = {Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition},
year = {2023},
pages = {6018--6026}
}
API Reference¶
Transformers-style DS-GAN components for PosterLayout generation.
DSGANConfig ¶
Bases: PretrainedConfig
Store DS-GAN architecture and dataset metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_name
|
DatasetName | str
|
Dataset key. DS-GAN currently supports PKU PosterLayout. |
pku_posterlayout
|
backbone
|
str
|
Timm ResNet backbone name used by the reference checkpoint. |
'resnet50'
|
max_elem
|
int
|
Maximum number of generated elements. |
32
|
in_channels
|
int
|
CNN-LSTM input channels after flattening class and box planes. |
8
|
out_channels
|
int
|
CNN-LSTM convolution output channels. |
32
|
hidden_size
|
int | None
|
Bidirectional LSTM hidden size. |
None
|
num_layers
|
int
|
Number of LSTM layers. |
4
|
output_size
|
int
|
Combined class and box output width in the internal model. |
8
|
image_size
|
tuple[int, int] | list[int]
|
Processor/model input size as |
(350, 240)
|
reference_canvas_size
|
tuple[int, int] | list[int]
|
Reference normalization canvas as |
(513, 750)
|
backbone_feature_size
|
int
|
Flattened ResNet-FPN spatial size. The reference
default is |
330
|
model_num_classes
|
int
|
Internal class channels including |
4
|
id2label
|
Id2LabelMapping | None
|
Public zero-based semantic label mapping. |
None
|
model_subfolder
|
str
|
Pipeline subfolder for the model component. |
'model'
|
processor_subfolder
|
str
|
Pipeline subfolder for the processor component. |
'processor'
|
Examples:
>>> DSGANConfig().max_elem
32
Source code in models/ds-gan/src/ds_gan/configuration_ds_gan.py
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 | |
__init__ ¶
__init__(
dataset_name: DatasetName
| str = DatasetName.pku_posterlayout,
backbone: str = "resnet50",
max_elem: int = 32,
in_channels: int = 8,
out_channels: int = 32,
hidden_size: int | None = None,
num_layers: int = 4,
output_size: int = 8,
image_size: tuple[int, int] | list[int] = (350, 240),
reference_canvas_size: tuple[int, int] | list[int] = (
513,
750,
),
backbone_feature_size: int = 330,
model_num_classes: int = 4,
id2label: Id2LabelMapping | None = None,
label2id: dict[str, int] | None = None,
model_subfolder: str = "model",
processor_subfolder: str = "processor",
condition_types: list[str]
| tuple[str, ...]
| None = None,
architectures: list[str] | None = None,
model_type: str | None = None,
transformers_version: str | None = None,
torch_dtype: str | None = None,
dtype: str | None = None,
name_or_path: str = "",
_commit_hash: str | None = None,
**kwargs: str | int | float | bool | None,
) -> None
Initialize DS-GAN configuration.
Source code in models/ds-gan/src/ds_gan/configuration_ds_gan.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 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 | |
DSGANModel ¶
Bases: PreTrainedModel
Transformers-compatible DS-GAN generator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
DSGANConfig
|
DS-GAN model configuration. |
required |
Examples:
>>> config = DSGANConfig(backbone="resnet18", max_elem=4, hidden_size=32, num_layers=2, image_size=(64, 64), backbone_feature_size=16)
>>> model = DSGANModel(config)
>>> model.config.model_type
'ds_gan'
Source code in models/ds-gan/src/ds_gan/modeling_ds_gan.py
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 | |
__init__ ¶
__init__(
config: DSGANConfig,
*,
backbone_weights: str | Path | None = None,
) -> None
Initialize DS-GAN generator layers.
Source code in models/ds-gan/src/ds_gan/modeling_ds_gan.py
171 172 173 174 175 176 177 178 179 180 | |
forward ¶
forward(
pixel_values: Float[Tensor, "batch 4 height width"],
layout: Float[Tensor, "batch elements 2 4"],
return_dict: bool = True,
) -> (
DSGANModelOutput
| tuple[
Float[torch.Tensor, "batch elements 4"],
Float[torch.Tensor, "batch elements 4"],
]
)
Run a DS-GAN generator forward pass.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pixel_values
|
Float[Tensor, 'batch 4 height width']
|
RGB plus saliency tensor shaped |
required |
layout
|
Float[Tensor, 'batch elements 2 4']
|
Initial internal layout shaped |
required |
return_dict
|
bool
|
Whether to return a dataclass output. |
True
|
Returns:
| Type | Description |
|---|---|
DSGANModelOutput | tuple[Float[Tensor, 'batch elements 4'], Float[Tensor, 'batch elements 4']]
|
Raw class probabilities and normalized center |
Raises:
| Type | Description |
|---|---|
ValueError
|
If tensor shapes do not match the config. |
Source code in models/ds-gan/src/ds_gan/modeling_ds_gan.py
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 | |
DSGANModelOutput
dataclass
¶
Bases: ModelOutput
Raw DS-GAN generator output.
Attributes:
| Name | Type | Description |
|---|---|---|
class_probs |
Float[Tensor, 'batch elements 4']
|
Internal class probabilities with shape
|
bbox |
Float[Tensor, 'batch elements 4'] | None
|
Normalized center |
initial_layout |
Float[Tensor, 'batch elements 2 4'] | None
|
Initial class/box layout passed to the generator. |
Source code in models/ds-gan/src/ds_gan/modeling_ds_gan.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | |
DSGANPipeline ¶
Bases: LayoutGenerationPipeline
Transformers-side pipeline for content-aware PosterLayout generation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
DSGANModel
|
DS-GAN generator. |
required |
processor
|
DSGANProcessor | None
|
Optional processor for images and output decoding. |
None
|
config
|
DSGANConfig | None
|
Optional root pipeline config. |
None
|
device
|
str | device | None
|
Optional runtime device. |
None
|
Examples:
>>> config = DSGANConfig(backbone="resnet18", max_elem=4, hidden_size=32, num_layers=2, image_size=(64, 64), backbone_feature_size=16)
>>> pipe = DSGANPipeline(DSGANModel(config))
>>> pipe.config.model_type
'ds_gan'
Source code in models/ds-gan/src/ds_gan/pipeline_ds_gan.py
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 | |
__init__ ¶
__init__(
model: DSGANModel,
processor: DSGANProcessor | None = None,
config: DSGANConfig | None = None,
device: str | device | None = None,
) -> None
Initialize DS-GAN pipeline.
Source code in models/ds-gan/src/ds_gan/pipeline_ds_gan.py
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | |
__call__ ¶
__call__(
images: ImageInput
| list[ImageInput]
| Float[Tensor, "..."]
| None = None,
*,
batch_size: int = 1,
seed: int | None = None,
generator: Generator | None = None,
condition_type: ConditionType
| str = ConditionType.content_image,
labels: Int[Tensor, "batch elements"]
| Sequence[ArrayLikeInput]
| None = None,
bbox: Float[Tensor, "batch elements 4"]
| Sequence[ArrayLikeInput]
| None = None,
mask: Bool[Tensor, "batch elements"]
| Sequence[ArrayLikeInput]
| 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,
num_inference_steps: int | None = None,
output_type: OutputType | str = OutputType.dataclass,
return_intermediates: bool = False,
saliency: ImageInput
| list[ImageInput]
| Float[Tensor, "..."]
| None = None,
saliency_pfpnet: ImageInput
| list[ImageInput]
| Float[Tensor, "..."]
| None = None,
saliency_basnet: ImageInput
| list[ImageInput]
| Float[Tensor, "..."]
| None = None,
pixel_values: Float[Tensor, "batch 4 height width"]
| None = None,
initial_layout: Float[Tensor, "batch elements 2 4"]
| None = None,
) -> (
LayoutGenerationOutput
| dict[
str,
Shaped[torch.Tensor, "..."]
| dict[int, str]
| Mapping[
str,
Shaped[torch.Tensor, "..."]
| ConditionType
| str
| bool,
]
| None,
]
)
Generate layouts from content images and saliency maps.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
images
|
ImageInput | list[ImageInput] | Float[Tensor, '...'] | None
|
RGB image or batch. Required unless |
None
|
batch_size
|
int
|
Batch size used when |
1
|
seed
|
int | None
|
Convenience seed. Ignored when |
None
|
generator
|
Generator | None
|
Explicit torch generator. |
None
|
condition_type
|
ConditionType | str
|
Must normalize to |
content_image
|
labels
|
Int[Tensor, 'batch elements'] | Sequence[ArrayLikeInput] | None
|
Optional public labels used only with |
None
|
bbox
|
Float[Tensor, 'batch elements 4'] | Sequence[ArrayLikeInput] | None
|
Optional public boxes used with |
None
|
mask
|
Bool[Tensor, 'batch elements'] | Sequence[ArrayLikeInput] | None
|
Optional valid-element mask for fixed initial layouts. |
None
|
num_elements
|
int | list[int] | Int[Tensor, 'batch'] | None
|
Reserved compatibility argument. |
None
|
box_format
|
BoxFormat | str
|
Format of optional |
xywh
|
normalized
|
bool
|
Whether optional |
True
|
canvas_size
|
tuple[int, int] | None
|
Pixel canvas size for optional unnormalized |
None
|
num_inference_steps
|
int | None
|
Reserved compatibility argument. |
None
|
output_type
|
OutputType | str
|
|
dataclass
|
return_intermediates
|
bool
|
Whether to include raw model tensors. |
False
|
saliency
|
ImageInput | list[ImageInput] | Float[Tensor, '...'] | None
|
Optional single merged saliency map. |
None
|
saliency_pfpnet
|
ImageInput | list[ImageInput] | Float[Tensor, '...'] | None
|
Optional PFPNet saliency map. |
None
|
saliency_basnet
|
ImageInput | list[ImageInput] | Float[Tensor, '...'] | None
|
Optional BASNet saliency map. |
None
|
pixel_values
|
Float[Tensor, 'batch 4 height width'] | None
|
Preprocessed |
None
|
initial_layout
|
Float[Tensor, 'batch elements 2 4'] | None
|
Optional internal layout |
None
|
Returns:
| Type | Description |
|---|---|
LayoutGenerationOutput | dict[str, Shaped[Tensor, '...'] | dict[int, str] | Mapping[str, Shaped[Tensor, '...'] | ConditionType | str | bool] | None]
|
Shared layout-generation output. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the condition, image inputs, or fixed layout are invalid. |
Source code in models/ds-gan/src/ds_gan/pipeline_ds_gan.py
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 | |
OutputType ¶
Bases: StrEnum
Supported DS-GAN pipeline output containers.
Source code in models/ds-gan/src/ds_gan/pipeline_ds_gan.py
36 37 38 39 40 | |
DSGANProcessor ¶
Bases: ProcessorMixin
Prepare PosterLayout RGB/saliency inputs and decode DS-GAN outputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_name
|
DatasetName | str
|
Dataset key. Only PKU PosterLayout is supported. |
pku_posterlayout
|
id2label
|
dict[int | str, str] | None
|
Public semantic labels excluding model |
None
|
image_size
|
tuple[int, int] | list[int]
|
Resize target as |
(350, 240)
|
Examples:
>>> processor = DSGANProcessor()
>>> processor.id2label[0]
'text'
Source code in models/ds-gan/src/ds_gan/processing_ds_gan.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 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 | |
__init__ ¶
__init__(
dataset_name: DatasetName
| str = DatasetName.pku_posterlayout,
id2label: dict[int | str, str] | None = None,
image_size: tuple[int, int] | list[int] = (350, 240),
) -> None
Initialize processor metadata.
Source code in models/ds-gan/src/ds_gan/processing_ds_gan.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | |
__call__ ¶
__call__(
images: DSGANImageInput | Sequence[DSGANImageInput],
*,
saliency: DSGANImageInput
| Sequence[DSGANImageInput]
| None = None,
saliency_pfpnet: DSGANImageInput
| Sequence[DSGANImageInput]
| None = None,
saliency_basnet: DSGANImageInput
| Sequence[DSGANImageInput]
| None = None,
return_tensors: Literal["pt"] = "pt",
) -> BatchEncoding
Encode content images into pixel_values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
images
|
DSGANImageInput | Sequence[DSGANImageInput]
|
RGB image or batch of RGB images. |
required |
saliency
|
DSGANImageInput | Sequence[DSGANImageInput] | None
|
Optional saliency image or batch. If omitted and both saliency maps are given, the maps are merged by pixelwise max. |
None
|
saliency_pfpnet
|
DSGANImageInput | Sequence[DSGANImageInput] | None
|
Optional PFPNet saliency map. |
None
|
saliency_basnet
|
DSGANImageInput | Sequence[DSGANImageInput] | None
|
Optional BASNet saliency map. |
None
|
return_tensors
|
Literal['pt']
|
Tensor framework. Only |
'pt'
|
Returns:
| Type | Description |
|---|---|
BatchEncoding
|
Batch encoding containing |
Source code in models/ds-gan/src/ds_gan/processing_ds_gan.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 | |
decode ¶
decode(
*,
class_probs: Float[Tensor, "batch elements 4"],
bbox: Float[Tensor, "batch elements 4"],
output_type: Literal["dataclass", "dict"] = "dataclass",
scores: Float[Tensor, "batch elements"] | None = None,
intermediates: Mapping[
str, Shaped[Tensor, "..."] | str | bool
]
| None = None,
) -> (
LayoutGenerationOutput
| dict[
str,
Shaped[torch.Tensor, "..."]
| dict[int, str]
| Mapping[
str, Shaped[torch.Tensor, "..."] | str | bool
]
| None,
]
)
Decode raw DS-GAN class probabilities and boxes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
class_probs
|
Float[Tensor, 'batch elements 4']
|
Internal class probabilities shaped |
required |
bbox
|
Float[Tensor, 'batch elements 4']
|
Normalized center |
required |
output_type
|
Literal['dataclass', 'dict']
|
Return format. |
'dataclass'
|
scores
|
Float[Tensor, 'batch elements'] | None
|
Optional per-element class scores. |
None
|
intermediates
|
Mapping[str, Shaped[Tensor, '...'] | str | bool] | None
|
Optional model-specific intermediate tensors. |
None
|
Returns:
| Type | Description |
|---|---|
LayoutGenerationOutput | dict[str, Shaped[Tensor, '...'] | dict[int, str] | Mapping[str, Shaped[Tensor, '...'] | str | bool] | None]
|
Shared layout output with public labels and mask semantics. |
Source code in models/ds-gan/src/ds_gan/processing_ds_gan.py
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 | |
encode_layout ¶
encode_layout(
*,
bbox: Float[Tensor, "batch elements 4"]
| Float[ndarray, "batch elements 4"]
| Sequence[ArrayLikeInput],
labels: Int[Tensor, "batch elements"]
| Int[ndarray, "batch elements"]
| Sequence[ArrayLikeInput],
mask: Bool[Tensor, "batch elements"]
| Bool[ndarray, "batch elements"]
| Sequence[ArrayLikeInput]
| None = None,
box_format: BoxFormat | str = BoxFormat.xywh,
normalized: bool = True,
canvas_size: tuple[int, int] | None = None,
max_elem: int = 32,
) -> dict[str, Shaped[torch.Tensor, "..."]]
Encode public boxes/labels into the internal layout tensor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bbox
|
Float[Tensor, 'batch elements 4'] | Float[ndarray, 'batch elements 4'] | Sequence[ArrayLikeInput]
|
Public boxes. |
required |
labels
|
Int[Tensor, 'batch elements'] | Int[ndarray, 'batch elements'] | Sequence[ArrayLikeInput]
|
Public zero-based semantic labels. |
required |
mask
|
Bool[Tensor, 'batch elements'] | Bool[ndarray, 'batch elements'] | Sequence[ArrayLikeInput] | None
|
Optional valid-element mask. |
None
|
box_format
|
BoxFormat | str
|
Input box format. |
xywh
|
normalized
|
bool
|
Whether the boxes are normalized. |
True
|
canvas_size
|
tuple[int, int] | None
|
Pixel canvas size used when |
None
|
max_elem
|
int
|
Output slot count. |
32
|
Returns:
| Type | Description |
|---|---|
dict[str, Shaped[Tensor, '...']]
|
Dictionary with internal |
Source code in models/ds-gan/src/ds_gan/processing_ds_gan.py
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 | |
pad ¶
pad(
bbox: Float[Tensor, "batch elements 4"],
labels: Int[Tensor, "batch elements"],
mask: Bool[Tensor, "batch elements"],
*,
max_elem: int,
) -> tuple[
Float[torch.Tensor, "batch padded_elements 4"],
Int[torch.Tensor, "batch padded_elements"],
Bool[torch.Tensor, "batch padded_elements"],
]
Pad layout tensors to DS-GAN max_elem slots.
Source code in models/ds-gan/src/ds_gan/processing_ds_gan.py
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 | |
default_ds_gan_config ¶
default_ds_gan_config() -> DSGANConfig
Return the reference-compatible DS-GAN default configuration.
Examples:
>>> default_ds_gan_config().backbone
'resnet50'
Source code in models/ds-gan/src/ds_gan/configuration_ds_gan.py
125 126 127 128 129 130 131 132 | |
convert_vendor_state_dict ¶
convert_vendor_state_dict(
state_dict: Mapping[str, Shaped[Tensor, "..."]],
) -> dict[str, Shaped[torch.Tensor, "..."]]
Convert vendor DS-GAN generator keys to DSGANModel keys.
The released checkpoint was commonly saved from torch.nn.DataParallel;
this helper strips the leading module. prefix and keeps all generator
module names otherwise unchanged.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state_dict
|
Mapping[str, Shaped[Tensor, '...']]
|
Original checkpoint mapping. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Shaped[Tensor, '...']]
|
Converted state dictionary. |
Examples:
>>> convert_vendor_state_dict({"module.fc1.weight": torch.zeros(1)})["fc1.weight"].shape
torch.Size([1])
Source code in models/ds-gan/src/ds_gan/conversion.py
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 | |
random_initial_layout ¶
random_initial_layout(
batch_size: int,
max_elem: int,
*,
generator: Generator | None = None,
seed: int | None = None,
device: device | str | None = None,
dtype: dtype = torch.float32,
weighted_classes: bool = True,
use_numpy_classes: bool = False,
) -> Float[torch.Tensor, "batch elements 2 4"]
Sample the DS-GAN initial layout tensor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch_size
|
int
|
Batch size. |
required |
max_elem
|
int
|
Number of layout slots. |
required |
generator
|
Generator | None
|
Optional torch generator. Takes precedence over |
None
|
seed
|
int | None
|
Convenience seed used only when |
None
|
device
|
device | str | None
|
Target torch device. |
None
|
dtype
|
dtype
|
Target floating dtype. |
float32
|
weighted_classes
|
bool
|
Whether to use the released inference class prior. |
True
|
use_numpy_classes
|
bool
|
Use NumPy's legacy |
False
|
Returns:
| Type | Description |
|---|---|
Float[Tensor, 'batch elements 2 4']
|
Tensor shaped |
Source code in models/ds-gan/src/ds_gan/modeling_ds_gan.py
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 | |
annotations_from_pku_example ¶
annotations_from_pku_example(
example: Mapping[str, DSGANExampleValue],
*,
max_elem: int = 32,
include_unconnected_underlays: bool = True,
canvas_size: tuple[int, int] | None = None,
vendor_box_fix: bool = False,
) -> dict[
str, Shaped[torch.Tensor, "..."] | tuple[int, int]
]
Convert a PKU PosterLayout dataset row into public layout tensors.
The adapter filters INVALID annotations, converts pixel ltrb boxes
to normalized center xywh, derives canvas size from the image columns,
and applies the reference designSeq.reorder ordering policy. Set
vendor_box_fix to reproduce the reference loader's overlapping-slice
assignment for inverted boxes.
Source code in models/ds-gan/src/ds_gan/processing_ds_gan.py
411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 | |
processor_for_dataset ¶
processor_for_dataset(
dataset_name: DatasetName | str,
) -> DSGANProcessor
Create a DS-GAN processor for a supported dataset.
Source code in models/ds-gan/src/ds_gan/processing_ds_gan.py
308 309 310 | |
configuration_ds_gan ¶
Configuration for converted DS-GAN checkpoints.
DSGANConfig ¶
Bases: PretrainedConfig
Store DS-GAN architecture and dataset metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_name
|
DatasetName | str
|
Dataset key. DS-GAN currently supports PKU PosterLayout. |
pku_posterlayout
|
backbone
|
str
|
Timm ResNet backbone name used by the reference checkpoint. |
'resnet50'
|
max_elem
|
int
|
Maximum number of generated elements. |
32
|
in_channels
|
int
|
CNN-LSTM input channels after flattening class and box planes. |
8
|
out_channels
|
int
|
CNN-LSTM convolution output channels. |
32
|
hidden_size
|
int | None
|
Bidirectional LSTM hidden size. |
None
|
num_layers
|
int
|
Number of LSTM layers. |
4
|
output_size
|
int
|
Combined class and box output width in the internal model. |
8
|
image_size
|
tuple[int, int] | list[int]
|
Processor/model input size as |
(350, 240)
|
reference_canvas_size
|
tuple[int, int] | list[int]
|
Reference normalization canvas as |
(513, 750)
|
backbone_feature_size
|
int
|
Flattened ResNet-FPN spatial size. The reference
default is |
330
|
model_num_classes
|
int
|
Internal class channels including |
4
|
id2label
|
Id2LabelMapping | None
|
Public zero-based semantic label mapping. |
None
|
model_subfolder
|
str
|
Pipeline subfolder for the model component. |
'model'
|
processor_subfolder
|
str
|
Pipeline subfolder for the processor component. |
'processor'
|
Examples:
>>> DSGANConfig().max_elem
32
Source code in models/ds-gan/src/ds_gan/configuration_ds_gan.py
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 | |
__init__ ¶
__init__(
dataset_name: DatasetName
| str = DatasetName.pku_posterlayout,
backbone: str = "resnet50",
max_elem: int = 32,
in_channels: int = 8,
out_channels: int = 32,
hidden_size: int | None = None,
num_layers: int = 4,
output_size: int = 8,
image_size: tuple[int, int] | list[int] = (350, 240),
reference_canvas_size: tuple[int, int] | list[int] = (
513,
750,
),
backbone_feature_size: int = 330,
model_num_classes: int = 4,
id2label: Id2LabelMapping | None = None,
label2id: dict[str, int] | None = None,
model_subfolder: str = "model",
processor_subfolder: str = "processor",
condition_types: list[str]
| tuple[str, ...]
| None = None,
architectures: list[str] | None = None,
model_type: str | None = None,
transformers_version: str | None = None,
torch_dtype: str | None = None,
dtype: str | None = None,
name_or_path: str = "",
_commit_hash: str | None = None,
**kwargs: str | int | float | bool | None,
) -> None
Initialize DS-GAN configuration.
Source code in models/ds-gan/src/ds_gan/configuration_ds_gan.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 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 | |
default_ds_gan_config ¶
default_ds_gan_config() -> DSGANConfig
Return the reference-compatible DS-GAN default configuration.
Examples:
>>> default_ds_gan_config().backbone
'resnet50'
Source code in models/ds-gan/src/ds_gan/configuration_ds_gan.py
125 126 127 128 129 130 131 132 | |
pku_model_label2id ¶
pku_model_label2id() -> dict[str, int]
Return DS-GAN model labels including the no-object class.
Examples:
>>> pku_model_label2id()["no_object"]
0
Source code in models/ds-gan/src/ds_gan/configuration_ds_gan.py
135 136 137 138 139 140 141 142 | |
pku_dataset_label2id ¶
pku_dataset_label2id() -> dict[str, int]
Return PKU dataset annotation labels including INVALID.
Source code in models/ds-gan/src/ds_gan/configuration_ds_gan.py
145 146 147 | |
conversion ¶
Conversion helpers for original PosterLayout DS-GAN checkpoints.
convert_vendor_state_dict ¶
convert_vendor_state_dict(
state_dict: Mapping[str, Shaped[Tensor, "..."]],
) -> dict[str, Shaped[torch.Tensor, "..."]]
Convert vendor DS-GAN generator keys to DSGANModel keys.
The released checkpoint was commonly saved from torch.nn.DataParallel;
this helper strips the leading module. prefix and keeps all generator
module names otherwise unchanged.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state_dict
|
Mapping[str, Shaped[Tensor, '...']]
|
Original checkpoint mapping. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Shaped[Tensor, '...']]
|
Converted state dictionary. |
Examples:
>>> convert_vendor_state_dict({"module.fc1.weight": torch.zeros(1)})["fc1.weight"].shape
torch.Size([1])
Source code in models/ds-gan/src/ds_gan/conversion.py
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 | |
config_from_vendor_args ¶
config_from_vendor_args(
args: Namespace
| SimpleNamespace
| Mapping[str, DSGANArgValue]
| None = None,
) -> DSGANConfig
Build a DS-GAN config from vendor args or defaults.
Source code in models/ds-gan/src/ds_gan/conversion.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | |
model_card ¶
Hub model-card helper for converted DS-GAN checkpoints.
dsgan_model_card ¶
dsgan_model_card() -> ModelCard
Build the DS-GAN PKU PosterLayout Hub model card.
Source code in models/ds-gan/src/ds_gan/model_card.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | |
write_dsgan_model_card ¶
write_dsgan_model_card(output_dir: str | Path) -> Path
Write README.md for a converted DS-GAN checkpoint directory.
Source code in models/ds-gan/src/ds_gan/model_card.py
73 74 75 76 77 | |
modeling_ds_gan ¶
PyTorch/Transformers implementation of the PosterLayout DS-GAN generator.
DSGANModelOutput
dataclass
¶
Bases: ModelOutput
Raw DS-GAN generator output.
Attributes:
| Name | Type | Description |
|---|---|---|
class_probs |
Float[Tensor, 'batch elements 4']
|
Internal class probabilities with shape
|
bbox |
Float[Tensor, 'batch elements 4'] | None
|
Normalized center |
initial_layout |
Float[Tensor, 'batch elements 2 4'] | None
|
Initial class/box layout passed to the generator. |
Source code in models/ds-gan/src/ds_gan/modeling_ds_gan.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | |
ResnetBackbone ¶
Bases: Module
DS-GAN ResNet-FPN encoder used to initialize the DS-GAN LSTM state.
Source code in models/ds-gan/src/ds_gan/modeling_ds_gan.py
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 | |
__init__ ¶
__init__(
config: DSGANConfig,
*,
backbone_weights: str | Path | None = None,
) -> None
Initialize the ResNet-FPN encoder.
Source code in models/ds-gan/src/ds_gan/modeling_ds_gan.py
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 | |
forward ¶
forward(
pixel_values: Float[Tensor, "batch 4 height width"],
) -> Float[torch.Tensor, "layers2 batch hidden"]
Encode image/saliency tensors into an LSTM initial hidden state.
Source code in models/ds-gan/src/ds_gan/modeling_ds_gan.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | |
CNNLSTM ¶
Bases: Module
DS-GAN CNN-LSTM sequence model.
Source code in models/ds-gan/src/ds_gan/modeling_ds_gan.py
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 | |
__init__ ¶
__init__(config: DSGANConfig) -> None
Initialize the CNN-LSTM block.
Source code in models/ds-gan/src/ds_gan/modeling_ds_gan.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | |
forward ¶
forward(
layout: Float[Tensor, "batch elements 2 4"],
h0: Float[Tensor, "layers2 batch hidden"],
) -> Float[torch.Tensor, "batch elements hidden2"]
Run the DS-GAN CNN-LSTM over initial layout tensors.
Source code in models/ds-gan/src/ds_gan/modeling_ds_gan.py
137 138 139 140 141 142 143 144 145 146 147 | |
DSGANModel ¶
Bases: PreTrainedModel
Transformers-compatible DS-GAN generator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
DSGANConfig
|
DS-GAN model configuration. |
required |
Examples:
>>> config = DSGANConfig(backbone="resnet18", max_elem=4, hidden_size=32, num_layers=2, image_size=(64, 64), backbone_feature_size=16)
>>> model = DSGANModel(config)
>>> model.config.model_type
'ds_gan'
Source code in models/ds-gan/src/ds_gan/modeling_ds_gan.py
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 | |
__init__ ¶
__init__(
config: DSGANConfig,
*,
backbone_weights: str | Path | None = None,
) -> None
Initialize DS-GAN generator layers.
Source code in models/ds-gan/src/ds_gan/modeling_ds_gan.py
171 172 173 174 175 176 177 178 179 180 | |
forward ¶
forward(
pixel_values: Float[Tensor, "batch 4 height width"],
layout: Float[Tensor, "batch elements 2 4"],
return_dict: bool = True,
) -> (
DSGANModelOutput
| tuple[
Float[torch.Tensor, "batch elements 4"],
Float[torch.Tensor, "batch elements 4"],
]
)
Run a DS-GAN generator forward pass.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pixel_values
|
Float[Tensor, 'batch 4 height width']
|
RGB plus saliency tensor shaped |
required |
layout
|
Float[Tensor, 'batch elements 2 4']
|
Initial internal layout shaped |
required |
return_dict
|
bool
|
Whether to return a dataclass output. |
True
|
Returns:
| Type | Description |
|---|---|
DSGANModelOutput | tuple[Float[Tensor, 'batch elements 4'], Float[Tensor, 'batch elements 4']]
|
Raw class probabilities and normalized center |
Raises:
| Type | Description |
|---|---|
ValueError
|
If tensor shapes do not match the config. |
Source code in models/ds-gan/src/ds_gan/modeling_ds_gan.py
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 | |
xyxy_to_xywh ¶
xyxy_to_xywh(
bbox: Float[Tensor, "... 4"],
) -> Float[torch.Tensor, "... 4"]
Convert left/top/right/bottom boxes to center xywh boxes.
Source code in models/ds-gan/src/ds_gan/modeling_ds_gan.py
229 230 231 232 233 234 235 236 237 | |
random_initial_layout ¶
random_initial_layout(
batch_size: int,
max_elem: int,
*,
generator: Generator | None = None,
seed: int | None = None,
device: device | str | None = None,
dtype: dtype = torch.float32,
weighted_classes: bool = True,
use_numpy_classes: bool = False,
) -> Float[torch.Tensor, "batch elements 2 4"]
Sample the DS-GAN initial layout tensor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch_size
|
int
|
Batch size. |
required |
max_elem
|
int
|
Number of layout slots. |
required |
generator
|
Generator | None
|
Optional torch generator. Takes precedence over |
None
|
seed
|
int | None
|
Convenience seed used only when |
None
|
device
|
device | str | None
|
Target torch device. |
None
|
dtype
|
dtype
|
Target floating dtype. |
float32
|
weighted_classes
|
bool
|
Whether to use the released inference class prior. |
True
|
use_numpy_classes
|
bool
|
Use NumPy's legacy |
False
|
Returns:
| Type | Description |
|---|---|
Float[Tensor, 'batch elements 2 4']
|
Tensor shaped |
Source code in models/ds-gan/src/ds_gan/modeling_ds_gan.py
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 | |
pipeline_ds_gan ¶
Pipeline interface for PosterLayout DS-GAN generation.
DSGANPipelineComponent ¶
Bases: Protocol
Runtime-checkable loaded pipeline component marker.
Source code in models/ds-gan/src/ds_gan/pipeline_ds_gan.py
31 32 33 | |
OutputType ¶
Bases: StrEnum
Supported DS-GAN pipeline output containers.
Source code in models/ds-gan/src/ds_gan/pipeline_ds_gan.py
36 37 38 39 40 | |
DSGANPipeline ¶
Bases: LayoutGenerationPipeline
Transformers-side pipeline for content-aware PosterLayout generation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
DSGANModel
|
DS-GAN generator. |
required |
processor
|
DSGANProcessor | None
|
Optional processor for images and output decoding. |
None
|
config
|
DSGANConfig | None
|
Optional root pipeline config. |
None
|
device
|
str | device | None
|
Optional runtime device. |
None
|
Examples:
>>> config = DSGANConfig(backbone="resnet18", max_elem=4, hidden_size=32, num_layers=2, image_size=(64, 64), backbone_feature_size=16)
>>> pipe = DSGANPipeline(DSGANModel(config))
>>> pipe.config.model_type
'ds_gan'
Source code in models/ds-gan/src/ds_gan/pipeline_ds_gan.py
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 | |
__init__ ¶
__init__(
model: DSGANModel,
processor: DSGANProcessor | None = None,
config: DSGANConfig | None = None,
device: str | device | None = None,
) -> None
Initialize DS-GAN pipeline.
Source code in models/ds-gan/src/ds_gan/pipeline_ds_gan.py
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | |
__call__ ¶
__call__(
images: ImageInput
| list[ImageInput]
| Float[Tensor, "..."]
| None = None,
*,
batch_size: int = 1,
seed: int | None = None,
generator: Generator | None = None,
condition_type: ConditionType
| str = ConditionType.content_image,
labels: Int[Tensor, "batch elements"]
| Sequence[ArrayLikeInput]
| None = None,
bbox: Float[Tensor, "batch elements 4"]
| Sequence[ArrayLikeInput]
| None = None,
mask: Bool[Tensor, "batch elements"]
| Sequence[ArrayLikeInput]
| 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,
num_inference_steps: int | None = None,
output_type: OutputType | str = OutputType.dataclass,
return_intermediates: bool = False,
saliency: ImageInput
| list[ImageInput]
| Float[Tensor, "..."]
| None = None,
saliency_pfpnet: ImageInput
| list[ImageInput]
| Float[Tensor, "..."]
| None = None,
saliency_basnet: ImageInput
| list[ImageInput]
| Float[Tensor, "..."]
| None = None,
pixel_values: Float[Tensor, "batch 4 height width"]
| None = None,
initial_layout: Float[Tensor, "batch elements 2 4"]
| None = None,
) -> (
LayoutGenerationOutput
| dict[
str,
Shaped[torch.Tensor, "..."]
| dict[int, str]
| Mapping[
str,
Shaped[torch.Tensor, "..."]
| ConditionType
| str
| bool,
]
| None,
]
)
Generate layouts from content images and saliency maps.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
images
|
ImageInput | list[ImageInput] | Float[Tensor, '...'] | None
|
RGB image or batch. Required unless |
None
|
batch_size
|
int
|
Batch size used when |
1
|
seed
|
int | None
|
Convenience seed. Ignored when |
None
|
generator
|
Generator | None
|
Explicit torch generator. |
None
|
condition_type
|
ConditionType | str
|
Must normalize to |
content_image
|
labels
|
Int[Tensor, 'batch elements'] | Sequence[ArrayLikeInput] | None
|
Optional public labels used only with |
None
|
bbox
|
Float[Tensor, 'batch elements 4'] | Sequence[ArrayLikeInput] | None
|
Optional public boxes used with |
None
|
mask
|
Bool[Tensor, 'batch elements'] | Sequence[ArrayLikeInput] | None
|
Optional valid-element mask for fixed initial layouts. |
None
|
num_elements
|
int | list[int] | Int[Tensor, 'batch'] | None
|
Reserved compatibility argument. |
None
|
box_format
|
BoxFormat | str
|
Format of optional |
xywh
|
normalized
|
bool
|
Whether optional |
True
|
canvas_size
|
tuple[int, int] | None
|
Pixel canvas size for optional unnormalized |
None
|
num_inference_steps
|
int | None
|
Reserved compatibility argument. |
None
|
output_type
|
OutputType | str
|
|
dataclass
|
return_intermediates
|
bool
|
Whether to include raw model tensors. |
False
|
saliency
|
ImageInput | list[ImageInput] | Float[Tensor, '...'] | None
|
Optional single merged saliency map. |
None
|
saliency_pfpnet
|
ImageInput | list[ImageInput] | Float[Tensor, '...'] | None
|
Optional PFPNet saliency map. |
None
|
saliency_basnet
|
ImageInput | list[ImageInput] | Float[Tensor, '...'] | None
|
Optional BASNet saliency map. |
None
|
pixel_values
|
Float[Tensor, 'batch 4 height width'] | None
|
Preprocessed |
None
|
initial_layout
|
Float[Tensor, 'batch elements 2 4'] | None
|
Optional internal layout |
None
|
Returns:
| Type | Description |
|---|---|
LayoutGenerationOutput | dict[str, Shaped[Tensor, '...'] | dict[int, str] | Mapping[str, Shaped[Tensor, '...'] | ConditionType | str | bool] | None]
|
Shared layout-generation output. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the condition, image inputs, or fixed layout are invalid. |
Source code in models/ds-gan/src/ds_gan/pipeline_ds_gan.py
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 | |
normalize_condition_type ¶
normalize_condition_type(
condition_type: ConditionType | str | None,
) -> ConditionType
Normalize DS-GAN condition aliases.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
condition_type
|
ConditionType | str | None
|
Canonical condition enum, alias, or |
required |
Returns:
| Type | Description |
|---|---|
ConditionType
|
Canonical |
Raises:
| Type | Description |
|---|---|
ValueError
|
If DS-GAN does not support the requested mode. |
Examples:
>>> str(normalize_condition_type("content"))
'content_image'
Source code in models/ds-gan/src/ds_gan/pipeline_ds_gan.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 | |
normalize_output_type ¶
normalize_output_type(
output_type: OutputType | str,
) -> OutputType
Normalize public output type aliases.
Source code in models/ds-gan/src/ds_gan/pipeline_ds_gan.py
85 86 87 88 89 90 91 92 | |
processing_ds_gan ¶
Processor for DS-GAN content-image inputs and layout decoding.
DSGANProcessor ¶
Bases: ProcessorMixin
Prepare PosterLayout RGB/saliency inputs and decode DS-GAN outputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_name
|
DatasetName | str
|
Dataset key. Only PKU PosterLayout is supported. |
pku_posterlayout
|
id2label
|
dict[int | str, str] | None
|
Public semantic labels excluding model |
None
|
image_size
|
tuple[int, int] | list[int]
|
Resize target as |
(350, 240)
|
Examples:
>>> processor = DSGANProcessor()
>>> processor.id2label[0]
'text'
Source code in models/ds-gan/src/ds_gan/processing_ds_gan.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 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 | |
__init__ ¶
__init__(
dataset_name: DatasetName
| str = DatasetName.pku_posterlayout,
id2label: dict[int | str, str] | None = None,
image_size: tuple[int, int] | list[int] = (350, 240),
) -> None
Initialize processor metadata.
Source code in models/ds-gan/src/ds_gan/processing_ds_gan.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | |
__call__ ¶
__call__(
images: DSGANImageInput | Sequence[DSGANImageInput],
*,
saliency: DSGANImageInput
| Sequence[DSGANImageInput]
| None = None,
saliency_pfpnet: DSGANImageInput
| Sequence[DSGANImageInput]
| None = None,
saliency_basnet: DSGANImageInput
| Sequence[DSGANImageInput]
| None = None,
return_tensors: Literal["pt"] = "pt",
) -> BatchEncoding
Encode content images into pixel_values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
images
|
DSGANImageInput | Sequence[DSGANImageInput]
|
RGB image or batch of RGB images. |
required |
saliency
|
DSGANImageInput | Sequence[DSGANImageInput] | None
|
Optional saliency image or batch. If omitted and both saliency maps are given, the maps are merged by pixelwise max. |
None
|
saliency_pfpnet
|
DSGANImageInput | Sequence[DSGANImageInput] | None
|
Optional PFPNet saliency map. |
None
|
saliency_basnet
|
DSGANImageInput | Sequence[DSGANImageInput] | None
|
Optional BASNet saliency map. |
None
|
return_tensors
|
Literal['pt']
|
Tensor framework. Only |
'pt'
|
Returns:
| Type | Description |
|---|---|
BatchEncoding
|
Batch encoding containing |
Source code in models/ds-gan/src/ds_gan/processing_ds_gan.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 | |
decode ¶
decode(
*,
class_probs: Float[Tensor, "batch elements 4"],
bbox: Float[Tensor, "batch elements 4"],
output_type: Literal["dataclass", "dict"] = "dataclass",
scores: Float[Tensor, "batch elements"] | None = None,
intermediates: Mapping[
str, Shaped[Tensor, "..."] | str | bool
]
| None = None,
) -> (
LayoutGenerationOutput
| dict[
str,
Shaped[torch.Tensor, "..."]
| dict[int, str]
| Mapping[
str, Shaped[torch.Tensor, "..."] | str | bool
]
| None,
]
)
Decode raw DS-GAN class probabilities and boxes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
class_probs
|
Float[Tensor, 'batch elements 4']
|
Internal class probabilities shaped |
required |
bbox
|
Float[Tensor, 'batch elements 4']
|
Normalized center |
required |
output_type
|
Literal['dataclass', 'dict']
|
Return format. |
'dataclass'
|
scores
|
Float[Tensor, 'batch elements'] | None
|
Optional per-element class scores. |
None
|
intermediates
|
Mapping[str, Shaped[Tensor, '...'] | str | bool] | None
|
Optional model-specific intermediate tensors. |
None
|
Returns:
| Type | Description |
|---|---|
LayoutGenerationOutput | dict[str, Shaped[Tensor, '...'] | dict[int, str] | Mapping[str, Shaped[Tensor, '...'] | str | bool] | None]
|
Shared layout output with public labels and mask semantics. |
Source code in models/ds-gan/src/ds_gan/processing_ds_gan.py
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 | |
encode_layout ¶
encode_layout(
*,
bbox: Float[Tensor, "batch elements 4"]
| Float[ndarray, "batch elements 4"]
| Sequence[ArrayLikeInput],
labels: Int[Tensor, "batch elements"]
| Int[ndarray, "batch elements"]
| Sequence[ArrayLikeInput],
mask: Bool[Tensor, "batch elements"]
| Bool[ndarray, "batch elements"]
| Sequence[ArrayLikeInput]
| None = None,
box_format: BoxFormat | str = BoxFormat.xywh,
normalized: bool = True,
canvas_size: tuple[int, int] | None = None,
max_elem: int = 32,
) -> dict[str, Shaped[torch.Tensor, "..."]]
Encode public boxes/labels into the internal layout tensor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bbox
|
Float[Tensor, 'batch elements 4'] | Float[ndarray, 'batch elements 4'] | Sequence[ArrayLikeInput]
|
Public boxes. |
required |
labels
|
Int[Tensor, 'batch elements'] | Int[ndarray, 'batch elements'] | Sequence[ArrayLikeInput]
|
Public zero-based semantic labels. |
required |
mask
|
Bool[Tensor, 'batch elements'] | Bool[ndarray, 'batch elements'] | Sequence[ArrayLikeInput] | None
|
Optional valid-element mask. |
None
|
box_format
|
BoxFormat | str
|
Input box format. |
xywh
|
normalized
|
bool
|
Whether the boxes are normalized. |
True
|
canvas_size
|
tuple[int, int] | None
|
Pixel canvas size used when |
None
|
max_elem
|
int
|
Output slot count. |
32
|
Returns:
| Type | Description |
|---|---|
dict[str, Shaped[Tensor, '...']]
|
Dictionary with internal |
Source code in models/ds-gan/src/ds_gan/processing_ds_gan.py
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 | |
pad ¶
pad(
bbox: Float[Tensor, "batch elements 4"],
labels: Int[Tensor, "batch elements"],
mask: Bool[Tensor, "batch elements"],
*,
max_elem: int,
) -> tuple[
Float[torch.Tensor, "batch padded_elements 4"],
Int[torch.Tensor, "batch padded_elements"],
Bool[torch.Tensor, "batch padded_elements"],
]
Pad layout tensors to DS-GAN max_elem slots.
Source code in models/ds-gan/src/ds_gan/processing_ds_gan.py
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 | |
processor_for_dataset ¶
processor_for_dataset(
dataset_name: DatasetName | str,
) -> DSGANProcessor
Create a DS-GAN processor for a supported dataset.
Source code in models/ds-gan/src/ds_gan/processing_ds_gan.py
308 309 310 | |
annotations_from_pku_example ¶
annotations_from_pku_example(
example: Mapping[str, DSGANExampleValue],
*,
max_elem: int = 32,
include_unconnected_underlays: bool = True,
canvas_size: tuple[int, int] | None = None,
vendor_box_fix: bool = False,
) -> dict[
str, Shaped[torch.Tensor, "..."] | tuple[int, int]
]
Convert a PKU PosterLayout dataset row into public layout tensors.
The adapter filters INVALID annotations, converts pixel ltrb boxes
to normalized center xywh, derives canvas size from the image columns,
and applies the reference designSeq.reorder ordering policy. Set
vendor_box_fix to reproduce the reference loader's overlapping-slice
assignment for inverted boxes.
Source code in models/ds-gan/src/ds_gan/processing_ds_gan.py
411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 | |
training ¶
Package-local training components for DS-GAN.
DSGANDataModule ¶
Bases: LightningDataModule
Prepare training and test streams with the reference transforms.
Source code in models/ds-gan/src/ds_gan/training/datamodule.py
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 | |
training_generator
property
¶
training_generator: Generator
Return the shared sampler and layout-initialization RNG stream.
__init__ ¶
__init__(
*,
dataset_name: str = "pku_posterlayout",
cache_dir: str | None = None,
batch_size: int = 128,
test_batch_size: int = 4,
max_elem: int = 32,
num_workers: int = 0,
seed: int = 0,
) -> None
Initialize the approved-source loader settings.
Source code in models/ds-gan/src/ds_gan/training/datamodule.py
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 | |
setup ¶
setup(stage: str | None = None) -> None
Open cached source rows for fitting or evaluation.
Source code in models/ds-gan/src/ds_gan/training/datamodule.py
66 67 68 69 | |
train_dataloader ¶
train_dataloader() -> DataLoader[
dict[str, Shaped[torch.Tensor, "..."]]
]
Return the reference-compatible shuffled training stream.
Source code in models/ds-gan/src/ds_gan/training/datamodule.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |
test_dataloader ¶
test_dataloader() -> DataLoader[
dict[str, Shaped[torch.Tensor, "..."]]
]
Return the complete unshuffled test stream.
Source code in models/ds-gan/src/ds_gan/training/datamodule.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | |
DSGANDataset ¶
Bases: Dataset[dict[str, Shaped[Tensor, '...']]]
Lazy DS-GAN dataset using the approved source and reference preprocessing.
Source code in models/ds-gan/src/ds_gan/training/dataset.py
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 | |
__init__ ¶
__init__(
rows: Dataset,
*,
split: str,
processor: DSGANProcessor | None = None,
max_elem: int = 32,
) -> None
Initialize the source bridge.
Source code in models/ds-gan/src/ds_gan/training/dataset.py
81 82 83 84 85 86 87 88 89 90 91 92 93 | |
__len__ ¶
__len__() -> int
Return the number of source rows.
Source code in models/ds-gan/src/ds_gan/training/dataset.py
95 96 97 | |
__getitem__ ¶
__getitem__(
index: int,
) -> dict[str, Shaped[torch.Tensor, "..."]]
Convert one source row into model inputs and padded labels.
Source code in models/ds-gan/src/ds_gan/training/dataset.py
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 | |
DSGANTrainingModule ¶
Bases: LightningModule
Train generator and discriminator with the reference update ordering.
Source code in models/ds-gan/src/ds_gan/training/lightning_module.py
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 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 389 390 391 392 393 394 395 396 397 398 399 400 401 402 | |
__init__ ¶
__init__(
*,
config: TrainingConfigInput,
discriminator_config: TrainingConfigInput | None = None,
generator: DSGANModel | None = None,
discriminator: DSGANDiscriminator | None = None,
generator_backbone_weights: str | None = None,
discriminator_backbone_weights: str | None = None,
generator_learning_rate: float = 0.0001,
discriminator_learning_rate: float = 0.001,
generator_backbone_learning_rate: float = 1e-05,
discriminator_backbone_learning_rate: float = 0.0001,
adversarial_weight_ramp_steps: int = 100,
scheduler_gamma: float = 0.8,
scheduler_generator_milestones: tuple[int, ...] = (
0,
50,
100,
150,
200,
250,
),
scheduler_discriminator_milestones: tuple[int, ...] = (
0,
25,
50,
75,
100,
125,
150,
175,
200,
225,
250,
275,
),
seed: int = 0,
) -> None
Initialize the two-network DS-GAN training state.
Source code in models/ds-gan/src/ds_gan/training/lightning_module.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 | |
forward ¶
forward(
pixel_values: Float[Tensor, "batch 4 height width"],
initial_layout: Float[Tensor, "batch elements 2 4"],
) -> DSGANModelOutput
Run the package generator.
Source code in models/ds-gan/src/ds_gan/training/lightning_module.py
175 176 177 178 179 180 181 182 183 184 185 | |
on_fit_start ¶
on_fit_start() -> None
Share the data module's seeded stream with layout initialization.
Source code in models/ds-gan/src/ds_gan/training/lightning_module.py
187 188 189 190 191 192 193 194 195 | |
configure_optimizers ¶
configure_optimizers() -> OptimizerLRScheduler
Return Adam optimizers and reference MultiStepLR schedulers.
Source code in models/ds-gan/src/ds_gan/training/lightning_module.py
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 | |
training_step ¶
training_step(
batch: Mapping[str, Shaped[Tensor, "..."]],
batch_idx: int,
) -> Float[torch.Tensor, ""]
Run one manually optimized generator-then-discriminator update.
Source code in models/ds-gan/src/ds_gan/training/lightning_module.py
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 | |
step_with_optimizers ¶
step_with_optimizers(
batch: Mapping[str, Shaped[Tensor, "..."]],
optimizer_g: Optimizer,
optimizer_d: Optimizer,
*,
initial_layout: Float[Tensor, "batch elements 2 4"]
| None = None,
numpy_rng: RandomState | None = None,
torch_generator: Generator | None = None,
epoch: int = 1,
) -> Float[torch.Tensor, ""]
Apply one exact G-then-D update and record its comparison trace.
Source code in models/ds-gan/src/ds_gan/training/lightning_module.py
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 | |
on_train_epoch_end ¶
on_train_epoch_end() -> None
Advance both epoch schedulers after all manual updates in an epoch.
Source code in models/ds-gan/src/ds_gan/training/lightning_module.py
352 353 354 355 356 357 358 359 | |
configure_gradient_clipping ¶
configure_gradient_clipping(
optimizer: Optimizer,
gradient_clip_val: float | None = None,
gradient_clip_algorithm: str | None = None,
) -> None
Delegate the Trainer's clipping policy for the active optimizer.
Source code in models/ds-gan/src/ds_gan/training/lightning_module.py
391 392 393 394 395 396 397 398 399 400 401 402 | |
DSGANSetCriterion ¶
Bases: Module
Compute the reference class, box, and generalized-IoU losses.
Source code in models/ds-gan/src/ds_gan/training/losses.py
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 | |
__init__ ¶
__init__(eos_weight: float = 0.1) -> None
Initialize the fixed reference loss weights.
Source code in models/ds-gan/src/ds_gan/training/losses.py
113 114 115 116 117 | |
forward ¶
forward(
pred_logits: Float[Tensor, "batch elements 4"],
pred_boxes: Float[Tensor, "batch elements 4"],
targets: Sequence[
dict[str, Shaped[Tensor, "elements ..."]]
],
) -> dict[str, Float[torch.Tensor, ""]]
Return the three weighted reconstruction components.
Source code in models/ds-gan/src/ds_gan/training/losses.py
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 | |
HungarianMatcher ¶
Bases: Module
Match predicted layout slots to target elements.
Source code in models/ds-gan/src/ds_gan/training/losses.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 | |
__init__ ¶
__init__(
cost_class: float = 2.0,
cost_bbox: float = 5.0,
cost_giou: float = 2.0,
) -> None
Initialize weighted matching costs.
Source code in models/ds-gan/src/ds_gan/training/losses.py
55 56 57 58 59 60 61 62 63 64 65 | |
forward ¶
forward(
outputs: dict[
str, Float[Tensor, "batch elements channels"]
],
targets: Sequence[
dict[str, Shaped[Tensor, "elements ..."]]
],
) -> list[
tuple[
Int[torch.Tensor, "matched"],
Int[torch.Tensor, "matched"],
]
]
Return per-example Hungarian assignments.
Source code in models/ds-gan/src/ds_gan/training/losses.py
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 | |
build_bridge_manifest ¶
build_bridge_manifest(
*,
source_revision: str,
train_count: int,
test_count: int,
source_hashes: Mapping[str, str],
source_fields: Mapping[str, str] | None = None,
available_fields: Sequence[str] | None = None,
) -> dict[str, ManifestValue]
Build a hash-manifested record of the approved-source bridge.
Source code in models/ds-gan/src/ds_gan/training/dataset.py
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 | |
bridge_example ¶
bridge_example(
example: Mapping[str, DatasetValue], *, split: str
) -> dict[str, DatasetValue]
Map one approved-source row to the fields consumed by the reference loader.
Source code in models/ds-gan/src/ds_gan/training/dataset.py
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 | |
explicit_setup_seed ¶
explicit_setup_seed(
seed: int, *, deterministic: bool = True
) -> None
Set every random source used by the reference training recipe.
Source code in models/ds-gan/src/ds_gan/training/rng.py
29 30 31 32 33 34 35 36 37 38 | |
vendor_random_initial_layout ¶
vendor_random_initial_layout(
batch_size: int,
max_elem: int,
*,
numpy_rng: NumpyChoiceSource,
torch_generator: Generator | None,
device: device | str = "cpu",
) -> Float[torch.Tensor, "batch elements 2 4"]
Reproduce the reference class and box draws with explicit RNG objects.
Source code in models/ds-gan/src/ds_gan/training/rng.py
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 | |
datamodule ¶
Lightning data module for the approved PKU PosterLayout source.
DSGANDataModule ¶
Bases: LightningDataModule
Prepare training and test streams with the reference transforms.
Source code in models/ds-gan/src/ds_gan/training/datamodule.py
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 | |
training_generator
property
¶
training_generator: Generator
Return the shared sampler and layout-initialization RNG stream.
__init__ ¶
__init__(
*,
dataset_name: str = "pku_posterlayout",
cache_dir: str | None = None,
batch_size: int = 128,
test_batch_size: int = 4,
max_elem: int = 32,
num_workers: int = 0,
seed: int = 0,
) -> None
Initialize the approved-source loader settings.
Source code in models/ds-gan/src/ds_gan/training/datamodule.py
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 | |
setup ¶
setup(stage: str | None = None) -> None
Open cached source rows for fitting or evaluation.
Source code in models/ds-gan/src/ds_gan/training/datamodule.py
66 67 68 69 | |
train_dataloader ¶
train_dataloader() -> DataLoader[
dict[str, Shaped[torch.Tensor, "..."]]
]
Return the reference-compatible shuffled training stream.
Source code in models/ds-gan/src/ds_gan/training/datamodule.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |
test_dataloader ¶
test_dataloader() -> DataLoader[
dict[str, Shaped[torch.Tensor, "..."]]
]
Return the complete unshuffled test stream.
Source code in models/ds-gan/src/ds_gan/training/datamodule.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | |
dataset ¶
Approved-source to reference-layout data bridge for DS-GAN.
DSGANDataset ¶
Bases: Dataset[dict[str, Shaped[Tensor, '...']]]
Lazy DS-GAN dataset using the approved source and reference preprocessing.
Source code in models/ds-gan/src/ds_gan/training/dataset.py
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 | |
__init__ ¶
__init__(
rows: Dataset,
*,
split: str,
processor: DSGANProcessor | None = None,
max_elem: int = 32,
) -> None
Initialize the source bridge.
Source code in models/ds-gan/src/ds_gan/training/dataset.py
81 82 83 84 85 86 87 88 89 90 91 92 93 | |
__len__ ¶
__len__() -> int
Return the number of source rows.
Source code in models/ds-gan/src/ds_gan/training/dataset.py
95 96 97 | |
__getitem__ ¶
__getitem__(
index: int,
) -> dict[str, Shaped[torch.Tensor, "..."]]
Convert one source row into model inputs and padded labels.
Source code in models/ds-gan/src/ds_gan/training/dataset.py
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 | |
bridge_example ¶
bridge_example(
example: Mapping[str, DatasetValue], *, split: str
) -> dict[str, DatasetValue]
Map one approved-source row to the fields consumed by the reference loader.
Source code in models/ds-gan/src/ds_gan/training/dataset.py
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 | |
build_bridge_manifest ¶
build_bridge_manifest(
*,
source_revision: str,
train_count: int,
test_count: int,
source_hashes: Mapping[str, str],
source_fields: Mapping[str, str] | None = None,
available_fields: Sequence[str] | None = None,
) -> dict[str, ManifestValue]
Build a hash-manifested record of the approved-source bridge.
Source code in models/ds-gan/src/ds_gan/training/dataset.py
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 | |
hash_file ¶
hash_file(path: Path) -> str
Hash a source metadata or arrow artifact in streaming chunks.
Source code in models/ds-gan/src/ds_gan/training/dataset.py
209 210 211 212 213 214 215 216 | |
load_cached_dataset ¶
load_cached_dataset(
cache_dir: str | Path | None = None,
) -> DatasetDict
Load the approved source from a standard datasets cache without downloading.
Source code in models/ds-gan/src/ds_gan/training/dataset.py
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | |
load_cached_test ¶
load_cached_test(
cache_dir: str | Path | None = None,
) -> Dataset
Load only the approved source TEST Arrow stream from cache.
Source code in models/ds-gan/src/ds_gan/training/dataset.py
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 | |
manifest_from_cached_dataset ¶
manifest_from_cached_dataset(
cache_dir: str | Path | None = None,
) -> dict[str, ManifestValue]
Create a bridge manifest from cached source metadata and Arrow hashes.
Source code in models/ds-gan/src/ds_gan/training/dataset.py
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 | |
discriminator ¶
Package-local DS-GAN discriminator and layout ordering.
DSGANDiscriminator ¶
Bases: Module
Package-local discriminator matching the original DS-GAN topology.
Source code in models/ds-gan/src/ds_gan/training/discriminator.py
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
__init__ ¶
__init__(
config: DSGANConfig,
*,
backbone_weights: str | Path | None = None,
) -> None
Initialize the discriminator from a ResNet-FPN and CNN-LSTM config.
Source code in models/ds-gan/src/ds_gan/training/discriminator.py
173 174 175 176 177 178 179 180 | |
forward ¶
forward(
pixel_values: Float[Tensor, "batch 4 height width"],
layout: Float[Tensor, "batch elements 2 4"],
) -> Float[torch.Tensor, "batch 1"]
Score a layout after hard class selection and ordering.
Source code in models/ds-gan/src/ds_gan/training/discriminator.py
182 183 184 185 186 187 188 189 190 191 | |
lightning_module ¶
Lightning training module matching the released DS-GAN recipe.
DSGANConfigArguments ¶
Bases: TypedDict
JSON-compatible constructor arguments accepted by DSGANConfig.
Source code in models/ds-gan/src/ds_gan/training/lightning_module.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 62 63 64 | |
DSGANTrainingModule ¶
Bases: LightningModule
Train generator and discriminator with the reference update ordering.
Source code in models/ds-gan/src/ds_gan/training/lightning_module.py
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 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 389 390 391 392 393 394 395 396 397 398 399 400 401 402 | |
__init__ ¶
__init__(
*,
config: TrainingConfigInput,
discriminator_config: TrainingConfigInput | None = None,
generator: DSGANModel | None = None,
discriminator: DSGANDiscriminator | None = None,
generator_backbone_weights: str | None = None,
discriminator_backbone_weights: str | None = None,
generator_learning_rate: float = 0.0001,
discriminator_learning_rate: float = 0.001,
generator_backbone_learning_rate: float = 1e-05,
discriminator_backbone_learning_rate: float = 0.0001,
adversarial_weight_ramp_steps: int = 100,
scheduler_gamma: float = 0.8,
scheduler_generator_milestones: tuple[int, ...] = (
0,
50,
100,
150,
200,
250,
),
scheduler_discriminator_milestones: tuple[int, ...] = (
0,
25,
50,
75,
100,
125,
150,
175,
200,
225,
250,
275,
),
seed: int = 0,
) -> None
Initialize the two-network DS-GAN training state.
Source code in models/ds-gan/src/ds_gan/training/lightning_module.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 | |
forward ¶
forward(
pixel_values: Float[Tensor, "batch 4 height width"],
initial_layout: Float[Tensor, "batch elements 2 4"],
) -> DSGANModelOutput
Run the package generator.
Source code in models/ds-gan/src/ds_gan/training/lightning_module.py
175 176 177 178 179 180 181 182 183 184 185 | |
on_fit_start ¶
on_fit_start() -> None
Share the data module's seeded stream with layout initialization.
Source code in models/ds-gan/src/ds_gan/training/lightning_module.py
187 188 189 190 191 192 193 194 195 | |
configure_optimizers ¶
configure_optimizers() -> OptimizerLRScheduler
Return Adam optimizers and reference MultiStepLR schedulers.
Source code in models/ds-gan/src/ds_gan/training/lightning_module.py
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 | |
training_step ¶
training_step(
batch: Mapping[str, Shaped[Tensor, "..."]],
batch_idx: int,
) -> Float[torch.Tensor, ""]
Run one manually optimized generator-then-discriminator update.
Source code in models/ds-gan/src/ds_gan/training/lightning_module.py
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 | |
step_with_optimizers ¶
step_with_optimizers(
batch: Mapping[str, Shaped[Tensor, "..."]],
optimizer_g: Optimizer,
optimizer_d: Optimizer,
*,
initial_layout: Float[Tensor, "batch elements 2 4"]
| None = None,
numpy_rng: RandomState | None = None,
torch_generator: Generator | None = None,
epoch: int = 1,
) -> Float[torch.Tensor, ""]
Apply one exact G-then-D update and record its comparison trace.
Source code in models/ds-gan/src/ds_gan/training/lightning_module.py
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 | |
on_train_epoch_end ¶
on_train_epoch_end() -> None
Advance both epoch schedulers after all manual updates in an epoch.
Source code in models/ds-gan/src/ds_gan/training/lightning_module.py
352 353 354 355 356 357 358 359 | |
configure_gradient_clipping ¶
configure_gradient_clipping(
optimizer: Optimizer,
gradient_clip_val: float | None = None,
gradient_clip_algorithm: str | None = None,
) -> None
Delegate the Trainer's clipping policy for the active optimizer.
Source code in models/ds-gan/src/ds_gan/training/lightning_module.py
391 392 393 394 395 396 397 398 399 400 401 402 | |
losses ¶
DS-GAN reconstruction losses matching the reference criterion.
HungarianMatcher ¶
Bases: Module
Match predicted layout slots to target elements.
Source code in models/ds-gan/src/ds_gan/training/losses.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 | |
__init__ ¶
__init__(
cost_class: float = 2.0,
cost_bbox: float = 5.0,
cost_giou: float = 2.0,
) -> None
Initialize weighted matching costs.
Source code in models/ds-gan/src/ds_gan/training/losses.py
55 56 57 58 59 60 61 62 63 64 65 | |
forward ¶
forward(
outputs: dict[
str, Float[Tensor, "batch elements channels"]
],
targets: Sequence[
dict[str, Shaped[Tensor, "elements ..."]]
],
) -> list[
tuple[
Int[torch.Tensor, "matched"],
Int[torch.Tensor, "matched"],
]
]
Return per-example Hungarian assignments.
Source code in models/ds-gan/src/ds_gan/training/losses.py
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 | |
DSGANSetCriterion ¶
Bases: Module
Compute the reference class, box, and generalized-IoU losses.
Source code in models/ds-gan/src/ds_gan/training/losses.py
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 | |
__init__ ¶
__init__(eos_weight: float = 0.1) -> None
Initialize the fixed reference loss weights.
Source code in models/ds-gan/src/ds_gan/training/losses.py
113 114 115 116 117 | |
forward ¶
forward(
pred_logits: Float[Tensor, "batch elements 4"],
pred_boxes: Float[Tensor, "batch elements 4"],
targets: Sequence[
dict[str, Shaped[Tensor, "elements ..."]]
],
) -> dict[str, Float[torch.Tensor, ""]]
Return the three weighted reconstruction components.
Source code in models/ds-gan/src/ds_gan/training/losses.py
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 | |
rng ¶
Deterministic random-state helpers for DS-GAN training.
NumpyChoiceSource ¶
Bases: Protocol
NumPy random source exposing the legacy weighted choice operation.
Source code in models/ds-gan/src/ds_gan/training/rng.py
16 17 18 19 20 21 22 23 24 25 26 | |
choice ¶
choice(
a: int,
*,
size: tuple[int, int, int],
p: Float[ndarray, "4"],
) -> Int[np.ndarray, "batch elements 1"]
Draw weighted class ids.
Source code in models/ds-gan/src/ds_gan/training/rng.py
19 20 21 22 23 24 25 26 | |
explicit_setup_seed ¶
explicit_setup_seed(
seed: int, *, deterministic: bool = True
) -> None
Set every random source used by the reference training recipe.
Source code in models/ds-gan/src/ds_gan/training/rng.py
29 30 31 32 33 34 35 36 37 38 | |
vendor_random_initial_layout ¶
vendor_random_initial_layout(
batch_size: int,
max_elem: int,
*,
numpy_rng: NumpyChoiceSource,
torch_generator: Generator | None,
device: device | str = "cpu",
) -> Float[torch.Tensor, "batch elements 2 4"]
Reproduce the reference class and box draws with explicit RNG objects.
Source code in models/ds-gan/src/ds_gan/training/rng.py
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 | |