forked from x4nth055/pythoncode-tutorials
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
Latest commit
40 lines (36 loc) · 1.06 KB
/
Copy pathtest.py
File metadata and controls
40 lines (36 loc) · 1.06 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
fromtrainimportload_data, batch_size
fromtensorflow.keras.modelsimportload_model
importmatplotlib.pyplotasplt
importnumpyasnp
# CIFAR-10 classes
categories= {
0: "airplane",
1: "automobile",
2: "bird",
3: "cat",
4: "deer",
5: "dog",
6: "frog",
7: "horse",
8: "ship",
9: "truck"
}
# load the testing set
# (_, _), (X_test, y_test) = load_data()
ds_train, ds_test, info=load_data()
# load the model with final model weights
model=load_model("results/cifar10-model-v1.h5")
# evaluation
loss, accuracy=model.evaluate(ds_test, steps=info.splits["test"].num_examples//batch_size)
print("Test accuracy:", accuracy*100, "%")
# get prediction for this image
data_sample=next(iter(ds_test))
sample_image=data_sample[0].numpy()[0]
sample_label=categories[data_sample[1].numpy()[0]]
prediction=np.argmax(model.predict(sample_image.reshape(-1, *sample_image.shape))[0])
print("Predicted label:", categories[prediction])
print("True label:", sample_label)
# show the first image
plt.axis('off')
plt.imshow(sample_image)
plt.show()