Harsh994 commited on
Commit
816f33e
1 Parent(s): a2ef05e

Upload test.py

Browse files
Files changed (1) hide show
  1. test.py +59 -0
test.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sys
2
+ import numpy as np
3
+ from PIL import Image
4
+ from numpy import asarray
5
+ import tensorflow as tf
6
+ from tensorflow import keras
7
+
8
+ from tensorflow.keras.preprocessing import image_dataset_from_directory
9
+
10
+
11
+ input = sys.argv[1]
12
+
13
+
14
+
15
+ path = r"archive/Train/Train"
16
+ train = image_dataset_from_directory(path, batch_size=32,
17
+ image_size=(256,256),shuffle=True)
18
+
19
+ #pathx=r"C:\Projects\Junk\model.keras"
20
+
21
+ class_labels = train.class_names
22
+
23
+ #model = keras.models.load_model("model.h5")
24
+ model = keras.models.load_model('model.h5', custom_objects=None, compile=True, safe_mode=True)
25
+ #print(model.summary())
26
+
27
+ #imgs = Image.open('basil.jpg')
28
+
29
+ def calling(img_path):
30
+ imgs = Image.open('basil.jpg')
31
+ predicted_class, confidence = Prediction(model, asarray(imgs))
32
+ return predicted_class
33
+
34
+
35
+ #print('hello')
36
+ def Prediction(model, img):
37
+ img_array = tf.keras.preprocessing.image.img_to_array((img))
38
+ img_array = tf.expand_dims(img_array, 0) # create a batch
39
+
40
+ predictions = model.predict(img_array)
41
+
42
+ predicted_class = class_labels[np.argmax(predictions[0])]
43
+ confidence = round(100 * (np.max(predictions[0])), 2)
44
+
45
+ return predicted_class, confidence
46
+ #return predicted_class
47
+ #return predictions
48
+
49
+ op = calling('basil.jpg')
50
+ print(op)
51
+
52
+ sys.stdout.flush()
53
+ #predicted_class , confidence = Prediction(model,asarray(imgs))
54
+ #pred = Prediction(model,asarray(imgs))
55
+ #print(predicted_class)
56
+
57
+
58
+
59
+ #print('hello2')