-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpredict_model.py
More file actions
45 lines (36 loc) · 837 Bytes
/
predict_model.py
File metadata and controls
45 lines (36 loc) · 837 Bytes
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
# # #
# Make predictions by my_keras_model.h5
# # #
from keras.models import Sequential
from keras.layers import Dense
from keras.models import load_model
import keras.utils
import numpy as np
# randomize for initial weights
np.random.seed(7)
# Generate Dataset for making predictions
# This dataset has 3 classes:
# [0]: y = x
# [1]: y = x^2
# [2]: y = x^3
X = []
for i in range(10, 12):
X.append([i, i, 0])
X.append([i, i**2, 1])
X.append([i, i**3, 2])
X = np.array(X)
Y = X[:, 2]
X = X[:, [0,1]]
# # #
# Load model
# # #
model = load_model('my_keras_model.h5')
# # #
# Make predictions
# # #
# calculate predictions
predictions = model.predict(X)
# print result
for i in range(len(X)):
print("\nX=%s, Y=%s, Predicted=[%s]\nPredict_Prob=%s" %
(X[i], Y[i], np.argmax(predictions[i]), predictions[i]))