Network for monocular depth estimation.
| 10 | |
| 11 | |
| 12 | class MidasNet_small(BaseModel): |
| 13 | """Network for monocular depth estimation. |
| 14 | """ |
| 15 | |
| 16 | def __init__(self, path=None, features=64, backbone="efficientnet_lite3", non_negative=True, exportable=True, channels_last=False, align_corners=True, |
| 17 | blocks={'expand': True}): |
| 18 | """Init. |
| 19 | |
| 20 | Args: |
| 21 | path (str, optional): Path to saved model. Defaults to None. |
| 22 | features (int, optional): Number of features. Defaults to 256. |
| 23 | backbone (str, optional): Backbone network for encoder. Defaults to resnet50 |
| 24 | """ |
| 25 | print("Loading weights: ", path) |
| 26 | |
| 27 | super(MidasNet_small, self).__init__() |
| 28 | |
| 29 | use_pretrained = False if path else True |
| 30 | |
| 31 | self.channels_last = channels_last |
| 32 | self.blocks = blocks |
| 33 | self.backbone = backbone |
| 34 | |
| 35 | self.groups = 1 |
| 36 | |
| 37 | features1=features |
| 38 | features2=features |
| 39 | features3=features |
| 40 | features4=features |
| 41 | self.expand = False |
| 42 | if "expand" in self.blocks and self.blocks['expand'] == True: |
| 43 | self.expand = True |
| 44 | features1=features |
| 45 | features2=features*2 |
| 46 | features3=features*4 |
| 47 | features4=features*8 |
| 48 | |
| 49 | self.pretrained, self.scratch = _make_encoder(self.backbone, features, use_pretrained, groups=self.groups, expand=self.expand, exportable=exportable) |
| 50 | |
| 51 | self.scratch.activation = nn.ReLU(False) |
| 52 | |
| 53 | self.scratch.refinenet4 = FeatureFusionBlock_custom(features4, self.scratch.activation, deconv=False, bn=False, expand=self.expand, align_corners=align_corners) |
| 54 | self.scratch.refinenet3 = FeatureFusionBlock_custom(features3, self.scratch.activation, deconv=False, bn=False, expand=self.expand, align_corners=align_corners) |
| 55 | self.scratch.refinenet2 = FeatureFusionBlock_custom(features2, self.scratch.activation, deconv=False, bn=False, expand=self.expand, align_corners=align_corners) |
| 56 | self.scratch.refinenet1 = FeatureFusionBlock_custom(features1, self.scratch.activation, deconv=False, bn=False, align_corners=align_corners) |
| 57 | |
| 58 | |
| 59 | self.scratch.output_conv = nn.Sequential( |
| 60 | nn.Conv2d(features, features//2, kernel_size=3, stride=1, padding=1, groups=self.groups), |
| 61 | Interpolate(scale_factor=2, mode="bilinear"), |
| 62 | nn.Conv2d(features//2, 32, kernel_size=3, stride=1, padding=1), |
| 63 | self.scratch.activation, |
| 64 | nn.Conv2d(32, 1, kernel_size=1, stride=1, padding=0), |
| 65 | nn.ReLU(True) if non_negative else nn.Identity(), |
| 66 | nn.Identity(), |
| 67 | ) |
| 68 | |
| 69 | if path: |
no outgoing calls
no test coverage detected