-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharchitectures.py
37 lines (32 loc) · 1.41 KB
/
architectures.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
# ******************************************************************************
import torch
from torchvision.models.resnet import resnet50,resnet18
import torch.backends.cudnn as cudnn
from archs.cifar_resnet import resnet as resnet_cifar
from archs.ham_resnet import resnet as resnet_ham
from datasets import get_normalize_layer
from torch.nn.functional import interpolate
import pdb
ARCHITECTURES = ["resnet50","resnet18", "cifar_resnet20","cifar_resnet56", "cifar_resnet110"]
def get_architecture(arch: str, dataset: str) -> torch.nn.Module:
""" Return a neural network (with random weights)
:param arch: the architecture - should be in the ARCHITECTURES list above
:param dataset: the dataset - should be in the datasets.DATASETS list
:return: a Pytorch module
"""
if dataset == 'ham':
model = resnet_ham().cuda()
return model
elif dataset == 'imagenette':
model = resnet_ham().cuda()
return model
elif dataset == 'cifar10':
if arch == "cifar_resnet20":
model = resnet_cifar(depth=20, num_classes=10).cuda()
elif arch == "cifar_resnet110":
model = resnet_cifar(depth=110, num_classes=10).cuda()
elif arch == "cifar_resnet56":
model = resnet_cifar(depth=56, num_classes = 10).cuda()
normalize_layer = get_normalize_layer(dataset)
return torch.nn.Sequential(normalize_layer, model)
# return model