AgbajeAyomipo commited on
Commit
8922014
·
1 Parent(s): f621e0d
Files changed (4) hide show
  1. app.py +46 -0
  2. car-airplane-ship.ipynb +0 -0
  3. models/final_model.h5 +3 -0
  4. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ os.environ['KERAS-BACKEND'] = 'tensorflow'
4
+
5
+ import keras_core as keras
6
+ import numpy as np
7
+ from keras.models import load_model
8
+ import cv2
9
+ import tensorflow as tf
10
+ import tensorflow.image
11
+
12
+
13
+
14
+
15
+ def image_predict(img_):
16
+ model = load_model('models/final_model.h5')
17
+
18
+ img = img_ / 255.0
19
+ img = tf.image.central_crop(img, central_fraction = .85).numpy()
20
+ img = cv2.resize(img, dsize = [224, 224])
21
+ img = np.expand_dims(img, axis = 0)
22
+
23
+ pred = model.predict(img, verbose = 1)
24
+ pred = np.argmax(pred, axis = 1)
25
+
26
+ if pred == 0:
27
+ answer = "The inputted image is an Airplane"
28
+ elif pred == 1:
29
+ answer = "The inputted image is a Car"
30
+
31
+ return answer
32
+
33
+
34
+ # image_ = gr.Image(label = 'Input Image to be predicted')
35
+ # output = gr.Textbox(label = 'Prediction')
36
+
37
+ # demo = gr.Interface(fn = image_predict, inputs = [image_], outputs = output)
38
+
39
+
40
+ with gr.Blocks() as demo:
41
+ image_ = gr.Image(label = 'Input Image to be predicted')
42
+ output = gr.Textbox(label = 'Prediction')
43
+ btn = gr.Button('Predict')
44
+ btn.click(fn = image_predict, inputs = [image_], outputs = output)
45
+
46
+ demo.launch(share = False)
car-airplane-ship.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
models/final_model.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e3941949e318d0f2f5c31508430cd5e8f9f8c09e56915a013041620da8691b2b
3
+ size 1176136
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ gradio
2
+ keras-core
3
+ tensorflow
4
+ opencv-python