Manul, da commited on
Commit
7012f5d
1 Parent(s): 3341e01

Create eval.py

Browse files
Files changed (1) hide show
  1. eval.py +31 -0
eval.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from tensorflow.keras.models import load_model
2
+ from tensorflow.keras.preprocessing.sequence import pad_sequences
3
+ import numpy as np
4
+ import csv
5
+ from tqdm import tqdm
6
+
7
+ model = load_model("net.h5")
8
+
9
+ dataset = "dataset_test.csv"
10
+ inp_len = 32
11
+
12
+ X = []
13
+ y = []
14
+
15
+ with open(dataset, 'r') as f:
16
+ csv_reader = csv.reader(f)
17
+ for row in tqdm(csv_reader):
18
+ if row == []: continue
19
+ label = int(row[0])
20
+ text = row[1]
21
+ text = [ord(char) for char in text]
22
+ X.append(text)
23
+ y.append(label)
24
+
25
+ X = np.array(pad_sequences(X, maxlen=inp_len, padding='post'))
26
+ y = np.array(y)
27
+
28
+ loss, accuracy = model.evaluate(X, y)
29
+ print(f"Loss: {loss}\nAccuracy: {accuracy}")
30
+
31
+