clip.marsclip_mae¶
marsclip_mae ¶
Stage A masked autoencoder components for MarsCLIP.
MarsMaskedAutoencoder ¶
MarsMaskedAutoencoder(*, image_size: int = 224, patch_size: int = 16, in_channels: int = 3, encoder_dim: int = 256, encoder_depth: int = 4, encoder_heads: int = 8, decoder_dim: int = 128, decoder_depth: int = 2, decoder_heads: int = 4, min_valid_fraction: float = DEFAULT_PATCH_VALID_FRACTION, normalize_inputs: bool = False, normalize_targets: bool = False, input_mean: Sequence[float] | Tensor | None = None, input_std: Sequence[float] | Tensor | None = None)
Bases: Module
Workflow-aligned Stage A masked autoencoder for MarsCLIP.
Source code in src/clip/marsclip_mae.py
forward_patch_batch ¶
forward_patch_batch(batch: dict[str, Any], *, mask_ratio: float = 0.75, generator: Generator | None = None) -> MarsMAEOutput
Run Stage A directly on a collated MarsCLIP patch batch.
Source code in src/clip/marsclip_mae.py
patchify ¶
Convert an image batch (B, C, H, W) into flattened patch vectors.
Source code in src/clip/marsclip_mae.py
unpatchify ¶
unpatchify(patches: Tensor, patch_size: int, *, channels: int, image_size: int | tuple[int, int] | None = None) -> torch.Tensor
Rebuild an image batch (B, C, H, W) from flattened patch vectors.
Source code in src/clip/marsclip_mae.py
expand_patch_mask ¶
expand_patch_mask(patch_mask: Tensor, patch_size: int, *, image_size: int | tuple[int, int] | None = None) -> torch.Tensor
Expand a patch mask (B, N) back to an image mask (B, H, W).
Source code in src/clip/marsclip_mae.py
compute_patch_valid_fraction ¶
Compute the valid-pixel fraction for each patch in a mask batch.
Source code in src/clip/marsclip_mae.py
compute_valid_patch_mask ¶
compute_valid_patch_mask(valid_mask: Tensor, patch_size: int, *, min_valid_fraction: float = DEFAULT_PATCH_VALID_FRACTION) -> torch.Tensor
Mark patches as valid only when their valid-pixel fraction clears a threshold.
Source code in src/clip/marsclip_mae.py
extract_scale_values ¶
Extract the Stage A scalar scale input from patch scale_features.
Source code in src/clip/marsclip_mae.py
normalize_valid_image ¶
normalize_valid_image(image: Tensor, valid_mask: Tensor, *, channel_mean: Sequence[float] | Tensor, channel_std: Sequence[float] | Tensor, eps: float = 1e-06) -> torch.Tensor
Normalize valid pixels channel-wise while keeping invalid pixels at zero.
Source code in src/clip/marsclip_mae.py
denormalize_patch_tokens ¶
denormalize_patch_tokens(patches: Tensor, *, patch_size: int, channels: int, channel_mean: Sequence[float] | Tensor, channel_std: Sequence[float] | Tensor, eps: float = 1e-06) -> torch.Tensor
Map normalized patch tokens back into the original channel scale.
Source code in src/clip/marsclip_mae.py
collate_patch_samples_for_mae ¶
Collate Stage A1 patch samples into a MAE-ready batch dictionary.
Source code in src/clip/marsclip_mae.py
build_masked_input_image ¶
build_masked_input_image(image: Tensor, patch_valid_mask: Tensor, visible_mask: Tensor, *, patch_size: int) -> torch.Tensor
Render the visible-token input image used by the MAE encoder.
Source code in src/clip/marsclip_mae.py
build_reconstruction_composite ¶
build_reconstruction_composite(image: Tensor, reconstruction: Tensor, patch_valid_mask: Tensor, visible_mask: Tensor, *, patch_size: int) -> tuple[torch.Tensor, torch.Tensor]
Build full reconstructed images and visible+reconstructed composites.
Source code in src/clip/marsclip_mae.py
sample_visible_patch_mask ¶
sample_visible_patch_mask(patch_valid_mask: Tensor, mask_ratio: float, generator: Generator | None = None) -> torch.Tensor
Select visible patches from the valid patch set for MAE encoding.
Source code in src/clip/marsclip_mae.py
scale_sinusoidal_encoding ¶
Encode physical scale values using ScaleMAE-style sinusoidal features.