GigaTIME-flash is a lightweight model that converts H&E [B, 3, 256, 256] tiles into 23-channel virtual multiplex IF (mIF) maps [B, 23, 256, 256].
To use it, you must:
- Set your HuggingFace read-only token as an environment variable.
- Download the model weights and configuration from HuggingFace.
- Initialize the
GigaTIMEFlash model architecture. - Remap the checkpoint keys to match the model's internal structure (handling
module., .base_layer., and encoder. prefixes). - Preprocess H&E tiles using
preprocess_tile and run them through do_inference.
export HF_TOKEN=<huggingface read-only token>
from huggingface_hub import snapshot_download
import torch
import os
repo_id = "prov-gigatime/GigaTIME-flash"
local_dir = snapshot_download(repo_id=repo_id)
weights_path = os.path.join(local_dir, "model.pth")
# Initialize model architecture
model = GigaTIMEFlash(num_classes=23)
# Load and remap weights
checkpoint = torch.load(weights_path, map_location="cpu")
if isinstance(checkpoint, dict) and "state_dict" in checkpoint:
checkpoint = checkpoint["state_dict"]
model_state = model.state_dict()
loaded = {}
for key, value in checkpoint.items():
candidates = [key]
if key.startswith("module."):
candidates.append(key[len("module."):])
if ".base_layer." in key:
candidates.append(key.replace(".base_layer.", "."))
if key.startswith("encoder.") and not key.startswith("encoder.base_model.model."):
candidates.append(key.replace("encoder.", "encoder.base_model.model.", 1))
for candidate in candidates:
if candidate in model_state and model_state[candidate].shape == value.shape:
loaded[candidate] = value
break
model.load_state_dict(loaded, strict=False)
model.to(device).eval()