Abdullah104 commited on
Commit
0c5a9ba
·
1 Parent(s): 5abd6c8

initial commit

Browse files
Files changed (3) hide show
  1. .gitignore +7 -0
  2. main.py +77 -0
  3. requirements.txt +8 -0
.gitignore ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ flagged/
2
+ *.pt
3
+ *.png
4
+ *.jpg
5
+ *.mp4
6
+ *.mkv
7
+ gradio_cached_examples/
main.py ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+ from PIL import Image
4
+ import tensorflow as tf
5
+
6
+ # Load the TFLite model
7
+ interpreter = tf.lite.Interpreter(model_path=r"D:\Projects\Computer Vision\cat_and_dog\saved_models\converted_models\quantization_DEFAULT_8bit_model_h5_to_tflite.tflite")
8
+ interpreter.allocate_tensors()
9
+
10
+ # Get input and output details
11
+ input_details = interpreter.get_input_details()
12
+ output_details = interpreter.get_output_details()
13
+
14
+ CLASS_NAMES = ['Abyssinian',
15
+ 'Bengal',
16
+ 'Birman',
17
+ 'Bombay',
18
+ 'British_Shorthair',
19
+ 'Egyptian_Mau',
20
+ 'Maine_Coon',
21
+ 'Persian',
22
+ 'Ragdoll',
23
+ 'Russian_Blue',
24
+ 'Siamese',
25
+ 'Sphynx',
26
+ 'american_bulldog',
27
+ 'american_pit_bull_terrier',
28
+ 'basset_hound',
29
+ 'beagle',
30
+ 'boxer',
31
+ 'chihuahua',
32
+ 'english_cocker_spaniel',
33
+ 'english_setter',
34
+ 'german_shorthaired',
35
+ 'great_pyrenees',
36
+ 'havanese',
37
+ 'japanese_chin',
38
+ 'keeshond',
39
+ 'leonberger',
40
+ 'miniature_pinscher',
41
+ 'newfoundland',
42
+ 'pomeranian',
43
+ 'pug',
44
+ 'saint_bernard',
45
+ 'samoyed',
46
+ 'scottish_terrier',
47
+ 'shiba_inu',
48
+ 'staffordshire_bull_terrier',
49
+ 'wheaten_terrier',
50
+ 'yorkshire_terrier']
51
+
52
+ IMAGE_SIZE = 256
53
+
54
+ def predict_image(image: Image.Image):
55
+ image = image.convert("RGB")
56
+ image = image.resize((IMAGE_SIZE, IMAGE_SIZE))
57
+ image_np = np.array(image) / 255.0
58
+ img_batch = np.expand_dims(image_np, 0).astype(np.float32)
59
+
60
+ interpreter.set_tensor(input_details[0]['index'], img_batch)
61
+ interpreter.invoke()
62
+ output = interpreter.get_tensor(output_details[0]['index'])[0]
63
+ predicted_class = CLASS_NAMES[np.argmax(output)]
64
+ confidence = float(np.max(output))
65
+ return predicted_class, f"{confidence:.2f}"
66
+
67
+ # Gradio interface
68
+ interface = gr.Interface(
69
+ fn=predict_image,
70
+ inputs=gr.Image(type="pil"),
71
+ outputs=[gr.Label(label="Predicted Class"), gr.Label(label="Confidence")],
72
+ title="Cat & Dog Breed Classifier",
73
+ description="Upload an image of a cat or dog to identify its breed."
74
+ )
75
+
76
+ if __name__ == "__main__":
77
+ interface.launch()
requirements.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ tensorflow==2.17.1
2
+ fastapi
3
+ uvicorn
4
+ python-multipart
5
+ pillow
6
+ tensorflow-serving-api==2.17.1
7
+ matplotlib
8
+ numpy