-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel.py
69 lines (54 loc) · 1.92 KB
/
model.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
import torch
from torchvision.models.detection.faster_rcnn import fasterrcnn_resnet50_fpn, fasterrcnn_mobilenet_v3_large_fpn, fasterrcnn_mobilenet_v3_large_320_fpn, FasterRCNN_ResNet50_FPN_Weights, FasterRCNN_MobileNet_V3_Large_FPN_Weights, FasterRCNN_MobileNet_V3_Large_320_FPN_Weights
from constants import num_classes
def get_new_model_resnet101():
model = torch.hub.load('pytorch/vision:v0.14.1', 'resnet101', pretrained=True)
return model
def get_new_model_fasterrcnn(pretrained=False):
"""get Faster R-CNN model
Paremeters
----------
pretrained : bool
whether the model should be pre-trained with COCO
Returns
-------
nn.Module
model
"""
if pretrained:
model = fasterrcnn_resnet50_fpn(num_classes=91, weights=FasterRCNN_ResNet50_FPN_Weights.DEFAULT)
else:
model = fasterrcnn_resnet50_fpn(num_classes=num_classes)
return model
def get_new_model_mobilenet(pretrained=False):
"""get MobileNetV3 model
Paremeters
----------
pretrained : bool
whether the model should be pre-trained with COCO
Returns
-------
nn.Module
model
"""
if pretrained:
model = fasterrcnn_mobilenet_v3_large_fpn(num_classes=91, weights=FasterRCNN_MobileNet_V3_Large_FPN_Weights.DEFAULT)
else:
model = fasterrcnn_mobilenet_v3_large_fpn(num_classes=num_classes)
return model
def get_new_model_mobilenet_320(pretrained=False):
"""get MobileNetV3 fine tuned for mobile use cases model
Paremeters
----------
pretrained : bool
whether the model should be pre-trained with COCO
Returns
-------
nn.Module
model
"""
if pretrained:
model = fasterrcnn_mobilenet_v3_large_320_fpn(num_classes=91, weights=FasterRCNN_MobileNet_V3_Large_320_FPN_Weights.DEFAULT)
else:
model = fasterrcnn_mobilenet_v3_large_320_fpn(num_classes=num_classes)
return model