|
|
import numpy as np |
|
|
import tensorflow as tf |
|
|
import tensorflow_hub as hub |
|
|
from PIL import Image |
|
|
|
|
|
def pre_process(image: Image.Image): |
|
|
|
|
|
|
|
|
img = image.resize((180,120)) |
|
|
|
|
|
|
|
|
numpydata = np.array(img) |
|
|
image = np.expand_dims(numpydata, axis=0) |
|
|
|
|
|
return image |
|
|
|
|
|
def predict(image: Image.Image): |
|
|
|
|
|
model = tf.keras.models.load_model('leaf_classify.h5',custom_objects={'KerasLayer':hub.KerasLayer}) |
|
|
pre = model.predict(image,batch_size = None) |
|
|
|
|
|
pred = tf.nn.sigmoid(pre) |
|
|
classes = ['Alstonia Scholaris','Arjun','Bael','Basil','Chinar','Gauva','Jamun','Jatropa','Lemon','Mango','Pomegranate', |
|
|
'Pongamia Pinnata'] |
|
|
return {classes[i]: float(pred[0][i]) for i in range(len(classes))} |