Spaces:
Sleeping
Sleeping
deployment 1
Browse files- app.py +65 -0
- requirements.txt +5 -0
- sketch_recogination_model_cnn.h5 +3 -0
app.py
ADDED
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
import numpy as np
|
3 |
+
import tensorflow as tf
|
4 |
+
|
5 |
+
# classes:
|
6 |
+
classes = [
|
7 |
+
'car',
|
8 |
+
'house',
|
9 |
+
'wine bottle',
|
10 |
+
'chair',
|
11 |
+
'table',
|
12 |
+
'tree',
|
13 |
+
'camera',
|
14 |
+
'fish',
|
15 |
+
'rain',
|
16 |
+
'clock',
|
17 |
+
'hat'
|
18 |
+
]
|
19 |
+
|
20 |
+
# labels :
|
21 |
+
labels = {
|
22 |
+
'car': 0,
|
23 |
+
'house': 1,
|
24 |
+
'wine bottle': 2,
|
25 |
+
'chair': 3,
|
26 |
+
'table': 4,
|
27 |
+
'tree': 5,
|
28 |
+
'camera': 6,
|
29 |
+
'fish': 7,
|
30 |
+
'rain': 8,
|
31 |
+
'clock': 9,
|
32 |
+
'hat': 10
|
33 |
+
}
|
34 |
+
|
35 |
+
num_classes = len(classes)
|
36 |
+
|
37 |
+
# load the model:
|
38 |
+
from keras.models import load_model
|
39 |
+
model = load_model('sketch_recogination_model_cnn.h5')
|
40 |
+
|
41 |
+
# Predict function for interface:
|
42 |
+
def predict_fn(image):
|
43 |
+
|
44 |
+
# preprocessing the size:
|
45 |
+
resized_image = tf.image.resize(image, (28, 28)) # Resize image to (28, 28)
|
46 |
+
grayscale_image = tf.image.rgb_to_grayscale(resized_image) # Convert image to grayscale
|
47 |
+
|
48 |
+
image = np.array(grayscale_image)
|
49 |
+
|
50 |
+
# model requirements:
|
51 |
+
image = image.reshape(1,28,28,1)
|
52 |
+
label = tf.constant(model.predict(image).reshape(num_classes)) # giving 2D output so 1D
|
53 |
+
|
54 |
+
# predict:
|
55 |
+
predicted_index = tf.argmax(label)
|
56 |
+
class_name = [name for name, index in labels.items() if predicted_index == index][0]
|
57 |
+
return class_name
|
58 |
+
|
59 |
+
|
60 |
+
def main():
|
61 |
+
|
62 |
+
# application interface:
|
63 |
+
import gradio as gr
|
64 |
+
|
65 |
+
gr.Interface(fn=predict_fn, inputs="paint", outputs="label", height=100).launch(share=True, debug=True)
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio==3.17.1
|
2 |
+
keras==2.11.0
|
3 |
+
numpy==1.22.4
|
4 |
+
pandas==1.5.3
|
5 |
+
tensorflow_intel==2.11.0
|
sketch_recogination_model_cnn.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:0fe3e822088ad43aa09d9d698ad814cb29a82e2ff17259648c9ed724a7f8c9b1
|
3 |
+
size 4007240
|