MCPcopy Create free account
hub / github.com/VisionXLab/OF-Diff / DPT

Class DPT

ldm/modules/midas/midas/dpt_depth.py:26–85  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24
25
26class DPT(BaseModel):
27 def __init__(
28 self,
29 head,
30 features=256,
31 backbone="vitb_rn50_384",
32 readout="project",
33 channels_last=False,
34 use_bn=False,
35 ):
36
37 super(DPT, self).__init__()
38
39 self.channels_last = channels_last
40
41 hooks = {
42 "vitb_rn50_384": [0, 1, 8, 11],
43 "vitb16_384": [2, 5, 8, 11],
44 "vitl16_384": [5, 11, 17, 23],
45 }
46
47 # Instantiate backbone and reassemble blocks
48 self.pretrained, self.scratch = _make_encoder(
49 backbone,
50 features,
51 False, # Set to true of you want to train from scratch, uses ImageNet weights
52 groups=1,
53 expand=False,
54 exportable=False,
55 hooks=hooks[backbone],
56 use_readout=readout,
57 )
58
59 self.scratch.refinenet1 = _make_fusion_block(features, use_bn)
60 self.scratch.refinenet2 = _make_fusion_block(features, use_bn)
61 self.scratch.refinenet3 = _make_fusion_block(features, use_bn)
62 self.scratch.refinenet4 = _make_fusion_block(features, use_bn)
63
64 self.scratch.output_conv = head
65
66
67 def forward(self, x):
68 if self.channels_last == True:
69 x.contiguous(memory_format=torch.channels_last)
70
71 layer_1, layer_2, layer_3, layer_4 = forward_vit(self.pretrained, x)
72
73 layer_1_rn = self.scratch.layer1_rn(layer_1)
74 layer_2_rn = self.scratch.layer2_rn(layer_2)
75 layer_3_rn = self.scratch.layer3_rn(layer_3)
76 layer_4_rn = self.scratch.layer4_rn(layer_4)
77
78 path_4 = self.scratch.refinenet4(layer_4_rn)
79 path_3 = self.scratch.refinenet3(path_4, layer_3_rn)
80 path_2 = self.scratch.refinenet2(path_3, layer_2_rn)
81 path_1 = self.scratch.refinenet1(path_2, layer_1_rn)
82
83 out = self.scratch.output_conv(path_1)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected