hsalih01 commited on
Commit
b384e36
·
verified ·
1 Parent(s): e7b39ae

Upload 2 files

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ Cat_transfer_learning_MobileNetV2.keras filter=lfs diff=lfs merge=lfs -text
Cat_transfer_learning_MobileNetV2.keras ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c06dfbfe5de9013d8cce0dabffad096d00fcdab25e96ca035087c50c934f3575
3
+ size 27577542
app.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+ import numpy as np
4
+ from PIL import Image
5
+
6
+ model_path = "C:\Users\salih\Project_imageclass_Hasicic_Salih\Project_Inference_Dogs\Cat_transfer_learning_MobileNetV2.keras"
7
+ model = tf.keras.models.load_model(model_path)
8
+
9
+ # Define the core prediction function
10
+ def predict_dog(image):
11
+ # Preprocess image
12
+ print(type(image))
13
+ image = Image.fromarray(image.astype('uint8')) # Convert numpy array to PIL image
14
+ image = image.resize((150, 150)) #resize the image to 28x28 and converts it to gray scale
15
+ image = np.array(image)
16
+ image = np.expand_dims(image, axis=0) # same as image[None, ...]
17
+
18
+ # Predict
19
+ prediction = model.predict(image)
20
+
21
+ # No need to apply sigmoid, as the output layer already uses softmax
22
+ # Convert the probabilities to rounded values
23
+ prediction = np.round(prediction, 3)
24
+
25
+ # Separate the probabilities for each class
26
+ p_americanshorthair = prediction[0][0] # Probability for class 'articuno'
27
+ p_bengal = prediction[0][1] # Probability for class 'moltres'
28
+ p_mainecoon = prediction[0][2] # Probability for class 'zapdos'
29
+ p_ragdoll = prediction[0][3] # Probability for class 'zapdos'
30
+ p_scottishfold = prediction[0][4]
31
+ p_sphinx = prediction[0][5]
32
+
33
+
34
+ return {'americanshorthair': p_americanshorthair, 'bengal': p_bengal, 'mainecoon': p_mainecoon, 'ragdoll': p_ragdoll, 'scottishfold': p_scottishfold, 'sphinx': p_sphinx }
35
+
36
+ # Create the Gradio interface
37
+ input_image = gr.Image()
38
+ iface = gr.Interface(
39
+ fn=predict_dog,
40
+ inputs=input_image,
41
+ outputs=gr.Label(),
42
+ examples=["images/americanshorthair_1.jpg", "images/americanshorthair_2.jpg", "images/americanshorthair_3.jpg", "images/bengal_1.jpg", "images/bengal_2.jpeg", "images/bengal_3.jpg", "images/mainecoon_1.jpg", "images/mainecoon_2.jpeg", "images/mainecoon_3.jpg", "images/ragdoll_1.jpg", "images/ragdoll_2.jpg", "images/ragdoll_3.jpeg", "images/scottishfold_1.jpeg", "images/scottishfold_2.jpg", "images/scottishfold_3.jpg", "images/sphinx_1.jpg", "images/sphinx_2.jpg", "images/sphinx_3.jpg"],
43
+ description="TEST.")
44
+
45
+ iface.launch()