-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.py
More file actions
34 lines (22 loc) · 839 Bytes
/
functions.py
File metadata and controls
34 lines (22 loc) · 839 Bytes
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
import torch
import numpy as np
import matplotlib.pyplot as plt
def cal_accuracy(prediction, labels):
prediction = prediction.detach().cpu().numpy()
labels = labels.detach().cpu().numpy()
hypothesis = [np.argmax(predict) for predict in prediction]
same = (hypothesis == labels)
return np.sum(same) / same.shape[0]
def cal_number(prediction, labels):
prediction = prediction.detach().cpu().numpy()
labels = labels.detach().cpu().numpy()
hypothesis = [np.argmax(predict) for predict in prediction]
same = (hypothesis == labels)
return np.sum(same)
def write_list(lists, path):
with open(path, 'w') as file:
file.write(' '.join(list(map(str, lists))))
def read_list(path):
with open(path, 'r') as file:
lists = list(map(float, file.read().split()))
return lists