Spaces:
Sleeping
Sleeping
File size: 1,373 Bytes
4c64d64 a07083f 50a8396 231b5e3 a07083f 88fc88b 21d4113 7d41901 21d4113 2fb9c5f 8e631e2 f2bbf86 48c865b 0a245e5 48c865b a6222a0 2bdf603 a6222a0 3ab4575 |
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 |
import gradio as gr
import pickle
import matplotlib.pyplot as plt
import numpy as np
import os
import PIL
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers
from keras.models import load_model
img_height,img_width=180,180
model_flower = keras.models.load_model('model_flower.h5')
from tensorflow.keras.models import Sequential
num_classes = 5
model = Sequential([
layers.experimental.preprocessing.Rescaling(1./255, input_shape=(img_height, img_width, 3)),
layers.Conv2D(16, 3, padding='same', activation='relu'),
layers.MaxPooling2D(),
layers.Conv2D(32, 3, padding='same', activation='relu'),
layers.MaxPooling2D(),
layers.Conv2D(64, 3, padding='same', activation='relu'),
layers.MaxPooling2D(),
layers.Flatten(),
layers.Dense(128, activation='relu'),
layers.Dense(num_classes,activation='softmax')
])
model.compile(optimizer='adam',
loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),
metrics=['accuracy'])
def predict_image(img):
img_2d=img.reshape(-1,180,180,3)
prediction=model_flower.predict(img_2d)[0]
return {class_names[i]: float(prediction[i]) for i in range(5)}
image = gr.inputs.Image(shape=(180,180))
label = gr.outputs.Label(num_top_classes=5)
gr.Interface(fn=predict_image, inputs=image, outputs=label,interpretation='default').launch() |