-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathCNNs_eval.py
62 lines (39 loc) · 1.58 KB
/
CNNs_eval.py
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
56
57
58
59
60
import numpy as np
import tensorflow as tf
import pickle as pickle # python pkl 文件读写
from CNNs_model import cnn_model_fn
tf.logging.set_verbosity(tf.logging.INFO)
def main(unused_argv):
predict_data = np.array(pickle.load(open('cache/test_temporary_data.plk', 'rb')) )
predict_labels = np.array(pickle.load(open('cache/test_temporary_labels.plk', 'rb')) )
# predict_data = np.array(pickle.load(open('cache/test_data.plk', 'rb')) )
# predict_labels = np.array(pickle.load(open('cache/test_labels.plk', 'rb')) )
# with tf.Session() as sess:
# train_data = tf.convert_to_tensor(train_data_np)
# eval_data = tf.convert_to_tensor(eval_data_np)
# Create the Estimator
cnn_classifier = tf.estimator.Estimator(
# model_fn=cnn_model_fn, model_dir="cnn_convnet_model")
model_fn=cnn_model_fn, model_dir="Model/cnn")
# Evaluate the model and print results
eval_input_fn = tf.estimator.inputs.numpy_input_fn(
x={"x": predict_data},
y=predict_labels,
num_epochs=1,
shuffle=False)
eval_results = cnn_classifier.evaluate(input_fn=eval_input_fn)
print(eval_results)
# predict
predict_input_fn = tf.estimator.inputs.numpy_input_fn(
x={"x": predict_data},
num_epochs=1,
shuffle=False)
predict_results = cnn_classifier.predict(input_fn=predict_input_fn)
for e in predict_results:
print(e['classes'])
# print(e['probabilities'])
print("done!")
for i in predict_labels:
print(i)
if __name__ == "__main__":
tf.app.run()