forked from gjy3035/C-3-Framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
train.py
63 lines (54 loc) · 2.01 KB
/
train.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
import os
import numpy as np
import torch
from config import cfg
#------------prepare enviroment------------
seed = cfg.SEED
if seed is not None:
np.random.seed(seed)
torch.manual_seed(seed)
torch.cuda.manual_seed(seed)
gpus = cfg.GPU_ID
if len(gpus)==1:
torch.cuda.set_device(gpus[0])
torch.backends.cudnn.benchmark = True
#------------prepare data loader------------
data_mode = cfg.DATASET
if data_mode is 'SHHA':
from datasets.SHHA.loading_data import loading_data
from datasets.SHHA.setting import cfg_data
elif data_mode is 'SHHB':
from datasets.SHHB.loading_data import loading_data
from datasets.SHHB.setting import cfg_data
elif data_mode is 'QNRF':
from datasets.QNRF.loading_data import loading_data
from datasets.QNRF.setting import cfg_data
elif data_mode is 'UCF50':
from datasets.UCF50.loading_data import loading_data
from datasets.UCF50.setting import cfg_data
elif data_mode is 'WE':
from datasets.WE.loading_data import loading_data
from datasets.WE.setting import cfg_data
elif data_mode is 'GCC':
from datasets.GCC.loading_data import loading_data
from datasets.GCC.setting import cfg_data
elif data_mode is 'Mall':
from datasets.Mall.loading_data import loading_data
from datasets.Mall.setting import cfg_data
elif data_mode is 'UCSD':
from datasets.UCSD.loading_data import loading_data
from datasets.UCSD.setting import cfg_data
#------------Prepare Trainer------------
net = cfg.NET
if net in ['MCNN', 'AlexNet', 'VGG', 'VGG_DECODER', 'Res50', 'Res101', 'CSRNet','Res101_SFCN']:
from trainer import Trainer
elif net in ['SANet']:
from trainer_for_M2TCC import Trainer # double losses but signle output
elif net in ['CMTL']:
from trainer_for_CMTL import Trainer # double losses and double outputs
elif net in ['PCCNet']:
from trainer_for_M3T3OCC import Trainer
#------------Start Training------------
pwd = os.path.split(os.path.realpath(__file__))[0]
cc_trainer = Trainer(loading_data,cfg_data,pwd)
cc_trainer.forward()