Ltnet
Transformers-style LT-Net package.
LTNetConfig ¶
Bases: PretrainedConfig
Architecture and processor metadata for LT-Net checkpoints.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_name
|
str
|
Dataset slug for the converted checkpoint. |
'coco'
|
vocab_size
|
int
|
Mixed special/object/predicate token vocabulary size. |
206
|
obj_classes_size
|
int
|
Object-id embedding/classifier vocabulary size. |
155
|
hidden_size
|
int
|
Transformer hidden dimension. |
256
|
num_hidden_layers
|
int
|
Number of relation encoder layers. |
4
|
num_attention_heads
|
int
|
Number of relation encoder attention heads. |
4
|
dropout
|
float
|
Dropout used by embeddings, encoder, and bbox heads. |
0.1
|
enable_noise
|
bool
|
Whether the original config enabled relation noise. |
False
|
noise_size
|
int
|
Original relation-noise size. |
64
|
decoder_head_type
|
DecoderHeadType | str
|
|
gmm
|
decoder_box_loss
|
BoxLossType | str
|
|
pdf
|
decoder_schedule_sample
|
bool
|
Whether training used scheduled sampling. |
False
|
decoder_two_path
|
bool
|
Whether the original config enabled two-path decoding. |
False
|
decoder_global_feature
|
bool
|
Whether to concatenate max-pooled global features. |
True
|
decoder_greedy
|
bool
|
Whether inference uses GMM means instead of sampling. |
True
|
xy_temperature
|
float
|
GMM mixture temperature for center coordinates. |
1.0
|
wh_temperature
|
float
|
GMM mixture temperature for box size. |
1.0
|
refine
|
bool
|
Whether a refinement head is present. |
False
|
refine_head_type
|
DecoderHeadType | str
|
Refinement bbox head type. |
linear
|
refine_box_loss
|
BoxLossType | str
|
Refinement objective family. |
reg
|
refine_x_softmax
|
bool
|
Whether the decoder records XY PDF scores for refine. |
True
|
max_sequence_length
|
int
|
Processor/model sequence length. |
128
|
id2label
|
Mapping[int, str] | Mapping[str, str] | None
|
Public object label mapping. |
None
|
relation_id2label
|
Mapping[int, str] | Mapping[str, str] | None
|
Public relation label mapping. |
None
|
model_type
|
str | None
|
Ignored compatibility field from serialized configs. |
None
|
transformers_version
|
str | None
|
Ignored compatibility field. |
None
|
kwargs
|
str | int | float | bool | None
|
Additional |
{}
|
Examples:
>>> config = LTNetConfig(hidden_size=32, num_attention_heads=4)
>>> config.model_type
'ltnet'
Source code in models/ltnet/src/ltnet/configuration_ltnet.py
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 | |
__init__ ¶
__init__(
*,
dataset_name: str = "coco",
vocab_size: int = 206,
obj_classes_size: int = 155,
hidden_size: int = 256,
num_hidden_layers: int = 4,
num_attention_heads: int = 4,
dropout: float = 0.1,
enable_noise: bool = False,
noise_size: int = 64,
decoder_head_type: DecoderHeadType
| str = DecoderHeadType.gmm,
decoder_box_loss: BoxLossType | str = BoxLossType.pdf,
decoder_schedule_sample: bool = False,
decoder_two_path: bool = False,
decoder_global_feature: bool = True,
decoder_greedy: bool = True,
xy_temperature: float = 1.0,
wh_temperature: float = 1.0,
refine: bool = False,
refine_head_type: DecoderHeadType
| str = DecoderHeadType.linear,
refine_box_loss: BoxLossType | str = BoxLossType.reg,
refine_x_softmax: bool = True,
max_sequence_length: int = 128,
id2label: Mapping[int, str]
| Mapping[str, str]
| None = None,
relation_id2label: Mapping[int, str]
| Mapping[str, str]
| None = None,
bos_token_id: int = 1,
eos_token_id: int = 2,
pad_token_id: int = 0,
mask_token_id: int = 3,
model_type: str | None = None,
transformers_version: str | None = None,
**kwargs: str | int | float | bool | None,
) -> None
Initialize LT-Net architecture and metadata fields.
Source code in models/ltnet/src/ltnet/configuration_ltnet.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 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | |
LTNetForLayoutGeneration ¶
Bases: PreTrainedModel
Transformers PreTrainedModel for LT-Net relation-to-layout inference.
Source code in models/ltnet/src/ltnet/modeling_ltnet.py
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 | |
__init__ ¶
__init__(config: LTNetConfig) -> None
Initialize relation encoder and bbox head.
Source code in models/ltnet/src/ltnet/modeling_ltnet.py
61 62 63 64 65 66 | |
forward ¶
forward(
input_token: Int[Tensor, "batch sequence"],
input_obj_id: Int[Tensor, "batch sequence"],
segment_label: Int[Tensor, "batch sequence"],
token_type: Int[Tensor, "batch sequence"],
src_mask: Bool[Tensor, "batch 1 sequence"]
| None = None,
global_mask: Bool[Tensor, "batch sequence"]
| None = None,
bbox: Float[Tensor, "batch sequence 4"] | None = None,
bbox_mask: Bool[Tensor, "batch sequence"] | None = None,
inference: bool = False,
generator: Generator | None = None,
output_hidden_states: bool = False,
return_dict: bool = True,
) -> (
LTNetModelOutput
| tuple[
Float[torch.Tensor, "batch sequence feature"]
| None,
...,
]
)
Run LT-Net relation encoding and bbox prediction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_token
|
Int[Tensor, 'batch sequence']
|
Mixed object/predicate token ids. |
required |
input_obj_id
|
Int[Tensor, 'batch sequence']
|
Stable object ids for object-token positions. |
required |
segment_label
|
Int[Tensor, 'batch sequence']
|
Relation segment ids. |
required |
token_type
|
Int[Tensor, 'batch sequence']
|
Token type ids |
required |
src_mask
|
Bool[Tensor, 'batch 1 sequence'] | None
|
Valid-token mask shaped |
None
|
global_mask
|
Bool[Tensor, 'batch sequence'] | None
|
Optional reference global-feature mask. |
None
|
bbox
|
Float[Tensor, 'batch sequence 4'] | None
|
Optional teacher-forced boxes for training/parity paths. |
None
|
bbox_mask
|
Bool[Tensor, 'batch sequence'] | None
|
Optional box validity mask, reserved for parity paths. |
None
|
inference
|
bool
|
Compatibility flag; greedy decoding is pipeline-owned. |
False
|
generator
|
Generator | None
|
Optional PyTorch generator for stochastic GMM sampling. |
None
|
output_hidden_states
|
bool
|
Whether to include encoder hidden states. |
False
|
return_dict
|
bool
|
Whether to return a |
True
|
Returns:
| Type | Description |
|---|---|
LTNetModelOutput | tuple[Float[Tensor, 'batch sequence feature'] | None, ...]
|
Raw LT-Net output dataclass or tuple. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If required tensor shapes are invalid. |
Source code in models/ltnet/src/ltnet/modeling_ltnet.py
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 | |
LTNetModelOutput
dataclass
¶
Bases: ModelOutput
Raw LT-Net model outputs.
Attributes:
| Name | Type | Description |
|---|---|---|
vocab_logits |
Float[Tensor, 'batch sequence vocab'] | None
|
Mixed token vocabulary logits. |
obj_id_logits |
Float[Tensor, 'batch sequence object_classes'] | None
|
Object-id classifier logits. |
token_type_logits |
Float[Tensor, 'batch sequence token_types'] | None
|
Token-type classifier logits. |
coarse_box |
Float[Tensor, 'batch sequence 4'] | None
|
Coarse normalized center |
coarse_gmm |
Float[Tensor, 'batch sequence gmm_params'] | None
|
Optional coarse GMM parameters. |
refine_box |
Float[Tensor, 'batch sequence 4'] | None
|
Optional refined normalized center |
refine_gmm |
Float[Tensor, 'batch sequence gmm_params'] | None
|
Optional refinement GMM parameters. |
hidden_states |
Float[Tensor, 'batch sequence hidden'] | None
|
Optional encoder hidden states. |
Examples:
>>> import torch
>>> out = LTNetModelOutput(
... vocab_logits=torch.zeros(1, 2, 3),
... obj_id_logits=torch.zeros(1, 2, 4),
... token_type_logits=torch.zeros(1, 2, 4),
... coarse_box=torch.zeros(1, 2, 4),
... )
>>> out.coarse_box.shape
torch.Size([1, 2, 4])
Source code in models/ltnet/src/ltnet/modeling_ltnet.py
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 | |
LTNetPipeline ¶
Bases: LayoutGenerationPipeline
Compose an LT-Net model and processor for scene-graph layout inference.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
LTNetForLayoutGeneration
|
Converted LT-Net model. |
required |
processor
|
LTNetProcessor
|
Matching scene-graph processor/tokenizer. |
required |
config
|
LTNetConfig | None
|
Optional root pipeline config. Defaults to |
None
|
Examples:
>>> processor = LTNetProcessor.from_config()
>>> config = LTNetConfig(
... vocab_size=processor.tokenizer.vocab_size,
... hidden_size=32,
... num_hidden_layers=1,
... num_attention_heads=4,
... )
>>> pipe = LTNetPipeline(
... model=LTNetForLayoutGeneration(config),
... processor=processor,
... )
>>> pipe.config.model_type
'ltnet'
Source code in models/ltnet/src/ltnet/pipeline_ltnet.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 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 | |
__init__ ¶
__init__(
model: LTNetForLayoutGeneration,
processor: LTNetProcessor,
config: LTNetConfig | None = None,
) -> None
Initialize the pipeline with model and processor components.
Source code in models/ltnet/src/ltnet/pipeline_ltnet.py
113 114 115 116 117 118 119 120 121 122 123 | |
__call__ ¶
__call__(
*,
batch_size: int = 1,
seed: int | None = None,
generator: Generator | None = None,
condition_type: ConditionType
| str = ConditionType.relation,
labels: Int[Tensor, "batch elements"]
| Sequence[int]
| None = None,
bbox: Float[Tensor, "batch elements 4"]
| Sequence[Sequence[float]]
| None = None,
mask: Bool[Tensor, "batch elements"]
| Sequence[bool]
| 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 = "dataclass",
return_intermediates: bool = False,
scene_graph: SceneGraphInput
| SceneGraphMapping
| None = None,
objects: Sequence[LayoutObject] | None = None,
relations: Sequence[LayoutRelation] | None = None,
) -> (
LayoutGenerationOutput
| dict[
str,
Float[torch.Tensor, "..."]
| Int[torch.Tensor, "..."]
| Bool[torch.Tensor, "..."]
| dict[int, str]
| dict[str, Float[torch.Tensor, "..."] | None],
]
)
Generate layouts from a public scene graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch_size
|
int
|
Number of layouts to generate from the same graph. |
1
|
seed
|
int | None
|
Convenience seed used only when |
None
|
generator
|
Generator | None
|
Optional PyTorch generator; takes precedence over seed. |
None
|
condition_type
|
ConditionType | str
|
Must normalize to |
relation
|
labels
|
Int[Tensor, 'batch elements'] | Sequence[int] | None
|
Reserved v1 interface input; LT-Net uses |
None
|
bbox
|
Float[Tensor, 'batch elements 4'] | Sequence[Sequence[float]] | None
|
Reserved v1 box constraint input. |
None
|
mask
|
Bool[Tensor, 'batch elements'] | Sequence[bool] | None
|
Reserved v1 validity-mask input. |
None
|
num_elements
|
int | list[int] | Int[Tensor, 'batch'] | None
|
Reserved v1 element-count input. |
None
|
box_format
|
BoxFormat | str
|
Output box format; LT-Net returns normalized |
xywh
|
normalized
|
bool
|
Whether output boxes should be normalized. |
True
|
canvas_size
|
tuple[int, int] | None
|
Reserved denormalization canvas size. |
None
|
num_inference_steps
|
int | None
|
Reserved v1 step count. |
None
|
output_type
|
OutputType
|
Return dataclass or dict. |
'dataclass'
|
return_intermediates
|
bool
|
Include raw logits/boxes in intermediates. |
False
|
scene_graph
|
SceneGraphInput | SceneGraphMapping | None
|
Public relation payload. |
None
|
objects
|
Sequence[LayoutObject] | None
|
Object-node shorthand when |
None
|
relations
|
Sequence[LayoutRelation] | None
|
Relation-edge shorthand when |
None
|
Returns:
| Type | Description |
|---|---|
LayoutGenerationOutput | dict[str, Float[Tensor, '...'] | Int[Tensor, '...'] | Bool[Tensor, '...'] | dict[int, str] | dict[str, Float[Tensor, '...'] | None]]
|
Layout generation output dataclass or dict. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the condition or graph payload is unsupported. |
Source code in models/ltnet/src/ltnet/pipeline_ltnet.py
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 | |
LTNetProcessor ¶
Bases: ProcessorMixin
Normalize scene graphs, tokenize LT-Net inputs, and postprocess boxes.
Source code in models/ltnet/src/ltnet/processing_ltnet.py
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 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 403 404 405 406 407 408 409 410 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 | |
__init__ ¶
__init__(
tokenizer: LTNetRelationTokenizer,
dataset_name: str = "coco",
max_sequence_length: int = 128,
id2label: Mapping[int, str]
| Mapping[str, str]
| None = None,
relation_id2label: Mapping[int, str]
| Mapping[str, str]
| None = None,
object_reduce: Literal[
"first", "last", "mean"
] = "first",
) -> None
Initialize processor label maps and tokenizer component.
Source code in models/ltnet/src/ltnet/processing_ltnet.py
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 | |
from_config
classmethod
¶
from_config(
*,
dataset_name: str = "coco",
max_sequence_length: int = 128,
id2label: Mapping[int, str]
| Mapping[str, str]
| None = None,
relation_id2label: Mapping[int, str]
| Mapping[str, str]
| None = None,
) -> "LTNetProcessor"
Construct a processor and tokenizer without external files.
Returns:
| Type | Description |
|---|---|
'LTNetProcessor'
|
Processor with synthetic vocabulary derived from the label maps. |
Examples:
>>> processor = LTNetProcessor.from_config()
>>> processor.tokenizer.cls_token_id
1
Source code in models/ltnet/src/ltnet/processing_ltnet.py
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 | |
normalize_condition_type ¶
normalize_condition_type(
condition_type: ConditionType | str,
) -> ConditionType
Normalize and validate the LT-Net public condition type.
Source code in models/ltnet/src/ltnet/processing_ltnet.py
140 141 142 143 144 145 146 147 148 149 150 151 | |
__call__ ¶
__call__(
*,
scene_graph: SceneGraphInput
| SceneGraphMapping
| None = None,
objects: Sequence[LayoutObject] | None = None,
relations: Sequence[LayoutRelation] | None = None,
batch_size: int = 1,
condition_type: ConditionType
| str = ConditionType.relation,
return_tensors: Literal["pt", "np"] = "pt",
max_sequence_length: int | None = None,
) -> BatchEncoding
Build LT-Net model tensors from public scene-graph inputs.
Source code in models/ltnet/src/ltnet/processing_ltnet.py
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 | |
post_process_layout_generation ¶
post_process_layout_generation(
model_outputs: LTNetModelOutput,
*,
input_token: Int[Tensor, "batch sequence"]
| None = None,
input_obj_id: Int[Tensor, "batch sequence"],
token_type: Int[Tensor, "batch sequence"],
box_format: BoxFormat | str = BoxFormat.xywh,
normalized: bool = True,
canvas_size: tuple[int, int] | None = None,
output_type: OutputType = "dataclass",
return_intermediates: bool = False,
) -> (
LayoutGenerationOutput
| dict[
str,
Float[torch.Tensor, "..."]
| Int[torch.Tensor, "..."]
| Bool[torch.Tensor, "..."]
| dict[int, str]
| dict[str, Float[torch.Tensor, "..."] | None],
]
)
Convert raw token-level boxes into public object-level layouts.
Source code in models/ltnet/src/ltnet/processing_ltnet.py
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 403 404 405 406 407 408 409 410 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 | |
save_pretrained ¶
save_pretrained(
save_directory: str | PathLike[str],
push_to_hub: bool = False,
**kwargs: str | int | float | bool | None,
) -> tuple[str, ...]
Save processor metadata and tokenizer files.
Source code in models/ltnet/src/ltnet/processing_ltnet.py
441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 | |
LayoutObject
dataclass
¶
One scene-graph object node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
int | str
|
Stable object id within a scene graph. |
required |
label
|
int | str
|
Dataset-local object label id or label string. |
required |
bbox
|
tuple[float, float, float, float] | None
|
Optional normalized center |
None
|
Examples:
>>> LayoutObject(id="person-1", label="person").id
'person-1'
Source code in models/ltnet/src/ltnet/relation_schema.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | |
LayoutRelation
dataclass
¶
One directed scene-graph edge.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subject
|
int | str
|
Source object id. |
required |
predicate
|
int | str
|
Relation id or label. |
required |
object
|
int | str
|
Target object id. |
required |
bbox_delta
|
tuple[float, float, float, float] | None
|
Optional relation geometry. |
None
|
score
|
float | None
|
Optional edge confidence. |
None
|
Examples:
>>> LayoutRelation("a", "left of", "b").predicate
'left of'
Source code in models/ltnet/src/ltnet/relation_schema.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | |
SceneGraphInput
dataclass
¶
Normalized scene graph payload.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
objects
|
tuple[LayoutObject, ...]
|
Scene-graph object nodes. |
required |
relations
|
tuple[LayoutRelation, ...]
|
Scene-graph relation edges. |
required |
id2label
|
dict[int, str] | None
|
Optional public object label mapping. |
None
|
relation_id2label
|
dict[int, str] | None
|
Optional relation label mapping. |
None
|
Examples:
>>> graph = SceneGraphInput(
... objects=(LayoutObject("a", "person"), LayoutObject("b", "table")),
... relations=(LayoutRelation("a", "left of", "b"),),
... )
>>> len(graph.relations)
1
Source code in models/ltnet/src/ltnet/relation_schema.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | |
LTNetRelationTokenizer ¶
Bases: WhitespaceTokenizerMixin, PreTrainedTokenizer
Discrete scene-graph tokenizer saved as a standard HF tokenizer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vocab_file
|
str | None
|
Optional path to |
None
|
tokens
|
list[str] | None
|
Optional token list used when no vocab file is supplied. |
None
|
object_token_ids
|
list[int] | None
|
Optional ids that represent object classes. |
None
|
relation_token_ids
|
list[int] | None
|
Optional ids that represent predicates. |
None
|
pad_token
|
str
|
Padding token. |
'[PAD]'
|
cls_token
|
str
|
Sequence-start token. |
'[CLS]'
|
sep_token
|
str
|
Triple separator token. |
'[SEP]'
|
mask_token
|
str
|
Mask token. |
'[MASK]'
|
unk_token
|
str
|
Unknown token. |
'[MASK]'
|
model_max_length
|
int
|
Maximum tokenizer length metadata. |
DEFAULT_MODEL_MAX_LENGTH
|
kwargs
|
str | int | float | bool | None
|
Additional tokenizer compatibility fields. |
{}
|
Examples:
>>> tokenizer = LTNetRelationTokenizer(tokens=["__image__", "person"])
>>> tokenizer.convert_tokens_to_ids("[CLS]")
1
Source code in models/ltnet/src/ltnet/tokenization_ltnet.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 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 | |
__init__ ¶
__init__(
vocab_file: str | None = None,
tokens: list[str] | None = None,
object_token_ids: list[int] | None = None,
relation_token_ids: list[int] | None = None,
pad_token: str = "[PAD]",
cls_token: str = "[CLS]",
sep_token: str = "[SEP]",
mask_token: str = "[MASK]",
unk_token: str = "[MASK]",
model_max_length: int = DEFAULT_MODEL_MAX_LENGTH,
padding_side: str = "right",
truncation_side: str = "right",
clean_up_tokenization_spaces: bool = False,
added_tokens_decoder: dict[int | str, str | AddedToken]
| None = None,
name_or_path: str = "",
**kwargs: str | int | float | bool | None,
) -> None
Initialize vocabulary and object/relation id metadata.
Source code in models/ltnet/src/ltnet/tokenization_ltnet.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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | |
encode_scene_graph_tokens ¶
encode_scene_graph_tokens(tokens: list[str]) -> list[int]
Encode already-normalized scene-graph token strings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tokens
|
list[str]
|
Token strings in LT-Net order. |
required |
Returns:
| Type | Description |
|---|---|
list[int]
|
Integer token ids. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If an unknown token appears. |
Source code in models/ltnet/src/ltnet/tokenization_ltnet.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
decode_scene_graph_tokens ¶
decode_scene_graph_tokens(
input_token: list[int],
) -> list[str]
Decode integer scene-graph token ids into token strings.
Source code in models/ltnet/src/ltnet/tokenization_ltnet.py
115 116 117 | |
save_vocabulary ¶
save_vocabulary(
save_directory: str, filename_prefix: str | None = None
) -> tuple[str]
Save object_pred_id2name.json as id-to-token metadata.
Source code in models/ltnet/src/ltnet/tokenization_ltnet.py
119 120 121 122 123 124 125 126 127 128 | |
save_pretrained ¶
save_pretrained(
save_directory: str | PathLike[str],
legacy_format: bool | None = None,
filename_prefix: str | None = None,
push_to_hub: bool = False,
**kwargs: str | int | float | bool | None,
) -> tuple[str, ...]
Save tokenizer files plus LT-Net tokenizer metadata.
Source code in models/ltnet/src/ltnet/tokenization_ltnet.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | |
from_pretrained
classmethod
¶
from_pretrained(
pretrained_model_name_or_path: str | PathLike[str],
cache_dir: str | PathLike[str] | None = None,
force_download: bool = False,
local_files_only: bool = False,
token: str | bool | None = None,
revision: str = "main",
object_token_ids: list[int] | None = None,
relation_token_ids: list[int] | None = None,
**kwargs: str | int | float | bool | None,
) -> "LTNetRelationTokenizer"
Load tokenizer and LT-Net metadata.
Source code in models/ltnet/src/ltnet/tokenization_ltnet.py
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 | |
configuration_ltnet ¶
Configuration for converted LT-Net checkpoints.
DecoderHeadType ¶
Bases: StrEnum
Supported LT-Net bbox decoder head types.
Source code in models/ltnet/src/ltnet/configuration_ltnet.py
12 13 14 15 16 | |
BoxLossType ¶
Bases: StrEnum
Supported LT-Net box objective families.
Source code in models/ltnet/src/ltnet/configuration_ltnet.py
19 20 21 22 23 | |
LTNetConfig ¶
Bases: PretrainedConfig
Architecture and processor metadata for LT-Net checkpoints.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_name
|
str
|
Dataset slug for the converted checkpoint. |
'coco'
|
vocab_size
|
int
|
Mixed special/object/predicate token vocabulary size. |
206
|
obj_classes_size
|
int
|
Object-id embedding/classifier vocabulary size. |
155
|
hidden_size
|
int
|
Transformer hidden dimension. |
256
|
num_hidden_layers
|
int
|
Number of relation encoder layers. |
4
|
num_attention_heads
|
int
|
Number of relation encoder attention heads. |
4
|
dropout
|
float
|
Dropout used by embeddings, encoder, and bbox heads. |
0.1
|
enable_noise
|
bool
|
Whether the original config enabled relation noise. |
False
|
noise_size
|
int
|
Original relation-noise size. |
64
|
decoder_head_type
|
DecoderHeadType | str
|
|
gmm
|
decoder_box_loss
|
BoxLossType | str
|
|
pdf
|
decoder_schedule_sample
|
bool
|
Whether training used scheduled sampling. |
False
|
decoder_two_path
|
bool
|
Whether the original config enabled two-path decoding. |
False
|
decoder_global_feature
|
bool
|
Whether to concatenate max-pooled global features. |
True
|
decoder_greedy
|
bool
|
Whether inference uses GMM means instead of sampling. |
True
|
xy_temperature
|
float
|
GMM mixture temperature for center coordinates. |
1.0
|
wh_temperature
|
float
|
GMM mixture temperature for box size. |
1.0
|
refine
|
bool
|
Whether a refinement head is present. |
False
|
refine_head_type
|
DecoderHeadType | str
|
Refinement bbox head type. |
linear
|
refine_box_loss
|
BoxLossType | str
|
Refinement objective family. |
reg
|
refine_x_softmax
|
bool
|
Whether the decoder records XY PDF scores for refine. |
True
|
max_sequence_length
|
int
|
Processor/model sequence length. |
128
|
id2label
|
Mapping[int, str] | Mapping[str, str] | None
|
Public object label mapping. |
None
|
relation_id2label
|
Mapping[int, str] | Mapping[str, str] | None
|
Public relation label mapping. |
None
|
model_type
|
str | None
|
Ignored compatibility field from serialized configs. |
None
|
transformers_version
|
str | None
|
Ignored compatibility field. |
None
|
kwargs
|
str | int | float | bool | None
|
Additional |
{}
|
Examples:
>>> config = LTNetConfig(hidden_size=32, num_attention_heads=4)
>>> config.model_type
'ltnet'
Source code in models/ltnet/src/ltnet/configuration_ltnet.py
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 | |
__init__ ¶
__init__(
*,
dataset_name: str = "coco",
vocab_size: int = 206,
obj_classes_size: int = 155,
hidden_size: int = 256,
num_hidden_layers: int = 4,
num_attention_heads: int = 4,
dropout: float = 0.1,
enable_noise: bool = False,
noise_size: int = 64,
decoder_head_type: DecoderHeadType
| str = DecoderHeadType.gmm,
decoder_box_loss: BoxLossType | str = BoxLossType.pdf,
decoder_schedule_sample: bool = False,
decoder_two_path: bool = False,
decoder_global_feature: bool = True,
decoder_greedy: bool = True,
xy_temperature: float = 1.0,
wh_temperature: float = 1.0,
refine: bool = False,
refine_head_type: DecoderHeadType
| str = DecoderHeadType.linear,
refine_box_loss: BoxLossType | str = BoxLossType.reg,
refine_x_softmax: bool = True,
max_sequence_length: int = 128,
id2label: Mapping[int, str]
| Mapping[str, str]
| None = None,
relation_id2label: Mapping[int, str]
| Mapping[str, str]
| None = None,
bos_token_id: int = 1,
eos_token_id: int = 2,
pad_token_id: int = 0,
mask_token_id: int = 3,
model_type: str | None = None,
transformers_version: str | None = None,
**kwargs: str | int | float | bool | None,
) -> None
Initialize LT-Net architecture and metadata fields.
Source code in models/ltnet/src/ltnet/configuration_ltnet.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 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | |
conversion ¶
Conversion helpers for original LT-Net checkpoints.
convert_original_checkpoint ¶
convert_original_checkpoint(
*,
checkpoint_path: str | Path,
cfg_path: str | Path,
vocab_path: str | Path,
output_dir: str | Path,
dataset_name: Literal["coco", "vg_msdn"],
push_to_hub: bool = False,
hub_model_id: str | None = None,
strict: bool = True,
) -> None
Convert an original LT-Net checkpoint into local HF-style files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
checkpoint_path
|
str | Path
|
Vendor |
required |
cfg_path
|
str | Path
|
Vendor YAML config path. Stored in metadata for traceability. |
required |
vocab_path
|
str | Path
|
JSON id-to-token vocabulary exported from
|
required |
output_dir
|
str | Path
|
Directory to write converted model/processor files. |
required |
dataset_name
|
Literal['coco', 'vg_msdn']
|
Dataset identifier for the converted checkpoint. |
required |
push_to_hub
|
bool
|
Reserved publish flag; implementation PRs keep it false. |
False
|
hub_model_id
|
str | None
|
Optional Hub repo id used only when publishing is enabled. |
None
|
strict
|
bool
|
Whether checkpoint keys must exactly match the converted model. |
True
|
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If Hub upload is requested from this helper. |
Examples:
>>> convert_original_checkpoint
<function convert_original_checkpoint at ...>
Source code in models/ltnet/src/ltnet/conversion.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 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 | |
modeling_lt_compatible ¶
Local LT-Net modules with original checkpoint-compatible state keys.
MultiHeadedAttention ¶
Bases: Module
Multi-head attention matching the original LT-Net implementation.
Source code in models/ltnet/src/ltnet/modeling_lt_compatible.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 | |
ContMultiHeadedAttention ¶
Bases: Module
Continuous-valued attention used by the original bbox decoder.
Source code in models/ltnet/src/ltnet/modeling_lt_compatible.py
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 | |
CustomAttention ¶
Bases: Module
Refinement attention with optional PDF confidence reweighting.
Source code in models/ltnet/src/ltnet/modeling_lt_compatible.py
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 | |
GELU ¶
Bases: Module
Original LT-Net GELU implementation.
Source code in models/ltnet/src/ltnet/modeling_lt_compatible.py
199 200 201 202 203 204 205 206 207 208 209 | |
PositionwiseFeedForward ¶
Bases: Module
Original pre-norm feed-forward block.
Source code in models/ltnet/src/ltnet/modeling_lt_compatible.py
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 | |
TransformerEncoderLayer ¶
Bases: Module
Original relation encoder layer.
Source code in models/ltnet/src/ltnet/modeling_lt_compatible.py
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | |
TransformerEncoder ¶
Bases: Module
Original relation transformer encoder.
Source code in models/ltnet/src/ltnet/modeling_lt_compatible.py
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 | |
SentenceEmbeddings ¶
Bases: Module
Original sentence/object/token-type embeddings.
Source code in models/ltnet/src/ltnet/modeling_lt_compatible.py
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 | |
RelEncoder ¶
Bases: Module
Original LT-Net relation encoder and token classifiers.
Source code in models/ltnet/src/ltnet/modeling_lt_compatible.py
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 | |
CustomTransformerDecoderLayer ¶
Bases: Module
Original bbox decoder layer.
Source code in models/ltnet/src/ltnet/modeling_lt_compatible.py
390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 | |
CustomTransformerDecoder ¶
Bases: Module
Original custom bbox transformer decoder.
Source code in models/ltnet/src/ltnet/modeling_lt_compatible.py
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 | |
DecoderLinearHead ¶
Bases: Module
Original linear decoder box head.
Source code in models/ltnet/src/ltnet/modeling_lt_compatible.py
500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 | |
LinearHead ¶
Bases: Module
Original linear refinement box head.
Source code in models/ltnet/src/ltnet/modeling_lt_compatible.py
521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 | |
GMMHead ¶
Bases: Module
Original GMM box head with optional generator plumbing.
Source code in models/ltnet/src/ltnet/modeling_lt_compatible.py
551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 | |
TransformerRefineLayer ¶
Bases: Module
Original refinement transformer layer.
Source code in models/ltnet/src/ltnet/modeling_lt_compatible.py
808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 | |
RefineEncoder ¶
Bases: Module
Original refinement encoder.
Source code in models/ltnet/src/ltnet/modeling_lt_compatible.py
843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 | |
PDFDecoder ¶
Bases: Module
Original LT-Net PDF decoder.
Source code in models/ltnet/src/ltnet/modeling_lt_compatible.py
886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 | |
BBoxHead ¶
Bases: Module
Original LT-Net bbox head.
Source code in models/ltnet/src/ltnet/modeling_lt_compatible.py
1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 | |
modeling_ltnet ¶
PyTorch model wrapper for LT-Net.
LTNetModelOutput
dataclass
¶
Bases: ModelOutput
Raw LT-Net model outputs.
Attributes:
| Name | Type | Description |
|---|---|---|
vocab_logits |
Float[Tensor, 'batch sequence vocab'] | None
|
Mixed token vocabulary logits. |
obj_id_logits |
Float[Tensor, 'batch sequence object_classes'] | None
|
Object-id classifier logits. |
token_type_logits |
Float[Tensor, 'batch sequence token_types'] | None
|
Token-type classifier logits. |
coarse_box |
Float[Tensor, 'batch sequence 4'] | None
|
Coarse normalized center |
coarse_gmm |
Float[Tensor, 'batch sequence gmm_params'] | None
|
Optional coarse GMM parameters. |
refine_box |
Float[Tensor, 'batch sequence 4'] | None
|
Optional refined normalized center |
refine_gmm |
Float[Tensor, 'batch sequence gmm_params'] | None
|
Optional refinement GMM parameters. |
hidden_states |
Float[Tensor, 'batch sequence hidden'] | None
|
Optional encoder hidden states. |
Examples:
>>> import torch
>>> out = LTNetModelOutput(
... vocab_logits=torch.zeros(1, 2, 3),
... obj_id_logits=torch.zeros(1, 2, 4),
... token_type_logits=torch.zeros(1, 2, 4),
... coarse_box=torch.zeros(1, 2, 4),
... )
>>> out.coarse_box.shape
torch.Size([1, 2, 4])
Source code in models/ltnet/src/ltnet/modeling_ltnet.py
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 | |
LTNetForLayoutGeneration ¶
Bases: PreTrainedModel
Transformers PreTrainedModel for LT-Net relation-to-layout inference.
Source code in models/ltnet/src/ltnet/modeling_ltnet.py
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 | |
__init__ ¶
__init__(config: LTNetConfig) -> None
Initialize relation encoder and bbox head.
Source code in models/ltnet/src/ltnet/modeling_ltnet.py
61 62 63 64 65 66 | |
forward ¶
forward(
input_token: Int[Tensor, "batch sequence"],
input_obj_id: Int[Tensor, "batch sequence"],
segment_label: Int[Tensor, "batch sequence"],
token_type: Int[Tensor, "batch sequence"],
src_mask: Bool[Tensor, "batch 1 sequence"]
| None = None,
global_mask: Bool[Tensor, "batch sequence"]
| None = None,
bbox: Float[Tensor, "batch sequence 4"] | None = None,
bbox_mask: Bool[Tensor, "batch sequence"] | None = None,
inference: bool = False,
generator: Generator | None = None,
output_hidden_states: bool = False,
return_dict: bool = True,
) -> (
LTNetModelOutput
| tuple[
Float[torch.Tensor, "batch sequence feature"]
| None,
...,
]
)
Run LT-Net relation encoding and bbox prediction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_token
|
Int[Tensor, 'batch sequence']
|
Mixed object/predicate token ids. |
required |
input_obj_id
|
Int[Tensor, 'batch sequence']
|
Stable object ids for object-token positions. |
required |
segment_label
|
Int[Tensor, 'batch sequence']
|
Relation segment ids. |
required |
token_type
|
Int[Tensor, 'batch sequence']
|
Token type ids |
required |
src_mask
|
Bool[Tensor, 'batch 1 sequence'] | None
|
Valid-token mask shaped |
None
|
global_mask
|
Bool[Tensor, 'batch sequence'] | None
|
Optional reference global-feature mask. |
None
|
bbox
|
Float[Tensor, 'batch sequence 4'] | None
|
Optional teacher-forced boxes for training/parity paths. |
None
|
bbox_mask
|
Bool[Tensor, 'batch sequence'] | None
|
Optional box validity mask, reserved for parity paths. |
None
|
inference
|
bool
|
Compatibility flag; greedy decoding is pipeline-owned. |
False
|
generator
|
Generator | None
|
Optional PyTorch generator for stochastic GMM sampling. |
None
|
output_hidden_states
|
bool
|
Whether to include encoder hidden states. |
False
|
return_dict
|
bool
|
Whether to return a |
True
|
Returns:
| Type | Description |
|---|---|
LTNetModelOutput | tuple[Float[Tensor, 'batch sequence feature'] | None, ...]
|
Raw LT-Net output dataclass or tuple. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If required tensor shapes are invalid. |
Source code in models/ltnet/src/ltnet/modeling_ltnet.py
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 | |
pipeline_ltnet ¶
Pipeline wrapper for LT-Net relation-to-layout generation.
LTNetPipeline ¶
Bases: LayoutGenerationPipeline
Compose an LT-Net model and processor for scene-graph layout inference.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
LTNetForLayoutGeneration
|
Converted LT-Net model. |
required |
processor
|
LTNetProcessor
|
Matching scene-graph processor/tokenizer. |
required |
config
|
LTNetConfig | None
|
Optional root pipeline config. Defaults to |
None
|
Examples:
>>> processor = LTNetProcessor.from_config()
>>> config = LTNetConfig(
... vocab_size=processor.tokenizer.vocab_size,
... hidden_size=32,
... num_hidden_layers=1,
... num_attention_heads=4,
... )
>>> pipe = LTNetPipeline(
... model=LTNetForLayoutGeneration(config),
... processor=processor,
... )
>>> pipe.config.model_type
'ltnet'
Source code in models/ltnet/src/ltnet/pipeline_ltnet.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 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 | |
__init__ ¶
__init__(
model: LTNetForLayoutGeneration,
processor: LTNetProcessor,
config: LTNetConfig | None = None,
) -> None
Initialize the pipeline with model and processor components.
Source code in models/ltnet/src/ltnet/pipeline_ltnet.py
113 114 115 116 117 118 119 120 121 122 123 | |
__call__ ¶
__call__(
*,
batch_size: int = 1,
seed: int | None = None,
generator: Generator | None = None,
condition_type: ConditionType
| str = ConditionType.relation,
labels: Int[Tensor, "batch elements"]
| Sequence[int]
| None = None,
bbox: Float[Tensor, "batch elements 4"]
| Sequence[Sequence[float]]
| None = None,
mask: Bool[Tensor, "batch elements"]
| Sequence[bool]
| 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 = "dataclass",
return_intermediates: bool = False,
scene_graph: SceneGraphInput
| SceneGraphMapping
| None = None,
objects: Sequence[LayoutObject] | None = None,
relations: Sequence[LayoutRelation] | None = None,
) -> (
LayoutGenerationOutput
| dict[
str,
Float[torch.Tensor, "..."]
| Int[torch.Tensor, "..."]
| Bool[torch.Tensor, "..."]
| dict[int, str]
| dict[str, Float[torch.Tensor, "..."] | None],
]
)
Generate layouts from a public scene graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch_size
|
int
|
Number of layouts to generate from the same graph. |
1
|
seed
|
int | None
|
Convenience seed used only when |
None
|
generator
|
Generator | None
|
Optional PyTorch generator; takes precedence over seed. |
None
|
condition_type
|
ConditionType | str
|
Must normalize to |
relation
|
labels
|
Int[Tensor, 'batch elements'] | Sequence[int] | None
|
Reserved v1 interface input; LT-Net uses |
None
|
bbox
|
Float[Tensor, 'batch elements 4'] | Sequence[Sequence[float]] | None
|
Reserved v1 box constraint input. |
None
|
mask
|
Bool[Tensor, 'batch elements'] | Sequence[bool] | None
|
Reserved v1 validity-mask input. |
None
|
num_elements
|
int | list[int] | Int[Tensor, 'batch'] | None
|
Reserved v1 element-count input. |
None
|
box_format
|
BoxFormat | str
|
Output box format; LT-Net returns normalized |
xywh
|
normalized
|
bool
|
Whether output boxes should be normalized. |
True
|
canvas_size
|
tuple[int, int] | None
|
Reserved denormalization canvas size. |
None
|
num_inference_steps
|
int | None
|
Reserved v1 step count. |
None
|
output_type
|
OutputType
|
Return dataclass or dict. |
'dataclass'
|
return_intermediates
|
bool
|
Include raw logits/boxes in intermediates. |
False
|
scene_graph
|
SceneGraphInput | SceneGraphMapping | None
|
Public relation payload. |
None
|
objects
|
Sequence[LayoutObject] | None
|
Object-node shorthand when |
None
|
relations
|
Sequence[LayoutRelation] | None
|
Relation-edge shorthand when |
None
|
Returns:
| Type | Description |
|---|---|
LayoutGenerationOutput | dict[str, Float[Tensor, '...'] | Int[Tensor, '...'] | Bool[Tensor, '...'] | dict[int, str] | dict[str, Float[Tensor, '...'] | None]]
|
Layout generation output dataclass or dict. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the condition or graph payload is unsupported. |
Source code in models/ltnet/src/ltnet/pipeline_ltnet.py
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 | |
processing_ltnet ¶
Processor for LT-Net scene graphs and layout outputs.
LTNetProcessor ¶
Bases: ProcessorMixin
Normalize scene graphs, tokenize LT-Net inputs, and postprocess boxes.
Source code in models/ltnet/src/ltnet/processing_ltnet.py
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 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 403 404 405 406 407 408 409 410 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 | |
__init__ ¶
__init__(
tokenizer: LTNetRelationTokenizer,
dataset_name: str = "coco",
max_sequence_length: int = 128,
id2label: Mapping[int, str]
| Mapping[str, str]
| None = None,
relation_id2label: Mapping[int, str]
| Mapping[str, str]
| None = None,
object_reduce: Literal[
"first", "last", "mean"
] = "first",
) -> None
Initialize processor label maps and tokenizer component.
Source code in models/ltnet/src/ltnet/processing_ltnet.py
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 | |
from_config
classmethod
¶
from_config(
*,
dataset_name: str = "coco",
max_sequence_length: int = 128,
id2label: Mapping[int, str]
| Mapping[str, str]
| None = None,
relation_id2label: Mapping[int, str]
| Mapping[str, str]
| None = None,
) -> "LTNetProcessor"
Construct a processor and tokenizer without external files.
Returns:
| Type | Description |
|---|---|
'LTNetProcessor'
|
Processor with synthetic vocabulary derived from the label maps. |
Examples:
>>> processor = LTNetProcessor.from_config()
>>> processor.tokenizer.cls_token_id
1
Source code in models/ltnet/src/ltnet/processing_ltnet.py
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 | |
normalize_condition_type ¶
normalize_condition_type(
condition_type: ConditionType | str,
) -> ConditionType
Normalize and validate the LT-Net public condition type.
Source code in models/ltnet/src/ltnet/processing_ltnet.py
140 141 142 143 144 145 146 147 148 149 150 151 | |
__call__ ¶
__call__(
*,
scene_graph: SceneGraphInput
| SceneGraphMapping
| None = None,
objects: Sequence[LayoutObject] | None = None,
relations: Sequence[LayoutRelation] | None = None,
batch_size: int = 1,
condition_type: ConditionType
| str = ConditionType.relation,
return_tensors: Literal["pt", "np"] = "pt",
max_sequence_length: int | None = None,
) -> BatchEncoding
Build LT-Net model tensors from public scene-graph inputs.
Source code in models/ltnet/src/ltnet/processing_ltnet.py
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 | |
post_process_layout_generation ¶
post_process_layout_generation(
model_outputs: LTNetModelOutput,
*,
input_token: Int[Tensor, "batch sequence"]
| None = None,
input_obj_id: Int[Tensor, "batch sequence"],
token_type: Int[Tensor, "batch sequence"],
box_format: BoxFormat | str = BoxFormat.xywh,
normalized: bool = True,
canvas_size: tuple[int, int] | None = None,
output_type: OutputType = "dataclass",
return_intermediates: bool = False,
) -> (
LayoutGenerationOutput
| dict[
str,
Float[torch.Tensor, "..."]
| Int[torch.Tensor, "..."]
| Bool[torch.Tensor, "..."]
| dict[int, str]
| dict[str, Float[torch.Tensor, "..."] | None],
]
)
Convert raw token-level boxes into public object-level layouts.
Source code in models/ltnet/src/ltnet/processing_ltnet.py
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 403 404 405 406 407 408 409 410 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 | |
save_pretrained ¶
save_pretrained(
save_directory: str | PathLike[str],
push_to_hub: bool = False,
**kwargs: str | int | float | bool | None,
) -> tuple[str, ...]
Save processor metadata and tokenizer files.
Source code in models/ltnet/src/ltnet/processing_ltnet.py
441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 | |
relation_schema ¶
Public scene-graph dataclasses for LT-Net processors.
LayoutObject
dataclass
¶
One scene-graph object node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
int | str
|
Stable object id within a scene graph. |
required |
label
|
int | str
|
Dataset-local object label id or label string. |
required |
bbox
|
tuple[float, float, float, float] | None
|
Optional normalized center |
None
|
Examples:
>>> LayoutObject(id="person-1", label="person").id
'person-1'
Source code in models/ltnet/src/ltnet/relation_schema.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | |
LayoutRelation
dataclass
¶
One directed scene-graph edge.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subject
|
int | str
|
Source object id. |
required |
predicate
|
int | str
|
Relation id or label. |
required |
object
|
int | str
|
Target object id. |
required |
bbox_delta
|
tuple[float, float, float, float] | None
|
Optional relation geometry. |
None
|
score
|
float | None
|
Optional edge confidence. |
None
|
Examples:
>>> LayoutRelation("a", "left of", "b").predicate
'left of'
Source code in models/ltnet/src/ltnet/relation_schema.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | |
SceneGraphInput
dataclass
¶
Normalized scene graph payload.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
objects
|
tuple[LayoutObject, ...]
|
Scene-graph object nodes. |
required |
relations
|
tuple[LayoutRelation, ...]
|
Scene-graph relation edges. |
required |
id2label
|
dict[int, str] | None
|
Optional public object label mapping. |
None
|
relation_id2label
|
dict[int, str] | None
|
Optional relation label mapping. |
None
|
Examples:
>>> graph = SceneGraphInput(
... objects=(LayoutObject("a", "person"), LayoutObject("b", "table")),
... relations=(LayoutRelation("a", "left of", "b"),),
... )
>>> len(graph.relations)
1
Source code in models/ltnet/src/ltnet/relation_schema.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | |
tokenization_ltnet ¶
Tokenizer for LT-Net scene-graph token vocabularies.
LTNetRelationTokenizer ¶
Bases: WhitespaceTokenizerMixin, PreTrainedTokenizer
Discrete scene-graph tokenizer saved as a standard HF tokenizer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vocab_file
|
str | None
|
Optional path to |
None
|
tokens
|
list[str] | None
|
Optional token list used when no vocab file is supplied. |
None
|
object_token_ids
|
list[int] | None
|
Optional ids that represent object classes. |
None
|
relation_token_ids
|
list[int] | None
|
Optional ids that represent predicates. |
None
|
pad_token
|
str
|
Padding token. |
'[PAD]'
|
cls_token
|
str
|
Sequence-start token. |
'[CLS]'
|
sep_token
|
str
|
Triple separator token. |
'[SEP]'
|
mask_token
|
str
|
Mask token. |
'[MASK]'
|
unk_token
|
str
|
Unknown token. |
'[MASK]'
|
model_max_length
|
int
|
Maximum tokenizer length metadata. |
DEFAULT_MODEL_MAX_LENGTH
|
kwargs
|
str | int | float | bool | None
|
Additional tokenizer compatibility fields. |
{}
|
Examples:
>>> tokenizer = LTNetRelationTokenizer(tokens=["__image__", "person"])
>>> tokenizer.convert_tokens_to_ids("[CLS]")
1
Source code in models/ltnet/src/ltnet/tokenization_ltnet.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 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 | |
__init__ ¶
__init__(
vocab_file: str | None = None,
tokens: list[str] | None = None,
object_token_ids: list[int] | None = None,
relation_token_ids: list[int] | None = None,
pad_token: str = "[PAD]",
cls_token: str = "[CLS]",
sep_token: str = "[SEP]",
mask_token: str = "[MASK]",
unk_token: str = "[MASK]",
model_max_length: int = DEFAULT_MODEL_MAX_LENGTH,
padding_side: str = "right",
truncation_side: str = "right",
clean_up_tokenization_spaces: bool = False,
added_tokens_decoder: dict[int | str, str | AddedToken]
| None = None,
name_or_path: str = "",
**kwargs: str | int | float | bool | None,
) -> None
Initialize vocabulary and object/relation id metadata.
Source code in models/ltnet/src/ltnet/tokenization_ltnet.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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | |
encode_scene_graph_tokens ¶
encode_scene_graph_tokens(tokens: list[str]) -> list[int]
Encode already-normalized scene-graph token strings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tokens
|
list[str]
|
Token strings in LT-Net order. |
required |
Returns:
| Type | Description |
|---|---|
list[int]
|
Integer token ids. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If an unknown token appears. |
Source code in models/ltnet/src/ltnet/tokenization_ltnet.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
decode_scene_graph_tokens ¶
decode_scene_graph_tokens(
input_token: list[int],
) -> list[str]
Decode integer scene-graph token ids into token strings.
Source code in models/ltnet/src/ltnet/tokenization_ltnet.py
115 116 117 | |
save_vocabulary ¶
save_vocabulary(
save_directory: str, filename_prefix: str | None = None
) -> tuple[str]
Save object_pred_id2name.json as id-to-token metadata.
Source code in models/ltnet/src/ltnet/tokenization_ltnet.py
119 120 121 122 123 124 125 126 127 128 | |
save_pretrained ¶
save_pretrained(
save_directory: str | PathLike[str],
legacy_format: bool | None = None,
filename_prefix: str | None = None,
push_to_hub: bool = False,
**kwargs: str | int | float | bool | None,
) -> tuple[str, ...]
Save tokenizer files plus LT-Net tokenizer metadata.
Source code in models/ltnet/src/ltnet/tokenization_ltnet.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | |
from_pretrained
classmethod
¶
from_pretrained(
pretrained_model_name_or_path: str | PathLike[str],
cache_dir: str | PathLike[str] | None = None,
force_download: bool = False,
local_files_only: bool = False,
token: str | bool | None = None,
revision: str = "main",
object_token_ids: list[int] | None = None,
relation_token_ids: list[int] | None = None,
**kwargs: str | int | float | bool | None,
) -> "LTNetRelationTokenizer"
Load tokenizer and LT-Net metadata.
Source code in models/ltnet/src/ltnet/tokenization_ltnet.py
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 | |
vendor_state_dict ¶
Utilities for loading LT-Net checkpoint state dictionaries.
load_original_state_dict ¶
load_original_state_dict(
checkpoint_path: str | Path,
) -> dict[str, Shaped[torch.Tensor, "..."]]
Load a vendor checkpoint and return model weights only.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
checkpoint_path
|
str | Path
|
Original |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Shaped[Tensor, '...']]
|
Raw or |
dict[str, Shaped[Tensor, '...']]
|
|
Examples:
>>> import tempfile
>>> import torch
>>> with tempfile.NamedTemporaryFile(suffix=".pth") as handle:
... torch.save({"state_dict": {"module.weight": torch.ones(1)}}, handle.name)
... sorted(load_original_state_dict(handle.name))
['weight']
Source code in models/ltnet/src/ltnet/vendor_state_dict.py
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 | |
load_strict_mapped_state_dict ¶
load_strict_mapped_state_dict(
model: Module,
state_dict: Mapping[str, Shaped[Tensor, "..."]],
) -> None
Load a mapped state dict and fail on any key mismatch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Module
|
Target converted model. |
required |
state_dict
|
Mapping[str, Shaped[Tensor, '...']]
|
Converted tensor mapping. |
required |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If keys are missing or unexpected. |
Source code in models/ltnet/src/ltnet/vendor_state_dict.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | |