Upload eval.py
Browse files
eval.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
|