File size: 1,665 Bytes
3211266 da09297 3211266 |
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 cv2
from keras.models import load_model
import gradio as gr
import numpy as np
from tensorflow.keras.preprocessing.image import ImageDataGenerator
model = load_model('Chicken_Gizzard_Updated_model.h5',compile=True)
class_names={0:'Normal Appearance',
1:'The proventriculusof infected chickens showing several ecchymotic hemorrhages on the tip of the proventricular glandsat 3 dpi',
2:'edema with increased number of solitary and coalesced ecchymotic hemorrhages on theproventricular glands at 4 dpi',
3:'and numerous hemorrhagic spots coalesced to form brush paintappearance on the entire mucosa at 5 dpi'}
def Predict_Gizzard(img):
img = img.reshape((1, img.shape[0], img.shape[1], img.shape[2]))
# Create the data generator with desired properties
datagen = ImageDataGenerator(
rotation_range=30,
width_shift_range=0.1,
height_shift_range=0.1,
shear_range=0.1,
zoom_range=0.1,
horizontal_flip=True,
fill_mode="nearest",
)
# Generate a batch of augmented images (contains only the single image)
augmented_images = datagen.flow(img, batch_size=1)
# Get the first (and only) augmented image from the batch
augmented_img = next(augmented_images)[0]
img=cv2.resize(augmented_img.astype(np.uint8),(224,224))
class_no=model.predict(img.reshape(1,224,224,3)).argmax()
name=class_names.get(class_no)
return name
interface=gr.Interface(fn=Predict_Gizzard,inputs='image',outputs=[gr.components.Textbox(label='Your Result')],
examples=[['Class A.PNG'],['Class B.PNG'],['Class C.PNG'],['Class D.PNG']])
interface.launch(debug=True)
|