-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLossPic.py
More file actions
55 lines (40 loc) · 1.47 KB
/
LossPic.py
File metadata and controls
55 lines (40 loc) · 1.47 KB
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
import numpy as np
import matplotlib.pyplot as plt
# 读取存储为txt文件的数据
def data_read(dir_path):
with open(dir_path, "r") as f:
raw_data = f.read()
data = raw_data[1:-1].split(", ")
return np.asfarray(data, float)
# 不同长度数据,统一为一个标准,倍乘x轴
def multiple_equal(x, y):
x_len = len(x)
y_len = len(y)
times = x_len/y_len
y_times = [i * times for i in y]
return y_times
if __name__ == "__main__":
cnn_loss_path = r"LossAndAccData/cnn_loss.txt"
rnn_loss_path = r"LossAndAccData/rnn_loss.txt"
y_cnn_loss = data_read(cnn_loss_path)
y_rnn_loss = data_read(rnn_loss_path)
x_cnn_loss = range(len(y_cnn_loss))
x_rnn_loss = multiple_equal(x_cnn_loss, range(len(y_rnn_loss)))
plt.figure()
# 去除顶部和右边框框
ax = plt.axes()
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
plt.xlabel('iters')
plt.ylabel('loss')
# plt.plot(x_train_loss, y_train_loss, linewidth=1, linestyle="solid", label="train loss")
plt.plot(x_rnn_loss, y_rnn_loss, color='red', linestyle="solid", label="BiRNN Loss")
plt.plot(x_cnn_loss, y_cnn_loss, linewidth=1, linestyle="solid", label="TextCNN Loss")
plt.legend()
plt.title('Loss(BiRNN VS TextCNN)')
plt.show()
#
# plt.plot(x_train_loss, y_train_loss, linewidth=1, linestyle="solid", label="train loss")
# plt.legend()
# plt.title('Loss curve')
# plt.show()