File size: 1,561 Bytes
221338a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 sys
import numpy as np
from PIL import Image
from numpy import asarray
import tensorflow as tf
from tensorflow import keras

from tensorflow.keras.preprocessing import image_dataset_from_directory


input = sys.argv[1]



path = r"D:\MinorP\venv\Validation"
train = image_dataset_from_directory(path, batch_size=32,
                                    image_size=(256,256),shuffle=True)

#pathx=r"C:\Projects\Junk\model.keras"

class_labels = train.class_names
pth=r"D:\MinorP\venv\model.h5"
#model = keras.models.load_model("model.h5")
model = keras.models.load_model(pth, custom_objects=None, compile=True, safe_mode=True)
#print(model.summary())

#imgs = Image.open('basil.jpg')

def calling(img_path):
    imgs = Image.open(img_path)
    predicted_class, confidence = Prediction(model, asarray(imgs))
    return predicted_class


#print('hello')
def Prediction(model, img):
    img_array = tf.keras.preprocessing.image.img_to_array((img))
    img_array = tf.expand_dims(img_array, 0)  # create a batch

    predictions = model.predict(img_array)

    predicted_class = class_labels[np.argmax(predictions[0])]
    confidence = round(100 * (np.max(predictions[0])), 2)

    return predicted_class, confidence
    #return predicted_class
    #return predictions
ph=r"D:\MinorP\venv\ashwagandha.jpg"
op = calling(ph)
print(op)

sys.stdout.flush()
#predicted_class , confidence = Prediction(model,asarray(imgs))
#pred = Prediction(model,asarray(imgs))
#print(predicted_class)



#print('hello2')