Model Card for RADM¶
This package ports RADM, the CIKM 2023 relation-aware diffusion method for controllable poster layout generation, into a 🧨diffusers-style package.
Model Details¶
Model Description¶
RADM is a proposal-box diffusion pipeline for content-aware poster layout generation. The public pipeline accepts a content image plus optional RADM text-feature tensors, runs reverse diffusion over normalized proposal boxes, and returns normalized center xywh boxes, dataset-local labels, a valid-element mask, id2label, scores, and optional denoising trajectory metadata.
- Developed by: RADM authors.
- Shared by: creative-graphic-design.
- Model type: content-aware; task: single-task; conditioning: none.
- Language(s) (NLP): not applicable.
- License: unconfirmed for the checked original source and any user-supplied or converted weights.
Model Sources¶
- Repository: RADM repository
- Paper: arXiv 2306.09086
- Original checkpoint host: the checked RADM README publishes dataset and testing-feature assets only; no released checkpoint is published.
Supported Checkpoints¶
| Checkpoint | Hub ID | Status |
|---|---|---|
| CGL | creative-graphic-design/radm-cgl |
not-published |
| CGL-v2 | creative-graphic-design/radm-cgl-v2 |
not-published |
Uses¶
Direct Use¶
Use this package for local RADM conversion experiments, CPU smoke tests, and gated original-code parity preparation after a user-supplied local checkpoint and license terms have been confirmed.
The first public condition is content_image. images or content["image"] is required; text_features and text_mask are auxiliary payload fields under the same content-image condition.
Downstream Use¶
Generated poster layouts may feed research evaluation, poster composition studies, or downstream rendering systems after dataset, license, and quality review.
Out-of-Scope Use¶
Do not use synthetic RADM smoke artifacts as release checkpoints, claim original-code agreement without generated references, or redistribute converted weights before local checkpoint provenance and license status are resolved.
Bias, Risks, and Limitations¶
The checked RADM README publishes dataset and testing-feature assets only; no public RADM checkpoint is published. The checked source has no license file, so weight redistribution is blocked until maintainers verify the source license, checkpoint provenance, and dataset terms.
Recommendations¶
Use explicit local paths for user-supplied checkpoints, datasets, text features, and vendor source. Run the gated parity workflow before comparing generated layouts against the original method.
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" \
"radm @ git+https://github.com/creative-graphic-design/design-generators.git#subdirectory=models/radm"
Clone this repository, install the workspace member, and run the conversion steps in REPRODUCING.md. Those steps create .cache/radm/converted/cgl.
git clone https://github.com/creative-graphic-design/design-generators.git
cd design-generators
uv sync --package radm
uv run --package radm python
from PIL import Image
from radm import RADMPipeline
path = ".cache/radm/converted/cgl"
# After Hub publication: from_pretrained("creative-graphic-design/radm-cgl")
pipe = RADMPipeline.from_pretrained(path)
out = pipe(Image.new("RGB", (512, 768)), seed=0)
print(out.bbox)
print(out.labels)
print(out.mask)
torch.Size([1, 100, 4])
torch.Size([1, 100])
torch.Size([1, 100])
Training Details¶
Training Data¶
The package-local adapter accepts explicit CGL and CGL-v2 COCO-style annotation, image, and precomputed 768-dimensional text-feature paths. It does not download data. Data provenance and the CGL-v2 license remain unresolved; see TRAINING.md for the current gate status.
Training Procedure¶
The CGL LightningCLI recipe predicts four classes while preserving the five-entry source vocabulary in its captured class mapping. It initializes ResNet-50 from Detectron2’s torchvision ImageNet checkpoint, which the Model Zoo lists under CC BY-SA 3.0. The three-seed, 1,500-step production runs verify the configured training path only. The 250,000-step CGL S5 retrain has not been rerun, so no trained-checkpoint reproduction is claimed; see TRAINING.md.
Evaluation¶
Testing Data, Factors & Metrics¶
Testing Data¶
Vendor parity requires local original-code outputs generated from a user-supplied checkpoint, CGL dataset root, text-feature root, and one selected GPU. Large generated tensors, images, weights, and downloaded artifacts are not committed.
Factors¶
Parity is disaggregated by checkpoint hash, config hash, seed, timestep sequence, proposal noise, denoiser logits, denoised boxes, post-threshold boxes, labels, scores, and NMS indices.
Metrics¶
Metrics are exact scheduler/timestep agreement, exact tensor equality where the converted and original paths share operations, and explicit tolerance only after dtype, TF32, operation-order, and Detectron2 versus torchvision differences are diagnosed.
Parity Results¶
| Dataset | Compared path | Cases | Assertion |
|---|---|---|---|
| CGL | original Detectron2 RADM path vs. converted 🧨diffusers path |
0 | not run; vendor parity is not verified, and the recorded evaluation-path artifact is diagnosis evidence, not an accepted parity result |
| Synthetic smoke | randomly initialized RADM pipeline save/load | 1 | schema smoke only, no original-code parity claim |
No accepted original-code inference parity number is available yet. The package includes a gated parity harness that fails under PARITY_REQUIRE=1 when required local assets are absent.
Reproducibility¶
Reproduce original-implementation agreement by supplying an approved local
checkpoint and data assets, capturing the original Detectron2 reference state,
running the gated parity tests, converting the checkpoint, and smoke-testing
from_pretrained as described in
REPRODUCING.md.
Training-stage status and the future member-scoped training commands are in
TRAINING.md.
Environmental Impact¶
No model weights are included. Conversion, reference generation, and parity costs depend on the selected checkpoint and local hardware.
Technical Specifications¶
Model Architecture and Objective¶
RADM samples proposal boxes and denoises them with relation-aware image and text conditioning. The package-level runtime keeps the image/text feature processor, proposal scheduler, denoiser, and postprocessing separate so converted artifacts can load through 🧨diffusers component folders.
Compute Infrastructure¶
Vendor parity commands are intended for one explicitly selected GPU when the original Detectron2 path is available.
Hardware¶
CPU is sufficient for import, tiny random-weight smoke tests, and config round trips. CUDA is required for heavyweight original-code parity.
Software¶
Use uv run --package radm ... from the repository root so workspace dependency sources and extras resolve correctly.
License¶
Repository wrapper code is Apache-2.0. The checked original RADM source has no license file, and weight redistribution is blocked until license and checkpoint provenance are confirmed.
Citation¶
@inproceedings{zhang2023radm,
title={Relation-Aware Diffusion Model for Controllable Poster Layout Generation},
author={Zhang, Yiheng and others},
booktitle={Proceedings of the 32nd ACM International Conference on Information and Knowledge Management},
year={2023}
}
API Reference¶
RADM Diffusers package for content-aware poster layout generation.
RADMConfig ¶
Bases: ConfigMixin
Configuration saved with RADM pipeline artifacts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_name
|
DatasetName | str
|
Poster dataset variant. |
cgl
|
id2label
|
Mapping[int | str, str] | None
|
Public label mapping. Defaults to the shared CGL labels. |
None
|
original_id2label
|
Mapping[int | str, str] | None
|
Label spellings from the checked RADM source. |
None
|
num_proposals
|
int
|
Number of proposal boxes sampled during inference. |
100
|
num_classes
|
int
|
Number of semantic classes predicted by the denoiser. |
5
|
hidden_dim
|
int
|
Proposal and condition hidden dimension. |
256
|
text_feature_dim
|
int
|
Last dimension of RADM text-feature tensors. |
768
|
max_text_num
|
int
|
Maximum text-feature rows per example. |
20
|
num_heads
|
int
|
Number of repeated proposal refinement blocks. |
6
|
num_attention_heads
|
int
|
Proposal self-attention head count. |
8
|
dim_feedforward
|
int
|
Proposal feed-forward hidden dimension. |
2048
|
num_dynamic
|
int
|
Number of dynamic-convolution projections. |
2
|
dim_dynamic
|
int
|
Intermediate dynamic-convolution dimension. |
64
|
num_cls
|
int
|
Number of repeated classification projection layers. |
1
|
num_reg
|
int
|
Number of repeated box-regression projection layers. |
3
|
roi_resolution
|
int
|
ROIAlign output resolution. |
7
|
roi_sampling_ratio
|
int
|
ROIAlign sampling ratio. |
2
|
with_vtram
|
bool
|
Whether visual-textual relation features are enabled. |
True
|
with_gram
|
bool
|
Whether geometric relation features are enabled. |
True
|
deep_supervision
|
bool
|
Whether intermediate proposal heads are returned. |
True
|
backbone_depth
|
int
|
ResNet backbone depth. |
50
|
backbone_freeze_at
|
int
|
Number of initial ResNet stages to freeze. |
2
|
image_size
|
int
|
Short-side image preprocessing target. |
800
|
size_divisibility
|
int
|
Padding multiple for image tensors. |
32
|
pixel_mean
|
Sequence[float]
|
RGB mean in 0-255 space. |
(123.675, 116.28, 103.53)
|
pixel_std
|
Sequence[float]
|
RGB standard deviation in 0-255 space. |
(58.395, 57.12, 57.375)
|
inference_steps
|
int
|
Default number of reverse-diffusion steps. |
50
|
num_train_timesteps
|
int
|
Number of training diffusion timesteps. |
1000
|
snr_scale
|
float
|
RADM signal-to-noise scaling metadata. |
2.0
|
sample_step
|
int
|
Original sampling stride metadata. |
1
|
class_threshold
|
float
|
Default confidence threshold. |
0.3
|
nms_threshold
|
float
|
Default class-wise NMS threshold. |
0.5
|
denoiser_subfolder
|
str
|
Pipeline denoiser component subfolder. |
'denoiser'
|
scheduler_subfolder
|
str
|
Pipeline scheduler component subfolder. |
'scheduler'
|
processor_subfolder
|
str
|
Pipeline processor component subfolder. |
'processor'
|
conversion_report
|
Mapping[str, YamlValue] | None
|
Conversion metadata persisted with local artifacts. |
None
|
checkpoint_status
|
str
|
Human-readable checkpoint status. |
'RADM README confirms datasets only; no released checkpoint is published'
|
license_status
|
str
|
Human-readable source/weight license status. |
'checked original source has no license file'
|
Examples:
>>> config = RADMConfig(num_proposals=2, hidden_dim=8)
>>> config.num_labels
5
Source code in models/radm/src/radm/configuration_radm.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | |
__init__ ¶
__init__(
*,
dataset_name: DatasetName | str = DatasetName.cgl,
id2label: Mapping[int | str, str] | None = None,
original_id2label: Mapping[int | str, str]
| None = None,
num_proposals: int = 100,
num_classes: int = 5,
hidden_dim: int = 256,
text_feature_dim: int = 768,
max_text_num: int = 20,
num_heads: int = 6,
num_attention_heads: int = 8,
dim_feedforward: int = 2048,
num_dynamic: int = 2,
dim_dynamic: int = 64,
num_cls: int = 1,
num_reg: int = 3,
roi_resolution: int = 7,
roi_sampling_ratio: int = 2,
with_vtram: bool = True,
with_gram: bool = True,
deep_supervision: bool = True,
backbone_depth: int = 50,
backbone_freeze_at: int = 2,
image_size: int = 800,
size_divisibility: int = 32,
pixel_mean: Sequence[float] = (123.675, 116.28, 103.53),
pixel_std: Sequence[float] = (58.395, 57.12, 57.375),
inference_steps: int = 50,
num_train_timesteps: int = 1000,
snr_scale: float = 2.0,
sample_step: int = 1,
class_threshold: float = 0.3,
nms_threshold: float = 0.5,
denoiser_subfolder: str = "denoiser",
scheduler_subfolder: str = "scheduler",
processor_subfolder: str = "processor",
conversion_report: Mapping[str, YamlValue]
| None = None,
checkpoint_status: str = "RADM README confirms datasets only; no released checkpoint is published",
license_status: str = "checked original source has no license file",
) -> None
Initialize RADM settings.
Source code in models/radm/src/radm/configuration_radm.py
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 | |
RADMLabelMode ¶
Bases: StrEnum
Closed set of public RADM label vocabularies.
Source code in models/radm/src/radm/configuration_radm.py
19 20 21 22 23 | |
RADMImageProcessor ¶
Bases: BaseImageProcessor
Prepare RGB images for RADM inference.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_size
|
int
|
Short-side resize target. |
800
|
size_divisibility
|
int
|
Padding multiple used by FPN-style backbones. |
32
|
pixel_mean
|
Sequence[float]
|
RGB mean in 0-255 space. |
(123.675, 116.28, 103.53)
|
pixel_std
|
Sequence[float]
|
RGB standard deviation in 0-255 space. |
(58.395, 57.12, 57.375)
|
Examples:
>>> processor = RADMImageProcessor(image_size=32)
>>> batch = processor.preprocess(Image.new("RGB", (16, 24)))
>>> tuple(batch["pixel_values"].shape[:2])
(1, 3)
Source code in models/radm/src/radm/image_processing_radm.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | |
__init__ ¶
__init__(
image_size: int = 800,
size_divisibility: int = 32,
pixel_mean: Sequence[float] = (123.675, 116.28, 103.53),
pixel_std: Sequence[float] = (58.395, 57.12, 57.375),
**kwargs: Unpack[ImagesKwargs],
) -> None
Initialize image normalization settings.
Source code in models/radm/src/radm/image_processing_radm.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
from_config
classmethod
¶
from_config(config: RADMConfig) -> 'RADMImageProcessor'
Build an image processor from RADM configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
RADMConfig
|
RADM pipeline configuration. |
required |
Returns:
| Type | Description |
|---|---|
'RADMImageProcessor'
|
Image processor with matching resize and normalization metadata. |
Source code in models/radm/src/radm/image_processing_radm.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | |
preprocess ¶
preprocess(
images: ImageInput | Sequence[ImageInput],
**kwargs: Unpack[ImagesKwargs],
) -> BatchFeature
Preprocess one image or an image batch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
images
|
ImageInput | Sequence[ImageInput]
|
PIL, numpy, or torch image input. |
required |
return_tensors
|
Tensor framework. Only |
required | |
kwargs
|
Unpack[ImagesKwargs]
|
Ignored compatibility kwargs. |
{}
|
Returns:
| Type | Description |
|---|---|
BatchFeature
|
Batch feature with padded |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in models/radm/src/radm/image_processing_radm.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 | |
RADMDenoiser ¶
Bases: ModelMixin, ConfigMixin
Genuine RADM proposal denoiser shared by inference and training.
Source code in models/radm/src/radm/modeling_radm.py
828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 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 884 885 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 1059 1060 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 | |
__init__ ¶
__init__(
*,
config: RADMConfig | None = None,
num_classes: int | None = None,
num_proposals: int | None = None,
hidden_dim: int | None = None,
text_feature_dim: int | None = None,
max_text_num: int | None = None,
num_heads: int | None = None,
num_attention_heads: int | None = None,
dim_feedforward: int | None = None,
num_dynamic: int | None = None,
dim_dynamic: int | None = None,
num_cls: int | None = None,
num_reg: int | None = None,
roi_resolution: int | None = None,
roi_sampling_ratio: int | None = None,
with_vtram: bool | None = None,
with_gram: bool | None = None,
deep_supervision: bool | None = None,
backbone_depth: int | None = None,
backbone_freeze_at: int | None = None,
num_train_timesteps: int | None = None,
snr_scale: float | None = None,
) -> None
Initialize from an explicit package config or serialized model values.
Source code in models/radm/src/radm/modeling_radm.py
833 834 835 836 837 838 839 840 841 842 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 884 885 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 | |
q_sample ¶
q_sample(
x_start: Float[Tensor, "batch proposals 4"],
timesteps: Int[Tensor, "batch"],
noise: Float[Tensor, "batch proposals 4"] | None = None,
) -> Float[torch.Tensor, "batch proposals 4"]
Sample the configured cosine forward diffusion process.
Source code in models/radm/src/radm/modeling_radm.py
968 969 970 971 972 973 974 975 976 977 978 979 980 | |
predict_noise_from_start ¶
predict_noise_from_start(
x_t: Float[Tensor, "batch proposals 4"],
timesteps: Int[Tensor, "batch"],
x_start: Float[Tensor, "batch proposals 4"],
) -> Float[torch.Tensor, "batch proposals 4"]
Recover epsilon from a predicted clean diffusion sample.
Source code in models/radm/src/radm/modeling_radm.py
982 983 984 985 986 987 988 989 990 991 992 | |
prepare_diffusion_concat ¶
prepare_diffusion_concat(
boxes_cxcywh: Float[Tensor, "elements 4"],
*,
generator: Generator | None = None,
) -> tuple[
Float[torch.Tensor, "proposals 4"],
Float[torch.Tensor, "proposals 4"],
Int[torch.Tensor, "1"],
]
Prepare one image's padded proposals using the configured sampler.
Source code in models/radm/src/radm/modeling_radm.py
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 | |
forward ¶
forward(
boxes_xyxy: Float[Tensor, "batch proposals 4"],
timesteps: Int[Tensor, "batch"]
| Int[Tensor, ""]
| Float[Tensor, "batch"]
| Float[Tensor, ""],
text_features: Float[Tensor, "batch text text_dim"],
text_mask: Bool[Tensor, "batch text 1"] | None = None,
images: Float[Tensor, "batch channels height width"]
| None = None,
image_scales: Float[Tensor, "batch 4"] | None = None,
absolute_boxes_xyxy: Float[Tensor, "batch proposals 4"]
| None = None,
) -> RADMDenoiserOutput
Predict proposal classes and denoised boxes.
Source code in models/radm/src/radm/modeling_radm.py
1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 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 | |
RADMDenoiserOutput
dataclass
¶
Bases: BaseOutput
Predictions from one relation-aware proposal refinement pass.
Source code in models/radm/src/radm/modeling_radm.py
27 28 29 30 31 32 33 34 35 36 37 38 39 | |
RADMPipeline ¶
Bases: DiffusionPipeline
Generate poster layouts with a RADM proposal diffusion pipeline.
Source code in models/radm/src/radm/pipeline_radm.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 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 | |
__init__ ¶
__init__(
denoiser: RADMDenoiser,
scheduler: RADMScheduler,
config: RADMConfig,
processor: RADMProcessor | None = None,
) -> None
Create a RADM pipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
denoiser
|
RADMDenoiser
|
Proposal denoiser component. |
required |
scheduler
|
RADMScheduler
|
Proposal diffusion scheduler. |
required |
config
|
RADMConfig
|
RADM configuration. |
required |
processor
|
RADMProcessor | None
|
Optional input/output processor derived from |
None
|
Source code in models/radm/src/radm/pipeline_radm.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |
__call__ ¶
__call__(
images: ImageInput | Sequence[ImageInput] | None = None,
*,
content: Mapping[
str,
ImageInput
| Sequence[ImageInput]
| Float[Tensor, "batch text text_dim"]
| Float[ndarray, "batch text text_dim"]
| Bool[Tensor, "batch text 1"]
| Bool[ndarray, "batch text 1"]
| NestedFloatSequence
| NestedBoolSequence
| JsonValue,
]
| None = None,
text_features: Float[Tensor, "batch text text_dim"]
| Float[ndarray, "batch text text_dim"]
| NestedFloatSequence
| None = None,
text_mask: Bool[Tensor, "batch text 1"]
| Bool[ndarray, "batch text 1"]
| NestedBoolSequence
| 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"]
| Int[ndarray, "batch elements"]
| Sequence[Sequence[int | str]]
| None = None,
bbox: Float[Tensor, "batch elements 4"]
| Float[ndarray, "batch elements 4"]
| Sequence[Sequence[float]]
| None = None,
mask: Bool[Tensor, "batch elements"]
| Bool[ndarray, "batch elements"]
| Sequence[Sequence[bool]]
| None = None,
num_elements: int
| Sequence[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: Literal["dataclass", "dict"] = "dataclass",
return_intermediates: bool = False,
class_threshold: float | None = None,
nms_threshold: float | None = None,
return_raw_predictions: bool = False,
) -> (
LayoutGenerationOutput
| dict[
str,
Float[torch.Tensor, "..."]
| Int[torch.Tensor, "..."]
| Bool[torch.Tensor, "..."]
| Mapping[int, str]
| Mapping[
str,
str
| int
| float
| bool
| None
| Float[torch.Tensor, "..."]
| Int[torch.Tensor, "..."]
| Bool[torch.Tensor, "..."]
| list[Float[torch.Tensor, "..."]],
]
| list[Float[torch.Tensor, "..."]]
| None,
]
)
Generate normalized poster layout boxes and labels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
images
|
ImageInput | Sequence[ImageInput] | None
|
Content image or image batch. |
None
|
content
|
Mapping[str, ImageInput | Sequence[ImageInput] | Float[Tensor, 'batch text text_dim'] | Float[ndarray, 'batch text text_dim'] | Bool[Tensor, 'batch text 1'] | Bool[ndarray, 'batch text 1'] | NestedFloatSequence | NestedBoolSequence | JsonValue] | None
|
Optional content carrier with image and text-feature fields. |
None
|
text_features
|
Float[Tensor, 'batch text text_dim'] | Float[ndarray, 'batch text text_dim'] | NestedFloatSequence | None
|
Optional RADM text feature tensor. |
None
|
text_mask
|
Bool[Tensor, 'batch text 1'] | Bool[ndarray, 'batch text 1'] | NestedBoolSequence | None
|
Optional text-feature mask. |
None
|
batch_size
|
int
|
Batch size for synthetic smoke inputs. |
1
|
seed
|
int | None
|
Optional seed used when |
None
|
generator
|
Generator | None
|
Optional torch generator. Takes precedence over |
None
|
condition_type
|
ConditionType | str
|
Public condition type. RADM supports |
content_image
|
labels
|
Int[Tensor, 'batch elements'] | Int[ndarray, 'batch elements'] | Sequence[Sequence[int | str]] | None
|
Accepted common layout argument; unsupported in the first PR. |
None
|
bbox
|
Float[Tensor, 'batch elements 4'] | Float[ndarray, 'batch elements 4'] | Sequence[Sequence[float]] | None
|
Accepted common layout argument; unsupported in the first PR. |
None
|
mask
|
Bool[Tensor, 'batch elements'] | Bool[ndarray, 'batch elements'] | Sequence[Sequence[bool]] | None
|
Accepted common layout argument; unsupported in the first PR. |
None
|
num_elements
|
int | Sequence[int] | Int[Tensor, 'batch'] | None
|
Accepted common layout argument; unsupported in the first PR. |
None
|
box_format
|
BoxFormat | str
|
Accepted common layout argument. |
xywh
|
normalized
|
bool
|
Accepted common layout argument. |
True
|
canvas_size
|
tuple[int, int] | None
|
Accepted common layout argument. |
None
|
num_inference_steps
|
int | None
|
Number of reverse diffusion steps. |
None
|
output_type
|
Literal['dataclass', 'dict']
|
|
'dataclass'
|
return_intermediates
|
bool
|
Whether to return debug intermediates. |
False
|
class_threshold
|
float | None
|
Optional confidence threshold. |
None
|
nms_threshold
|
float | None
|
Optional NMS threshold. |
None
|
return_raw_predictions
|
bool
|
Whether raw predictions should be included. |
False
|
Returns:
| Type | Description |
|---|---|
LayoutGenerationOutput | dict[str, Float[Tensor, '...'] | Int[Tensor, '...'] | Bool[Tensor, '...'] | Mapping[int, str] | Mapping[str, str | int | float | bool | None | Float[Tensor, '...'] | Int[Tensor, '...'] | Bool[Tensor, '...'] | list[Float[Tensor, '...']]] | list[Float[Tensor, '...']] | None]
|
Layout generation output dataclass or dictionary. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the selected condition is unsupported. |
ValueError
|
If public arguments are unsupported. |
Examples:
>>> from PIL import Image
>>> config = RADMConfig(num_proposals=2, hidden_dim=8, text_feature_dim=4, backbone_depth=18)
>>> pipe = RADMPipeline(
... denoiser=RADMDenoiser(config=config),
... scheduler=RADMScheduler(num_train_timesteps=10, num_inference_steps=2),
... config=config,
... processor=RADMProcessor(config=config),
... )
>>> out = pipe(Image.new("RGB", (16, 16)), seed=0, num_inference_steps=2)
>>> out.bbox.shape[-1]
4
Source code in models/radm/src/radm/pipeline_radm.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 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 | |
save_pretrained ¶
save_pretrained(save_directory: str | Path) -> None
Save pipeline components and RADM config.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
save_directory
|
str | Path
|
Output directory. |
required |
Source code in models/radm/src/radm/pipeline_radm.py
265 266 267 268 269 270 271 272 273 274 275 | |
from_pretrained
classmethod
¶
from_pretrained(
pretrained_model_name_or_path: str | Path,
) -> Self
Load a saved RADM pipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pretrained_model_name_or_path
|
str | Path
|
Local directory or Hub id. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
Loaded RADM pipeline. |
Source code in models/radm/src/radm/pipeline_radm.py
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 | |
RADMProcessor ¶
Bases: ProcessorMixin
Normalize RADM content payloads and decode proposal predictions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_processor
|
RADMImageProcessor | None
|
Image processor for content images. |
None
|
config
|
RADMConfig
|
RADM configuration. |
required |
id2label
|
Mapping[int | str, str] | None
|
Optional public label mapping. |
None
|
Examples:
>>> processor = RADMProcessor(config=RADMConfig(num_proposals=2))
>>> processor.id2label[0]
'logo'
Source code in models/radm/src/radm/processing_radm.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 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 | |
__init__ ¶
__init__(
*,
image_processor: RADMImageProcessor | None = None,
config: RADMConfig,
id2label: Mapping[int | str, str] | None = None,
) -> None
Initialize processor metadata.
Source code in models/radm/src/radm/processing_radm.py
53 54 55 56 57 58 59 60 61 62 63 64 65 | |
save_pretrained ¶
save_pretrained(
save_directory: str | Path,
push_to_hub: bool = False,
**kwargs: Unpack[ProcessingKwargs],
) -> None
Save processor metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
save_directory
|
str | Path
|
Directory receiving processor files. |
required |
push_to_hub
|
bool
|
Accepted for |
False
|
kwargs
|
Unpack[ProcessingKwargs]
|
Accepted for compatibility. |
{}
|
Source code in models/radm/src/radm/processing_radm.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | |
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",
subfolder: str | None = None,
**kwargs: Unpack[ProcessingKwargs],
) -> Self
Load processor metadata from a local pipeline directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pretrained_model_name_or_path
|
str | PathLike[str]
|
Root path or processor subfolder. |
required |
cache_dir
|
str | PathLike[str] | None
|
Accepted for API compatibility. |
None
|
force_download
|
bool
|
Accepted for API compatibility. |
False
|
local_files_only
|
bool
|
Accepted for API compatibility. |
False
|
token
|
str | bool | None
|
Accepted for API compatibility. |
None
|
revision
|
str
|
Accepted for API compatibility. |
'main'
|
subfolder
|
str | None
|
Optional processor subfolder. |
None
|
kwargs
|
Unpack[ProcessingKwargs]
|
Ignored compatibility kwargs. |
{}
|
Returns:
| Type | Description |
|---|---|
Self
|
Loaded RADM processor. |
Source code in models/radm/src/radm/processing_radm.py
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 | |
__call__ ¶
__call__(
images: ImageInput | Sequence[ImageInput] | None = None,
*,
content: Mapping[
str,
ImageInput
| Sequence[ImageInput]
| Float[Tensor, "batch text text_dim"]
| Float[ndarray, "batch text text_dim"]
| Bool[Tensor, "batch text 1"]
| Bool[ndarray, "batch text 1"]
| NestedFloatSequence
| NestedBoolSequence
| JsonValue,
]
| None = None,
text_features: Float[Tensor, "batch text text_dim"]
| Float[ndarray, "batch text text_dim"]
| NestedFloatSequence
| None = None,
text_mask: Bool[Tensor, "batch text 1"]
| Bool[ndarray, "batch text 1"]
| NestedBoolSequence
| None = None,
batch_size: int = 1,
return_tensors: Literal["pt"] = "pt",
**kwargs: Unpack[ProcessingKwargs],
) -> BatchEncoding
Encode public RADM inputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
images
|
ImageInput | Sequence[ImageInput] | None
|
Image or image batch. |
None
|
content
|
Mapping[str, ImageInput | Sequence[ImageInput] | Float[Tensor, 'batch text text_dim'] | Float[ndarray, 'batch text text_dim'] | Bool[Tensor, 'batch text 1'] | Bool[ndarray, 'batch text 1'] | NestedFloatSequence | NestedBoolSequence | JsonValue] | None
|
Optional content carrier with |
None
|
text_features
|
Float[Tensor, 'batch text text_dim'] | Float[ndarray, 'batch text text_dim'] | NestedFloatSequence | None
|
Optional text feature tensor. |
None
|
text_mask
|
Bool[Tensor, 'batch text 1'] | Bool[ndarray, 'batch text 1'] | NestedBoolSequence | None
|
Optional text-feature mask. |
None
|
batch_size
|
int
|
Synthetic batch size used when images are absent. |
1
|
return_tensors
|
Literal['pt']
|
Tensor framework. Only |
'pt'
|
kwargs
|
Unpack[ProcessingKwargs]
|
Ignored compatibility kwargs. |
{}
|
Returns:
| Type | Description |
|---|---|
BatchEncoding
|
Batch encoding with image and text tensors. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no image/content image is supplied. |
Source code in models/radm/src/radm/processing_radm.py
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 | |
validate_condition ¶
validate_condition(
condition_type: ConditionType | str,
) -> ConditionType
Normalize and validate RADM condition mode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
condition_type
|
ConditionType | str
|
Public condition name or alias. |
required |
Returns:
| Type | Description |
|---|---|
ConditionType
|
|
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If RADM does not support the condition. |
Source code in models/radm/src/radm/processing_radm.py
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |
decode ¶
decode(
*,
boxes_xyxy: Float[Tensor, "batch proposals 4"],
logits: Float[Tensor, "batch proposals classes"],
class_threshold: float,
nms_threshold: float,
output_type: Literal["dataclass", "dict"] = "dataclass",
return_intermediates: bool = False,
extra_intermediates: Mapping[
str,
str
| int
| float
| bool
| None
| Float[Tensor, "..."]
| Int[Tensor, "..."]
| Bool[Tensor, "..."]
| list[Float[Tensor, "..."]],
]
| None = None,
) -> (
LayoutGenerationOutput
| dict[
str,
Float[torch.Tensor, "..."]
| Int[torch.Tensor, "..."]
| Bool[torch.Tensor, "..."]
| Mapping[int, str]
| Mapping[
str,
str
| int
| float
| bool
| None
| Float[torch.Tensor, "..."]
| Int[torch.Tensor, "..."]
| Bool[torch.Tensor, "..."]
| list[Float[torch.Tensor, "..."]],
]
| list[Float[torch.Tensor, "..."]]
| None,
]
)
Decode denoiser predictions into the common layout schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
boxes_xyxy
|
Float[Tensor, 'batch proposals 4']
|
Normalized proposal boxes. |
required |
logits
|
Float[Tensor, 'batch proposals classes']
|
Class logits. |
required |
class_threshold
|
float
|
Confidence threshold. |
required |
nms_threshold
|
float
|
NMS threshold. |
required |
output_type
|
Literal['dataclass', 'dict']
|
Output container selector. |
'dataclass'
|
return_intermediates
|
bool
|
Whether to include raw predictions. |
False
|
extra_intermediates
|
Mapping[str, str | int | float | bool | None | Float[Tensor, '...'] | Int[Tensor, '...'] | Bool[Tensor, '...'] | list[Float[Tensor, '...']]] | None
|
Optional debug metadata. |
None
|
Returns:
| Type | Description |
|---|---|
LayoutGenerationOutput | dict[str, Float[Tensor, '...'] | Int[Tensor, '...'] | Bool[Tensor, '...'] | Mapping[int, str] | Mapping[str, str | int | float | bool | None | Float[Tensor, '...'] | Int[Tensor, '...'] | Bool[Tensor, '...'] | list[Float[Tensor, '...']]] | list[Float[Tensor, '...']] | None]
|
Layout output dataclass or dictionary. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in models/radm/src/radm/processing_radm.py
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 | |
RADMScheduler ¶
Bases: SchedulerMixin, ConfigMixin
DDIM-style scheduler for RADM's scaled proposal latents.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_train_timesteps
|
int
|
Number of training diffusion timesteps. |
1000
|
num_inference_steps
|
int
|
Default inference step count. |
50
|
beta_schedule
|
Literal['cosine']
|
Schedule name. Only |
'cosine'
|
eta
|
float
|
DDIM stochasticity parameter. |
1.0
|
prediction_type
|
Literal['sample']
|
Model prediction type. |
'sample'
|
snr_scale
|
float
|
Scaling applied to the latent at the model boundary. |
2.0
|
Examples:
>>> scheduler = RADMScheduler(num_train_timesteps=10, num_inference_steps=3)
>>> scheduler.set_timesteps(3)
>>> scheduler.timesteps.tolist()
[9, 5, 2]
Source code in models/radm/src/radm/scheduling_radm.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 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 | |
__init__ ¶
__init__(
num_train_timesteps: int = 1000,
num_inference_steps: int = 50,
beta_schedule: Literal["cosine"] = "cosine",
eta: float = 1.0,
prediction_type: Literal["sample"] = "sample",
snr_scale: float = 2.0,
) -> None
Initialize RADM scheduler metadata.
Source code in models/radm/src/radm/scheduling_radm.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 93 94 95 96 | |
set_timesteps ¶
set_timesteps(
num_inference_steps: int | None = None,
*,
device: device | str | None = None,
) -> None
Set reversed inference timesteps.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_inference_steps
|
int | None
|
Optional step count. |
None
|
device
|
device | str | None
|
Optional target device. |
None
|
Source code in models/radm/src/radm/scheduling_radm.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
sample_initial_proposals ¶
sample_initial_proposals(
*,
batch_size: int,
num_proposals: int,
generator: Generator | None = None,
device: device | str | None = None,
dtype: dtype = torch.float32,
) -> Float[torch.Tensor, "batch proposals 4"]
Sample the source-effective unbounded Gaussian proposal latents.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch_size
|
int
|
Number of examples. |
required |
num_proposals
|
int
|
Number of proposal boxes. |
required |
generator
|
Generator | None
|
Optional random generator. |
None
|
device
|
device | str | None
|
Output device. |
None
|
dtype
|
dtype
|
Output dtype. |
float32
|
Returns:
| Type | Description |
|---|---|
Float[Tensor, 'batch proposals 4']
|
Raw Gaussian proposal latents in source |
Source code in models/radm/src/radm/scheduling_radm.py
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 | |
latent_to_normalized_boxes ¶
latent_to_normalized_boxes(
sample: Float[Tensor, "batch proposals 4"],
) -> Float[torch.Tensor, "batch proposals 4"]
Convert a scaled source latent to normalized xyxy boxes.
Source code in models/radm/src/radm/scheduling_radm.py
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
normalized_boxes_to_latent ¶
normalized_boxes_to_latent(
boxes_xyxy: Float[Tensor, "batch proposals 4"],
) -> Float[torch.Tensor, "batch proposals 4"]
Convert normalized xyxy model output to a scaled source latent.
Source code in models/radm/src/radm/scheduling_radm.py
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | |
scale_model_input ¶
scale_model_input(
sample: Float[Tensor, "batch proposals 4"],
timestep: Float[Tensor, ""] | float,
) -> Float[torch.Tensor, "batch proposals 4"]
Return sample unchanged for Diffusers scheduler compatibility.
Source code in models/radm/src/radm/scheduling_radm.py
182 183 184 185 186 187 188 189 | |
predict_noise_from_start ¶
predict_noise_from_start(
sample: Float[Tensor, "batch proposals 4"],
timestep: Int[Tensor, "batch"] | Int[Tensor, ""] | int,
pred_original_sample: Float[
Tensor, "batch proposals 4"
],
) -> Float[torch.Tensor, "batch proposals 4"]
Return the noise implied by x_t and predicted x_0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sample
|
Float[Tensor, 'batch proposals 4']
|
Current latent sample. |
required |
timestep
|
Int[Tensor, 'batch'] | Int[Tensor, ''] | int
|
Training timestep indices. |
required |
pred_original_sample
|
Float[Tensor, 'batch proposals 4']
|
Predicted denoised sample. |
required |
Returns:
| Type | Description |
|---|---|
Float[Tensor, 'batch proposals 4']
|
Predicted noise tensor. |
Source code in models/radm/src/radm/scheduling_radm.py
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 | |
q_sample ¶
q_sample(
x_start: Float[Tensor, "batch proposals 4"],
timestep: Int[Tensor, "batch"] | Int[Tensor, ""] | int,
noise: Float[Tensor, "batch proposals 4"] | None = None,
) -> Float[torch.Tensor, "batch proposals 4"]
Diffuse x_start to x_t with the RADM forward process.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x_start
|
Float[Tensor, 'batch proposals 4']
|
Initial clean sample. |
required |
timestep
|
Int[Tensor, 'batch'] | Int[Tensor, ''] | int
|
Training timestep indices. |
required |
noise
|
Float[Tensor, 'batch proposals 4'] | None
|
Optional fixed noise tensor. |
None
|
Returns:
| Type | Description |
|---|---|
Float[Tensor, 'batch proposals 4']
|
Noised sample at |
Source code in models/radm/src/radm/scheduling_radm.py
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 | |
step ¶
step(
model_output: Float[Tensor, "batch proposals 4"],
timestep: Int[Tensor, ""] | int,
sample: Float[Tensor, "batch proposals 4"],
*,
generator: Generator | None = None,
return_dict: Literal[True] = True,
) -> RADMSchedulerOutput
step(
model_output: Float[Tensor, "batch proposals 4"],
timestep: Int[Tensor, ""] | int,
sample: Float[Tensor, "batch proposals 4"],
*,
generator: Generator | None = None,
return_dict: Literal[False],
) -> tuple[
Float[torch.Tensor, "batch proposals 4"],
Float[torch.Tensor, "batch proposals 4"],
]
step(
model_output: Float[Tensor, "batch proposals 4"],
timestep: Int[Tensor, ""] | int,
sample: Float[Tensor, "batch proposals 4"],
*,
generator: Generator | None = None,
return_dict: bool = True,
) -> (
RADMSchedulerOutput
| tuple[
Float[torch.Tensor, "batch proposals 4"],
Float[torch.Tensor, "batch proposals 4"],
]
)
Advance one reverse-diffusion step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_output
|
Float[Tensor, 'batch proposals 4']
|
Predicted denoised sample. |
required |
timestep
|
Int[Tensor, ''] | int
|
Current training timestep. |
required |
sample
|
Float[Tensor, 'batch proposals 4']
|
Current proposal sample. |
required |
generator
|
Generator | None
|
Optional generator for DDIM noise. |
None
|
return_dict
|
bool
|
Whether to return a dataclass. |
True
|
Returns:
| Type | Description |
|---|---|
RADMSchedulerOutput | tuple[Float[Tensor, 'batch proposals 4'], Float[Tensor, 'batch proposals 4']]
|
Scheduler output dataclass or tuple. |
Source code in models/radm/src/radm/scheduling_radm.py
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 | |
posterior_mean_variance ¶
posterior_mean_variance(
x_start: Float[Tensor, "batch proposals 4"],
sample: Float[Tensor, "batch proposals 4"],
timestep: Int[Tensor, "batch"] | Int[Tensor, ""] | int,
) -> tuple[
Float[torch.Tensor, "batch proposals 4"],
Float[torch.Tensor, "batch proposals 4"],
Float[torch.Tensor, "batch proposals 4"],
]
Return RADM posterior mean, variance, and clipped log variance.
Source code in models/radm/src/radm/scheduling_radm.py
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 | |
RADMSchedulerOutput
dataclass
¶
Bases: BaseOutput
Output of one RADM scheduler step.
Source code in models/radm/src/radm/scheduling_radm.py
17 18 19 20 21 22 23 | |
default_id2label ¶
default_id2label(
dataset_name: DatasetName | str = DatasetName.cgl,
*,
label_mode: RADMLabelMode | str = RADMLabelMode.english,
) -> dict[int, str]
Return the public RADM label mapping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_name
|
DatasetName | str
|
Poster dataset name or alias. |
cgl
|
label_mode
|
RADMLabelMode | str
|
|
english
|
Returns:
| Type | Description |
|---|---|
dict[int, str]
|
Integer label ids mapped to display names. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the dataset or label mode is unsupported. |
Examples:
>>> default_id2label("cgl")[0]
'logo'
>>> default_id2label("cgl", label_mode="original")[1]
'æ–‡å—'
Source code in models/radm/src/radm/configuration_radm.py
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 | |
evaluate_checkpoint ¶
evaluate_checkpoint(
checkpoint_path: str | Path,
*,
config: RADMConfig,
effective: "RADMEffectiveConfig",
data_module: "RADMDataModule",
output_dir: str | Path | None = None,
device: str | device = "cpu",
seed: int = 1,
num_inference_steps: int | None = None,
class_threshold: float = 0.25,
nms_threshold: float = 0.15,
max_samples: int | None = None,
) -> CocoEvaluationReport
Load a Lightning checkpoint and evaluate its CGL test predictions.
Source code in models/radm/src/radm/evaluation.py
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 | |
evaluate_cgl_predictions ¶
evaluate_cgl_predictions(
annotation_path: str | Path,
predictions: Sequence[
Mapping[str, CocoPredictionValue]
],
*,
output_dir: str | Path | None = None,
image_ids: Sequence[int] | None = None,
) -> CocoEvaluationReport
Compute the COCO bbox metrics used by the CGL evaluation entrypoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
annotation_path
|
str | Path
|
COCO annotation JSON for the evaluated split. |
required |
predictions
|
Sequence[Mapping[str, CocoPredictionValue]]
|
COCO detection records with |
required |
output_dir
|
str | Path | None
|
Optional directory for the COCO result and metric files. |
None
|
image_ids
|
Sequence[int] | None
|
Optional subset evaluated by the result comparison. |
None
|
Returns:
| Type | Description |
|---|---|
CocoEvaluationReport
|
A JSON-serializable report with |
Raises:
| Type | Description |
|---|---|
ImportError
|
If the optional COCO API is not installed. |
Source code in models/radm/src/radm/evaluation.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 184 185 186 187 188 189 190 191 192 193 194 195 196 | |
layout_predictions_to_coco ¶
layout_predictions_to_coco(
*,
image_ids: Sequence[int],
boxes_xyxy: Float[Tensor, "batch proposals 4"],
labels: Int[Tensor, "batch proposals"],
mask: Bool[Tensor, "batch proposals"],
scores: Float[Tensor, "batch proposals"],
image_scales: Float[Tensor, "batch 4"],
original_image_scales: Float[Tensor, "batch 4"],
model_image_scales: Float[Tensor, "batch 4"]
| None = None,
boxes_are_absolute: bool = False,
category_id_map: Mapping[int, int] | None = None,
) -> list[CocoPrediction]
Convert selected normalized boxes into COCO detection records.
The CGL annotations use one-based contiguous category ids, while the public
RADM prediction tensors use zero-based ids. category_id_map is
available for datasets with a different explicit COCO category mapping.
Source code in models/radm/src/radm/evaluation.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 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 | |
options: show_submodules: true