-
Notifications
You must be signed in to change notification settings - Fork 2
/
fcn.py
103 lines (71 loc) · 2.64 KB
/
fcn.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
from cvm import models
from ..utils import export, get_out_channels, load_from_local_or_url
from .heads import ClsHead, FCNHead
from typing import Any
from .segmentation_model import SegmentationModel
@export
class FCN(SegmentationModel):
...
@export
def create_fcn(
backbone: str = 'resnet50_v1',
num_classes: int = 21,
aux_loss: bool = False,
cls_loss: bool = False,
dropout_rate: float = 0.1,
pretrained_backbone: bool = False,
pretrained: bool = False,
pth: str = None,
progress: bool = True,
**kwargs: Any
):
if pretrained:
pretrained_backbone = False
backbone = models.__dict__[backbone](
pretrained=pretrained_backbone,
dilations=[1, 1, 2, 4],
**kwargs
).features
aux_head = FCNHead(get_out_channels(backbone.stage3), None, num_classes, dropout_rate) if aux_loss else None
cls_head = ClsHead(get_out_channels(backbone.stage4), num_classes) if cls_loss else None
decode_head = FCNHead(get_out_channels(backbone.stage4), None, num_classes, dropout_rate)
model = FCN(backbone, [3, 4] if aux_loss else [4], decode_head, aux_head, cls_head)
if pretrained:
load_from_local_or_url(model, pth, kwargs.get('url', None), progress)
return model
@export
def fcn_resnet50_v1(*args, **kwargs: Any):
return create_fcn('resnet50_v1', *args, **kwargs)
@export
def fcn_mobilenet_v3_small(*args, **kwargs: Any):
return create_fcn('mobilenet_v3_small', *args, **kwargs)
@export
def fcn_mobilenet_v3_large(*args, **kwargs: Any):
return create_fcn('mobilenet_v3_large', *args, **kwargs)
@export
def fcn_regnet_x_400mf(*args, **kwargs: Any):
return create_fcn('regnet_x_400mf', *args, **kwargs)
@export
def fcn_mobilenet_v1_x1_0(*args, **kwargs: Any):
return create_fcn('mobilenet_v1_x1_0', *args, **kwargs)
@export
def fcn_sd_mobilenet_v1_x1_0(*args, **kwargs: Any):
return create_fcn('sd_mobilenet_v1_x1_0', *args, **kwargs)
@export
def fcn_mobilenet_v2_x1_0(*args, **kwargs: Any):
return create_fcn('mobilenet_v2_x1_0', *args, **kwargs)
@export
def fcn_sd_mobilenet_v2_x1_0(*args, **kwargs: Any):
return create_fcn('sd_mobilenet_v2_x1_0', *args, **kwargs)
@export
def fcn_shufflenet_v2_x2_0(*args, **kwargs: Any):
return create_fcn('shufflenet_v2_x2_0', *args, **kwargs)
@export
def fcn_sd_shufflenet_v2_x2_0(*args, **kwargs: Any):
return create_fcn('sd_shufflenet_v2_x2_0', *args, **kwargs)
@export
def fcn_efficientnet_b0(*args, **kwargs: Any):
return create_fcn('efficientnet_b0', *args, **kwargs)
@export
def fcn_sd_efficientnet_b0(*args, **kwargs: Any):
return create_fcn('sd_efficientnet_b0', *args, **kwargs)