MCPcopy Create free account
hub / github.com/dcharatan/flowmap / __init__

Method __init__

flowmap/flow/flow_predictor_gmflow.py:28–64  ·  view source on GitHub ↗
(self, cfg: FlowPredictorGMFlowCfg)

Source from the content-addressed store, hash-verified

26
27class 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,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected