|
import pandas as pd |
|
import numpy as np |
|
import tensorflow as tf |
|
|
|
|
|
classes = [ |
|
'car', |
|
'house', |
|
'wine bottle', |
|
'chair', |
|
'table', |
|
'tree', |
|
'camera', |
|
'fish', |
|
'rain', |
|
'clock', |
|
'hat' |
|
] |
|
|
|
|
|
labels = { |
|
'car': 0, |
|
'house': 1, |
|
'wine bottle': 2, |
|
'chair': 3, |
|
'table': 4, |
|
'tree': 5, |
|
'camera': 6, |
|
'fish': 7, |
|
'rain': 8, |
|
'clock': 9, |
|
'hat': 10 |
|
} |
|
|
|
num_classes = len(classes) |
|
|
|
|
|
from keras.models import load_model |
|
model = load_model('sketch_recogination_model_cnn.h5') |
|
|
|
|
|
def predict_fn(image): |
|
|
|
|
|
resized_image = tf.image.resize(image, (28, 28)) |
|
grayscale_image = tf.image.rgb_to_grayscale(resized_image) |
|
|
|
image = np.array(grayscale_image) |
|
|
|
|
|
image = image.reshape(1,28,28,1) |
|
label = tf.constant(model.predict(image).reshape(num_classes)) |
|
|
|
|
|
predicted_index = tf.argmax(label) |
|
class_name = [name for name, index in labels.items() if predicted_index == index][0] |
|
return class_name |
|
|
|
|
|
|
|
import gradio as gr |
|
gr.Interface(fn=predict_fn, inputs="paint", outputs="label", title="DoodleDecoder", description="Draw something from: Car, House, Wine bottle, Chair, Table, Tree, Camera, Fish, Rain, Clock, Hat", interpretation='default', article="Draw large with thick stroke.").launch() |
|
|
|
|