Jorge Fioranelli commited on
Commit
215bf66
1 Parent(s): 3b79346

Added sketch_recognition

Browse files
Files changed (2) hide show
  1. app.py +25 -4
  2. models/sketch_recognition/cnn.h5 +3 -0
app.py CHANGED
@@ -1,7 +1,28 @@
1
  import gradio as gr
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
 
 
5
 
6
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ import tensorflow as tf
3
+ import urllib.request
4
 
5
+ # mlp_model = tf.keras.models.load_model(
6
+ # "models/sketch_recognition/mlp.h5")
7
+ cnn_model = tf.keras.models.load_model(
8
+ "models/sketch_recognition/cnn.h5")
9
 
10
+ labels = urllib.request.urlopen("https://raw.githubusercontent.com/googlecreativelab/quickdraw-dataset/master/categories.txt")
11
+ labels = labels.read()
12
+ labels = labels.decode('utf-8').split("\n")[:-1]
13
+
14
+
15
+ def predict(img):
16
+ img = tf.math.divide(img, 255)
17
+ preds = cnn_model.predict(img.reshape(-1, 28, 28, 1))[0]
18
+ return {label: float(pred) for label, pred in zip(labels, preds)}
19
+
20
+ output = gr.outputs.Label(num_top_classes=3)
21
+
22
+ title="Sketch Recognition"
23
+ description="This Convolution Neural Network was trained on Google's " \
24
+ "QuickDraw dataset with 345 classes. Try it by drawing a " \
25
+ "lightbulb, radio, or anything you can think of!"
26
+ thumbnail="https://github.com/gradio-app/machine-learning-experiments/raw/master/lightbulb.png?raw=true"
27
+ gr.Interface(predict, "sketchpad", output, live=True, title=title, analytics_enabled=False,
28
+ description=description, thumbnail=thumbnail, capture_session=True).launch()
models/sketch_recognition/cnn.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:25b551a31a9ca980637231fef74428a4f7b2dcea199cbe3226fed89629741075
3
+ size 2029392