Spaces:
Runtime error
Runtime error
File size: 1,347 Bytes
25fa374 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
import numpy as np
import pandas as pd
import matplotlib.pylab as plt
import gradio as gr
import PIL.Image as Image
import tensorflow as tf
import tensorflow_hub as hub
TF_MODEL_URL = 'https://tfhub.dev/google/on_device_vision/classifier/landmarks_classifier_asia_V1/1'
LABEL_MAP_URL = 'https://www.gstatic.com/aihub/tfhub/labelmaps/landmarks_classifier_asia_V1_label_map.csv'
IMAGE_SHAPE = (321, 321)
classifier = tf.keras.Sequential([hub.KerasLayer(TF_MODEL_URL,
input_shape=IMAGE_SHAPE+(3,),
output_key="predictions:logits")])
df = pd.read_csv(LABEL_MAP_URL)
label_map = dict(zip(df.id, df.name))
label_map
img_loc = "image.jpeg"
img = Image.open(img_loc).resize(IMAGE_SHAPE)
img
img = np.array(img)/255.0
img.shape
img = img[np.newaxis, ...]
img.shape
result = classifier.predict(img)
result
label_map[np.argmax(result)]
class_names=list(label_map.values())
def classify_image(image):
img = np.array(image)/255.0
img = img[np.newaxis, ...]
prediction = classifier.predict(img)
return label_map[np.argmax(prediction)]
image = gr.inputs.Image(shape=(321, 321))
label = gr.outputs.Label(num_top_classes=1)
gr.Interface(
classify_image,
image,
label,
capture_session=True).launch(debug=True); |