-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
47 lines (33 loc) · 1.17 KB
/
test.py
File metadata and controls
47 lines (33 loc) · 1.17 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
import pickle
import numpy as np
from keras.models import load_model
from sklearn.metrics import accuracy_score
# Load the trained model
model = load_model('original_mnist.h5')
# Load the test data from the pkl file
#정규화 하지 않은 파일
with open('testdata1D.pkl', 'rb') as file:
test_data = pickle.load(file)
# Print the content of test_data
#print(test_data)
# Extract the necessary data from test_data
X_test = test_data[0]
Y_test = test_data[1]
# Save test data with the correct structure
test_data = {'X_test': X_test, 'Y_test': Y_test}
with open('test_data.pkl', 'wb') as file:
pickle.dump(test_data, file)
# Access the test data from the tuple
X_test = test_data['X_test']
Y_test = test_data['Y_test']
X_test = X_test.reshape(X_test.shape[0], 784).astype('float32') / 255
# Perform predictions
predictions = model.predict(X_test)
# Convert predictions to class labels
predicted_labels = np.argmax(predictions, axis=1)
# Calculate accuracy
accuracy = accuracy_score(Y_test, predicted_labels)
# Print the test values, predicted values, and accuracy
print("Test Values:\n", Y_test)
print("Predicted Values:\n", predicted_labels)
print("Accuracy:\n", accuracy)