import gradio as gr | |
from keras.applications.vgg16 import VGG16 | |
from keras.preprocessing import image | |
from keras.applications.vgg16 import preprocess_input | |
from keras.applications.vgg16 import decode_predictions | |
import numpy as np | |
def predict_image(img): | |
img_4d = img.reshape(-1,224,224,3) | |
prediction = model.predict(img_4d) | |
prediction_results = decode_predictions(prediction, top = 5) | |
return { prediction_results[0][i][1]: float(prediction_results[0][i][2]) for i in range(5) } | |
model = VGG16() | |
model.summary() | |
image = gr.Image() # shape=(224,224)) | |
label = gr.Label(num_top_classes=5) | |
gr.Interface(fn=predict_image, | |
title="VGG16 Classification", | |
description="VGG16 CNN", | |
inputs = image, | |
outputs = label, | |
live=True, | |
#interpretation='default', | |
allow_flagging="never").launch() |