-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
96 lines (81 loc) · 3.33 KB
/
models.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
'''
Use of ResNet models written in architecture.py
'''
# import libraries
import architectures
import torch
def ResNet18(img_channels, num_classes, device='cuda', use_final=True):
'''
Using the architectures to build a resnet18 model
'''
# raising an error for not entering true parameters to the function
if use_final and num_classes is None:
raise Exception('when use_final is set to true, it is necessary to give an integer value to num_classes')
# define the model under different conditions
model = architectures.SmallResNet(
num_layers=[2, 2, 2, 2],
img_channels=img_channels,
num_classes=num_classes if use_final else None,
use_final=use_final
).to(device=device)
return model
def ResNet32(img_channels, num_classes, device='cuda', use_final=True):
'''
Using the architectures to build a resnet32 model
'''
# raising an error for not entering true parameters to the function
if use_final and num_classes is None:
raise Exception('when use_final is set to true, it is necessary to give an integer value to num_classes')
# define the model under different conditions
model = architectures.SmallResNet(
num_layers=[3, 4, 6, 3],
img_channels=img_channels,
num_classes=num_classes if use_final else None,
use_final=use_final
).to(device=device)
return model
def ResNet50(img_channels, num_classes, device='cuda', use_final=True):
'''
Using the architectures to build a resnet50 model
'''
# raising an error for not entering true parameters to the function
if use_final and num_classes is None:
raise Exception('when use_final is set to true, it is necessary to give an integer value to num_classes')
# define the model under different conditions
model = architectures.LargeResNet(
num_blocks=[3, 4, 6, 3],
img_channels=img_channels,
num_classes=num_classes if use_final else None,
use_final=use_final
).to(device=device)
return model
def ResNet101(img_channels, num_classes, device='cuda', use_final=True):
'''
Using the architectures to build a resnet101 model
'''
# raising an error for not entering true parameters to the function
if use_final and num_classes is None:
raise Exception('when use_final is set to true, it is necessary to give an integer value to num_classes')
# define the model under different conditions
model = architectures.LargeResNet(
num_blocks=[3, 4, 23, 3],
img_channels=img_channels,
num_classes=num_classes if use_final else None,
use_final=use_final
).to(device=device)
return model
def ResNet152(img_channels, num_classes, device='cuda', use_final=True):
'''
Using the architectures to build a resnet152 model
'''
# raising an error for not entering true parameters to the function
if use_final and num_classes is None:
raise Exception('when use_final is set to true, it is necessary to give an integer value to num_classes')
# define the model under different conditions
model = architectures.LargeResNet(
num_blocks=[3, 8, 36, 3],
img_channels=img_channels,
num_classes=num_classes if use_final else None,
use_final=use_final
).to(device=device)
return model