-
Notifications
You must be signed in to change notification settings - Fork 0
/
gathor.py
80 lines (41 loc) · 1.56 KB
/
gathor.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
'''
Created on 2019年2月9日
@author: jinglingzhiyu
'''
import torch,torchvision
import pandas as pd
import numpy as np
import random,os
from decoder.gather import decoder_module
from decoder.classification import dec_cf_csv,make_cf_dec_protocol
from preprocess.gathor import MyDataset_cf
from control.gathor import local_train_for_cf_pytorch
from my_model import model_v4
from PIL import Image
def init_cf_process(block):
# 随机种子
np.random.seed(500)
torch.manual_seed(500)
torch.cuda.manual_seed_all(500)
random.seed(500)
#设置
block.file_name = os.path.basename(__file__).split('.')[0] #获取当前文件名
block.current_path = os.getcwd()
#从csv文件中提取数据信息
block.decoders = decoder_module(dec_cf_csv)
block.dec_protocol = make_cf_dec_protocol(False,0.88) #设置训练集和测试集划分比例为88:12
block.csv_path = 'label.csv'
block.locktrain_data,val_data = block.decoders(block.csv_path,block.dec_protocol)
#选择模型
block.model = model_v4.v4(num_classes=12)
block.model = torch.nn.DataParallel(block.model).cuda()
#选择训练函数
block.train_func = local_train_for_cf_pytorch(block.model)
class total_control():
def __init__(self):
pass
def init_params(self,init_func):
init_func(self)
if __name__ == '__main__':
session = total_control()
session.init_params(init_cf_process)