|
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"archive/Train/Train"
|
|
train = image_dataset_from_directory(path, batch_size=32,
|
|
image_size=(256,256),shuffle=True)
|
|
|
|
|
|
|
|
class_labels = train.class_names
|
|
|
|
|
|
model = keras.models.load_model('model.h5', custom_objects=None, compile=True, safe_mode=True)
|
|
|
|
|
|
|
|
|
|
def calling(img_path):
|
|
imgs = Image.open('basil.jpg')
|
|
predicted_class, confidence = Prediction(model, asarray(imgs))
|
|
return predicted_class
|
|
|
|
|
|
|
|
def Prediction(model, img):
|
|
img_array = tf.keras.preprocessing.image.img_to_array((img))
|
|
img_array = tf.expand_dims(img_array, 0)
|
|
|
|
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
|
|
|
|
|
|
|
|
op = calling('basil.jpg')
|
|
print(op)
|
|
|
|
sys.stdout.flush()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|