This repository has been archived by the owner on Sep 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgcn.py
597 lines (447 loc) · 23 KB
/
gcn.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
import numpy as np
import math
import copy
import sklearn
import torch
import torch.nn.functional as F
from torch_geometric.nn import GCNConv, Linear, GATConv
from torch_geometric.nn.pool import EdgePooling
from cluster_pool import ClusterPooling
from DAGpool import DAGPool
from torch_geometric.data import Data
from sklearn import metrics
from ThesisModel import ThesisModelInterface
class GraphConvNN(torch.nn.Module):
archName = "Graph Convolutional Neural Network"
def __init__(self, node_features, num_classes):
super().__init__()
self.n_epochs = 500
self.num_classes = num_classes
if self.num_classes == 2: #binary
self.num_classes = 1
hidden_channel = 128
self.conv1 = GCNConv(node_features, hidden_channel)
self.conv2 = GCNConv(hidden_channel+node_features, hidden_channel)
self.conv3 = GCNConv(hidden_channel+node_features, hidden_channel)
self.conv4 = GCNConv(hidden_channel+node_features, hidden_channel)
self.lin1 = Linear(hidden_channel+node_features, hidden_channel)
self.lin2 = Linear(hidden_channel+node_features, out_channels=self.num_classes)
self.optimizer = torch.optim.Adam(self.parameters(), lr=0.00020, weight_decay=1e-4)
def forward(self, data):
data = Data(x=data[0], edge_index=data[1].t().contiguous())
x, edge_index = data.x, data.edge_index
x_in = x.clone()
x = self.conv1(x, edge_index)
x = F.relu(x)
x = torch.cat((x_in, x), -1)
x = self.conv2(x, edge_index)
x = F.relu(x)
x = torch.cat((x_in, x), -1)
x = self.conv3(x, edge_index)
x = F.relu(x)
x = torch.cat((x_in, x), -1)
x = self.conv4(x, edge_index)
x = F.relu(x)
x = F.relu(self.lin1(torch.cat((x_in, x), -1)))
x = self.lin2(torch.cat((x_in, x), -1))
if self.num_classes == 1: #binary
return torch.flatten(torch.sigmoid(x))
return F.log_softmax(x, dim=1)
class GraphConvPoolNN(torch.nn.Module):
archName = "GCN Pooling"
def __init__(self, node_features, num_classes):
super().__init__()
self.n_epochs = 500
self.num_classes = num_classes
if self.num_classes == 2: #binary
self.num_classes = 1
hid_channel = 64
self.dropout = torch.nn.Dropout(p=0.1) #Should've given this to the pooling layers too?
self.conv1 = GCNConv(node_features, hid_channel)
self.pool1 = EdgePooling(hid_channel+node_features)
self.pool2 = EdgePooling(hid_channel+node_features)
self.pool3 = EdgePooling(hid_channel+node_features)
self.conv2 = GCNConv(hid_channel+node_features, hid_channel)
self.conv3 = GCNConv(hid_channel*2+node_features, hid_channel)
self.conv4 = GCNConv(hid_channel*2+node_features, hid_channel)
self.fc1 = torch.nn.Linear(hid_channel+node_features, hid_channel)
self.fc2 = torch.nn.Linear(hid_channel+node_features, self.num_classes)
def forward(self, data):
data = Data(x=data[0], edge_index=data[1].t().contiguous())
x, edge_index = data.x, data.edge_index
x_in = torch.clone(x)
x = self.conv1(x, edge_index)
x = self.dropout(x)
x = F.relu(x)
x = torch.cat((x_in, x), -1) #Skip here from input
batch = torch.tensor(np.zeros(x.shape[0])).long().to(x.get_device()) #Make a batch tensor of np.zeros of length num nodes
x, edge_index, batch, unpool1 = self.pool1(x, edge_index.long(), batch)
x, edge_index, batch, unpool2 = self.pool2(x, edge_index.long(), batch)
x, edge_index, batch, unpool3 = self.pool3(x, edge_index.long(), batch)
x_pool3 = x.clone()
x = self.conv2(x, edge_index)
x = self.dropout(x)
x = F.relu(x)
x = self.conv3(torch.cat((x_pool3, x), -1), edge_index) #Skip connection
x = self.dropout(x)
x = F.relu(x)
x = self.conv4(torch.cat((x_pool3, x), -1), edge_index) #Skip connection
x = self.dropout(x)
x = F.relu(x)
x, edge_index, batch = self.pool3.unpool(x, unpool3)
x, edge_index, batch = self.pool2.unpool(x, unpool2)
x, edge_index, batch = self.pool1.unpool(x, unpool1)
x = torch.cat((x_in, x), -1)
x = self.fc1(x)
x = self.dropout(x)
x = F.relu(x)
x = self.fc2(torch.cat((x_in, x), -1))
if self.num_classes == 1: #binary
return torch.flatten(torch.sigmoid(x))
return F.log_softmax(x, dim=1)
class GraphConvDAGPoolNN(torch.nn.Module):
archName = "GCN DAG Pooling"
def __init__(self, node_features, num_classes):
super().__init__()
self.n_epochs = 500
self.num_classes = num_classes
if self.num_classes == 2: #binary
self.num_classes = 1
self.hid_channel = 128
self.nfeatures = node_features
self.cluster_sizes = 3
self.dropout = torch.nn.Dropout(p=0.5)
self.conv1 = GCNConv(node_features, self.hid_channel)
self.conv2 = GCNConv(self.hid_channel+node_features, self.hid_channel)
self.pool1 = DAGPool(5)
self.conv3 = GCNConv(self.hid_channel+node_features, self.hid_channel)
self.fc1 = torch.nn.Linear(self.hid_channel*2+node_features, self.hid_channel)
#self.conv3 = GCNConv((self.hid_channel+node_features)*self.cluster_sizes, self.hid_channel)
#self.fc1 = torch.nn.Linear(self.hid_channel + (self.hid_channel+node_features)*self.cluster_sizes, self.hid_channel)
self.pool2 = DAGPool(self.cluster_sizes)
self.conv4 = GCNConv(self.hid_channel, self.hid_channel)
self.fc2 = torch.nn.Linear(self.hid_channel*2, self.hid_channel)
#self.conv4 = GCNConv(self.hid_channel*self.cluster_sizes, self.hid_channel)
#self.fc2 = torch.nn.Linear(self.hid_channel + self.hid_channel*self.cluster_sizes, self.hid_channel)
self.pool3 = DAGPool(self.cluster_sizes)
self.conv5 = GCNConv(self.hid_channel, self.hid_channel)
self.fc3 = torch.nn.Linear(self.hid_channel*2, self.hid_channel)
#self.conv5 = GCNConv(self.hid_channel*self.cluster_sizes, self.hid_channel)
#self.fc3 = torch.nn.Linear(self.hid_channel + self.hid_channel*self.cluster_sizes, self.hid_channel)
self.fc4 = torch.nn.Linear(self.hid_channel+node_features, self.hid_channel)
self.fc5 = torch.nn.Linear(self.hid_channel+node_features, self.num_classes)
def forward(self, data):
data = Data(x=data[0], edge_index=data[1].t().contiguous())
x, edge_index = data.x, data.edge_index
x_in = torch.clone(x)
x = self.conv1(x, edge_index)
x = self.dropout(x)
x = F.relu(x)
x = torch.cat((x, x_in), -1)
x = self.conv2(x, edge_index)
x = self.dropout(x)
x = F.relu(x)
x = torch.cat((x_in, x), -1) #Skip here from input
#batch = torch.tensor(np.zeros(x.shape[0])).long().to(x.get_device()) #Make a batch tensor of np.zeros of length num nodes
x, edge_index, unpool1 = self.pool1(x, edge_index.long())
x_out = torch.clone(x)
x = self.conv3(x, edge_index)
x = self.dropout(x)
x = F.relu(x)
#print(x_out.size(), x.size())
x = torch.cat((x_out, x), -1)
#print(x.size())
#print("Test: ", (self.hid_channel+self.nfeatures)*self.cluster_sizes+self.hid_channel)
x = self.fc1(x)
self.dropout(x)
x = F.relu(x)
x, edge_index, unpool2 = self.pool2(x, edge_index.long())
x_out = torch.clone(x)
x = self.conv4(x, edge_index)
x = self.dropout(x)
x = F.relu(x)
x = torch.cat((x_out, x), -1)
x = self.fc2(x)
self.dropout(x)
x = F.relu(x)
x, edge_index, unpool3 = self.pool3(x, edge_index.long())
x_out = torch.clone(x)
x = self.conv5(x, edge_index)
x = self.dropout(x)
x = F.relu(x)
x = torch.cat((x_out, x), -1)
x = self.fc3(x)
self.dropout(x)
x = F.relu(x)
x, edge_index = self.pool3.unpool(unpool3)
x, edge_index = self.pool2.unpool(unpool2)
x, edge_index = self.pool1.unpool(unpool1)
#x = torch.cat((x_in, x), -1)
x = self.fc4(x)
x = self.dropout(x)
x = F.relu(x)
x = self.fc5(torch.cat((x_in, x), -1))
if self.num_classes == 1: #binary
return torch.flatten(torch.sigmoid(x))
return F.log_softmax(x, dim=1)
class GraphGATPoolNN(torch.nn.Module):
archName = "GAT Pooling"
def __init__(self, node_features, num_classes):
super().__init__()
self.n_epochs = 200
self.num_classes = num_classes
if self.num_classes == 2: #binary
self.num_classes = 1
hid_channel = 64
heads = 2
self.gat1 = GATConv(node_features, hid_channel, heads=heads) #Replace with GAT, use 2-4 heads MAX (Heads double the amount of output features)
self.pool1 = EdgePooling(hid_channel*heads+node_features)
self.pool2 = EdgePooling(hid_channel*heads+node_features)
self.pool3 = EdgePooling(hid_channel*heads+node_features)
self.gat2 = GATConv(hid_channel*heads+node_features, hid_channel, heads=heads) #Replace with GAT, use 2-4 heads MAX
self.gat3 = GATConv(hid_channel*heads*2+node_features, hid_channel, heads=heads) #Replace with GAT, use 2-4 heads MAX
self.gat4 = GATConv(hid_channel*heads*2+node_features, hid_channel, heads=heads) #Replace with GAT, use 2-4 heads MAX
self.fc1 = torch.nn.Linear(hid_channel*heads+node_features, hid_channel)
self.fc2 = torch.nn.Linear(hid_channel+node_features, self.num_classes)
def forward(self, data):
data = Data(x=data[0], edge_index=data[1].t().contiguous())
x, edge_index = data.x, data.edge_index
x_in = torch.clone(x)
x = self.gat1(x, edge_index)
x = F.relu(x)
x = torch.cat((x_in, x), -1) #Skip here from input
batch = torch.tensor(np.zeros(x.shape[0])).long().to(x.get_device()) #Make a batch tensor of np.zeros of length num nodes
x, edge_index, batch, unpool1 = self.pool1(x, edge_index.long(), batch)
x, edge_index, batch, unpool2 = self.pool2(x, edge_index.long(), batch)
x, edge_index, batch, unpool3 = self.pool3(x, edge_index.long(), batch)
x_pool3 = x.clone()
x = self.gat2(x, edge_index)
x = F.relu(x)
x = self.gat3(torch.cat((x_pool3, x), -1), edge_index) #Skip connection
x = F.relu(x)
x = self.gat4(torch.cat((x_pool3, x), -1), edge_index) #Skip connection
x = F.relu(x)
x, edge_index, batch = self.pool3.unpool(x, unpool3)
x, edge_index, batch = self.pool2.unpool(x, unpool2)
x, edge_index, batch = self.pool1.unpool(x, unpool1)
x = F.relu(self.fc1(torch.cat((x_in, x), -1)))
x = self.fc2(torch.cat((x_in, x), -1)) #Skip here from x_in
if self.num_classes == 1: #binary
return torch.flatten(torch.sigmoid(x))
return F.log_softmax(x, dim=1)
class GraphConvNewPoolNN(torch.nn.Module):
archName = "GCN Cluster Pooling"
def __init__(self, node_features, num_classes):
super().__init__()
self.n_epochs = 500
self.num_classes = num_classes
if self.num_classes == 2: #binary
self.num_classes = 1
self.minsize = 0
self.hidden_channel = 128
self.clusmap = None
self.dropoutp = 0.1
self.dropout = torch.nn.Dropout(p=self.dropoutp)
self.conv1 = GCNConv(node_features, self.hidden_channel)
self.pool1 = ClusterPooling(self.hidden_channel+node_features, dropout=self.dropoutp)
self.conv4 = GCNConv(self.hidden_channel+node_features, self.hidden_channel)
self.pool2 = ClusterPooling(2*self.hidden_channel+node_features, dropout=self.dropoutp)
self.conv5 = GCNConv(self.hidden_channel*2+node_features, self.hidden_channel)
self.pool3 = ClusterPooling(3*self.hidden_channel+node_features, dropout=self.dropoutp)
self.conv6 = GCNConv(self.hidden_channel*3+node_features, self.hidden_channel)
self.conv7 = GCNConv(self.hidden_channel+node_features, self.hidden_channel)
self.fc1 = torch.nn.Linear(self.hidden_channel + node_features, self.hidden_channel)
self.fc2 = torch.nn.Linear(self.hidden_channel + node_features, self.num_classes)
def forward(self, data):
data = Data(x=data[0], edge_index=data[1].t().contiguous())
x, edge_index = data.x, data.edge_index
x_in = torch.clone(x)
x = self.conv1(x, edge_index)
x = self.dropout(x)
x = F.relu(x)
x = torch.cat((x_in, x), -1) #Skip connection
batch = torch.tensor(np.zeros(x.shape[0])).long().to(x.get_device()) #Make a batch tensor of np.zeros of length num nodes
x, edge_index, batch, unpool1 = self.pool1(x, edge_index.long(), batch)
x_pool = x.clone()
self.clusmap = unpool1.cluster_map
x = self.conv4(x, edge_index)
x = self.dropout(x)
x = F.relu(x)
x = torch.cat((x_pool, x), -1) #Skip connection
x, edge_index, batch, unpool2 = self.pool2(x, edge_index.long(), batch)
x_pool = x.clone()
x = self.conv5(x, edge_index)
x = self.dropout(x)
x = F.relu(x)
x = torch.cat((x_pool, x), -1) #Skip connection
x, edge_index, batch, unpool3 = self.pool3(x, edge_index.long(), batch)
x_pool = x.clone()
x = self.conv6(x, edge_index)
x = self.dropout(x)
x = F.relu(x)
#Unpool
x, edge_index, batch = self.pool3.unpool(x, unpool3)
x, edge_index, batch = self.pool2.unpool(x, unpool2)
x, edge_index, batch = self.pool1.unpool(x, unpool1)
x = torch.cat((x_in, x), -1) #Skip connection
x = self.conv7(x, edge_index)
x = self.dropout(x)
x = F.relu(x)
x = torch.cat((x_in, x), -1) #Skip connection
x = self.fc1(x)
x = self.dropout(x)
x = F.relu(x)
x = torch.cat((x_in, x), -1) #Skip connection
x = self.fc2(x)
if self.num_classes == 1: #binary
return torch.flatten(torch.sigmoid(x))
return F.log_softmax(x, dim=1)
class GUNET(torch.nn.Module):
archName = "Graph UNET2"
def __init__(self, features, labels, pType=ClusterPooling):
super().__init__()
self.in_channels = features
self.out_channels = labels
self.hidden_channels = 128
if self.out_channels == 2:
self.out_channels = 1
self.depth = 3#Try bigger sizes? [1, 10] range makes sense for this problem
self.n_epochs = 500
self.num_classes = self.out_channels
self.dropoutval = 0.1
self.pooldropoutval = 0.05
self.dropout = torch.nn.Dropout(p=self.dropoutval)
self.poolingType = pType
self.show_cluster_plots = True
self.shown = False
self.cf1 = [[] for _ in range(self.depth)]
#self.optim = torch.optim.Adam(self.mdl.parameters(), lr=0.00020)
self.down_convs = torch.nn.ModuleList()
self.pools = torch.nn.ModuleList()
self.down_convs.append(GCNConv(self.in_channels, self.hidden_channels, improved=True))
for i in range(self.depth):
self.pools.append(self.poolingType(self.hidden_channels, dropout=self.pooldropoutval))
self.down_convs.append(GCNConv(self.hidden_channels, self.hidden_channels, improved=True))
self.up_convs = torch.nn.ModuleList()
for i in range(self.depth-1):
self.up_convs.append(GCNConv(self.hidden_channels*2, self.hidden_channels, improved=True))
self.up_convs.append(GCNConv(self.hidden_channels*2+self.in_channels, self.out_channels, improved=True)) #+self.in_channels
self.reset_parameters()
def reset_parameters(self):
for conv in self.down_convs:
conv.reset_parameters()
for pool in self.pools:
pool.reset_parameters()
for conv in self.up_convs:
conv.reset_parameters()
def forward(self, data):
data = Data(x=data[0], edge_index=data[1].t().contiguous(), y=data[2])
x, edge_index = data.x, data.edge_index
x_in = torch.clone(x)
batch = torch.tensor(np.zeros(x.shape[0])).long().to(x.get_device()) #Make a batch tensor of np.zeros of length num nodes
memory = []
unpool_infos = []
for i in range(self.depth):
x = self.down_convs[i](x, edge_index)
if self.training: x = self.dropout(x)
x = F.relu(x)
memory.append(x.clone())
x, edge_index, batch, unpool = self.pools[i](x, edge_index.long(), batch)
unpool_infos.append(unpool)
memory[0] = torch.cat((memory[0], x_in), -1) #Concatenate the input features to the output of the first convolutional layer
x = self.down_convs[-1](x, edge_index)
for i in range(self.depth):
j = self.depth - 1 - i
x, edge_index, batch = self.pools[j].unpool(x, unpool_infos.pop())
x = torch.cat((memory.pop(), x), -1)
x = self.up_convs[i](x, edge_index)
if self.training and i < self.depth - 1: x = self.dropout(x)
x = F.relu(x) if i < self.depth - 1 else x
return torch.sigmoid(x).flatten()
class GCNModel(ThesisModelInterface):
def __init__(self, data, labels, test_set_idx, type=GraphConvNN):
super().__init__(data, labels, test_set_idx)
self.architecture = type
self.clfName = self.architecture.archName
if self.architecture == GUNET:
self.clfName = self.clfName + "- ClusterPool"
self.n_node_features = len(data[0][0][0])
self.n_labels = len(labels)
def train_model(self, replace_model=True):
"Function to fit the model to the data"
if self.clf is None or replace_model is True:
self.clf = self.architecture(self.n_node_features, self.n_labels)
if self.architecture == GUNET:
self.clfName = self.clfName + " " + str(self.clf.poolingType)
self.clf.to(self.device)
if hasattr(self.clf, "optimizer"):
optimizer = self.clf.optimizer
else:
optimizer = torch.optim.Adam(self.clf.parameters(), lr=0.00005, weight_decay=1e-4)
#optimizer = torch.optim.Adam(self.clf.parameters(), lr=0.00025, weight_decay=1e-4)
self.clf.train()
loss_func = F.nll_loss #nll_loss is logloss
if self.clf.num_classes == 1: #Binary
def BCELoss_class_weighted(weights):
def loss(input, target):
input = torch.clamp(input,min=1e-7,max=1-1e-7)
bce = - weights[1] * target * torch.log(input) - \
weights[0] * (1 - target) * torch.log(1 - input)
return torch.mean(bce)
return loss
loss_func = BCELoss_class_weighted([1,4])
tf1 = []
tloss = []
vf1 = []
nr = []
best_mod = copy.deepcopy(self.clf.state_dict())
for epoch in range(self.clf.n_epochs + 1):
tot_lss = 0.0
train_f1 = 0.0
y_train_probs = []
for index, data in enumerate(self.train): #For every graph in the data set
optimizer.zero_grad()
out = self.clf(data) #Get the labels from all the nodes in one graph
class_lbls = data[2]
loss = loss_func(out, class_lbls) #Now get the loss based on these outputs and the actual labels of the graph
#print(metrics.f1_score(class_lbls.cpu().detach().numpy(), (out > self.threshold).int().cpu().detach().numpy(), zero_division=0))
y_train_probs.extend(out.cpu().detach().numpy().tolist())
tot_lss += loss.item()
if math.isnan(loss.item()):
print("\t\tError in loss in Epoch: " + str(epoch+1) + "/" + str(self.clf.n_epochs))
if torch.isnan(out).nonzero().size(0) > 0: #We have a nan output
print("\t\t Error in output of the network: " + str(torch.isnan(out).nonzero().size(0)), " nan values")
return tf1, tloss, vf1
loss.backward()
optimizer.step()
#test
prec, rec, threshold = sklearn.metrics.precision_recall_curve(self.y_train, y_train_probs)
if not ((prec+rec) == 0).any():
f1s = (2*(prec * rec)) / (prec + rec)
train_f1 = np.max(f1s)
if len(tf1) == 0 or train_f1 > np.max(tf1):
best_mod = copy.deepcopy(self.clf.state_dict())
self.threshold = threshold[np.argmax(f1s)]
#train_f1 = train_f1 / len(self.train)
tf1.append(train_f1)
tloss.append(tot_lss/ len(self.train))
"""if epoch % 10 == 0 and epoch > 0:
self.clf.train(mode=False)
valid_f1 = self.validate_model()
self.clf.train()
prec, rec, threshold = sklearn.metrics.precision_recall_curve(self.y_valid, self.y_valid_dist)
if not ((prec+rec) == 0).any():
f1s = (2*(prec * rec)) / (prec + rec)
valid_f1 = np.max(f1s)
vf1.append(valid_f1)
if valid_f1 >= np.max(vf1): #Best validation score thusfar
best_mod = copy.deepcopy(self.clf.state_dict())
if not ((prec+rec) == 0).any(): #Can we calculate the best threshold?
self.threshold = threshold[np.argmax(f1s)] #Set the threshhold to the most optimal one
print("\n")
print("\t\tLoss in Epoch " + str(epoch) + ": " + str(tot_lss))
print(f"\t\tValid F1 score: {valid_f1:.4f} (Best: {np.max(vf1):.4f}, Thresh: {self.threshold:.4f})")"""
print(f"\t\tEpoch {epoch} Train F1: {train_f1:.4f}, Best: {np.max(tf1):.4f}")
self.clf.load_state_dict(best_mod)
self.clf.train(mode=False)
return tf1, tloss, vf1