radnomnamegenorater commited on
Commit
b80f6c0
1 Parent(s): 1ecb4eb

Upload 6 files

Browse files
Files changed (6) hide show
  1. Cat.jpg +0 -0
  2. Dog.jpg +0 -0
  3. Rabbit.jpg +0 -0
  4. app.py +26 -0
  5. classifier.tflite +3 -0
  6. requirements.txt +2 -0
Cat.jpg ADDED
Dog.jpg ADDED
Rabbit.jpg ADDED
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import tensorflow as tf
2
+ import gradio as gr
3
+
4
+ CLASS_NAMES = ['Cat', 'Dog', 'Rabbit']
5
+
6
+ # Load and initialize tf lite model
7
+ interpreter = tf.lite.Interpreter(model_path="classifier.tflite")
8
+ interpreter.allocate_tensors()
9
+ input_details = interpreter.get_input_details()
10
+ output_details = interpreter.get_output_details()
11
+ input_shape = input_details[0]['shape']
12
+
13
+ def classify_image(image):
14
+ image = tf.image.resize(image, (224, 224))
15
+ input_data = tf.expand_dims(image, axis=0)
16
+ interpreter.set_tensor(input_details[0]['index'], input_data)
17
+ interpreter.invoke()
18
+ predictions = interpreter.get_tensor(output_details[0]['index']).ravel()
19
+ confidences = {CLASS_NAMES[i]: float(predictions[i]) for i in range(len(CLASS_NAMES))}
20
+ return confidences
21
+
22
+ gr.Interface(fn=classify_image,
23
+ inputs=gr.Image(shape=(224,224)),
24
+ outputs=gr.Label(num_top_classes=3),
25
+ examples=['Cat.jpg', 'Dog.jpg', 'Rabbit.jpg'],
26
+ cache_examples=True).launch()
classifier.tflite ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:83016276ad0a48c1f589139d68fd18ad12b0b210cac0ffe0979420cacc03070b
3
+ size 16064232
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ tensorflow==2.8.4
2
+ gradio==3.16.2