-
Notifications
You must be signed in to change notification settings - Fork 0
/
model_testing.py
59 lines (44 loc) · 1.42 KB
/
model_testing.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
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
#importing libraries
import numpy as np
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import models
from tensorflow.keras import layers
import matplotlib.pyplot as plt
import cv2
#Connect to drive
#REMAINING
#loading model
cnn=tf.keras.models.load_model(r"C:\Users\HP\Desktop\pythonpro\trained_model.h5")
##Visualization and Performing Prediction on single image
image_path=''
imag =cv2.imread(image_path)
image=tf.keras.preprocessing.image.load_img(image_path,target_size=(64,64))
input_arr=tf.keras.preprocessing.image.img_to_array(image)
input_arr = np.array([input_arr]) #converting single image to batch
predictions =cnn.predict(input_arr)
print(predictions[0])
print(max(predictions[0]))
test_set=tf.keras.utils.image_dataset_from_directory(
'/content/drive/MyDrive/Training_data/test',
labels='inferred',
label_mode='categorical',
class_names=None,
color_mode='rgb',
batch_size=32,
image_size=(64,64),
shuffle=True,
seed= None,
validation_split=None,
subset=None,
interpolation='bilinear',
follow_links=False,
crop_to_aspect_ratio=False
)
result_index =np.where(predictions[0] ==max(predictions[0]))
print(result_index[0][0])
#Display Image
#Single prediction
print("It's a {}".format(test_set.class_names[result_index[0][0]]))