Hussain033 commited on
Commit
05b82f6
·
1 Parent(s): 049c207

Create predict.py

Browse files
Files changed (1) hide show
  1. predict.py +25 -0
predict.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import tensorflow as tf
3
+ import tensorflow_hub as hub
4
+ from PIL import Image
5
+
6
+ def pre_process(image: Image.Image):
7
+ # load the image and convert into
8
+ # numpy array
9
+ img = image.resize((180,120))
10
+ # asarray() class is used to convert
11
+ # PIL images into NumPy arrays
12
+ numpydata = np.array(img)
13
+ image = np.expand_dims(numpydata, axis=0)
14
+ #image = image//255.0
15
+ return image
16
+
17
+ def predict(image: Image.Image):
18
+ #save_option = tf.saved_model.LoadOptions(experimental_io_device='/job:localhost', )
19
+ model = tf.keras.models.load_model('leaf_classify.h5',custom_objects={'KerasLayer':hub.KerasLayer})#, options=save_option)
20
+ pre = model.predict(image,batch_size = None)
21
+ #result = np.argmax(pre)
22
+ pred = tf.nn.sigmoid(pre)
23
+ classes = ['Alstonia Scholaris','Arjun','Bael','Basil','Chinar','Gauva','Jamun','Jatropa','Lemon','Mango','Pomegranate',
24
+ 'Pongamia Pinnata']
25
+ return {classes[i]: float(pred[0][i]) for i in range(len(classes))}