(self, cfg: FlowPredictorGMFlowCfg)
| 26 | |
| 27 | class FlowPredictorGMFlow(FlowPredictor[FlowPredictorGMFlowCfg]): |
| 28 | def __init__(self, cfg: FlowPredictorGMFlowCfg) -> None: |
| 29 | super().__init__(cfg) |
| 30 | |
| 31 | # Warn that GMFlow isn't installed. |
| 32 | if GMFlow is None: |
| 33 | print( |
| 34 | "Warning: GMFlow could not be imported. Did you forget to initialize " |
| 35 | "the git submodules?" |
| 36 | ) |
| 37 | sys.exit(1) |
| 38 | |
| 39 | # Ensure that the checkpoint exists. |
| 40 | checkpoint = "gmflow-scale1-mixdata-train320x576-4c3a6e9a.pth" |
| 41 | checkpoint_path = cfg.cache_path / checkpoint |
| 42 | if not checkpoint_path.exists(): |
| 43 | checkpoint_path.parent.mkdir(exist_ok=True, parents=True) |
| 44 | print("Downloading GMFlow checkpoint.") |
| 45 | urllib.request.urlretrieve( |
| 46 | f"https://s3.eu-central-1.amazonaws.com/avg-projects/unimatch/pretrained/{checkpoint}", |
| 47 | checkpoint_path, |
| 48 | ) |
| 49 | |
| 50 | # Set up the model. |
| 51 | self.model = GMFlow( |
| 52 | feature_channels=128, |
| 53 | num_scales=1, |
| 54 | upsample_factor=8, |
| 55 | num_head=1, |
| 56 | attention_type="swin", |
| 57 | ffn_dim_expansion=4, |
| 58 | num_transformer_layers=6, |
| 59 | ) |
| 60 | |
| 61 | # Load the pre-trained checkpoint. |
| 62 | checkpoint = torch.load(checkpoint_path) |
| 63 | weights = checkpoint["model"] if "model" in checkpoint else checkpoint |
| 64 | self.model.load_state_dict(weights, strict=False) |
| 65 | |
| 66 | def forward( |
| 67 | self, |
nothing calls this directly
no outgoing calls
no test coverage detected