okface/plants
0
1# from fastbook import *2import gradio as gr3import matplotlib.image as im4import tensorflow as tf5# learn = load_learner('export.pkl')6import pickle7#import numpy as np8file = open("mark_1_file.pkl",'r')9model = pickle.load(file)10# learn = load_learner("mark_1_file.pkl")11# categories = ("Kamal_Hasan","Rajini","Vijay")12categories = ("jute","maize","rice","sugarcane","wheat")13def classify_image(img):14 # img_data = im.imread(img)15 img = tf.image.resize(img_data,size=(224,224))16 pred = model.predict(tf.expand_dims(img,axis=0))17 # print(pred)18 pred_label = pred.argmax()19 pred_prob = pred.max()20 # pred,idx,prob = learn.predict(img)21 return dict(zip(categories,map(float,pred)))22 23image = gr.inputs.Image(shape=(224,224))24label = gr.outputs.Label()25# examples = ["rajini_1.jfif","rajini_2.jfif","rajini_3.jfif","kamal_1.jfif","kamal_2.jfif","vijay_1.jfif","vijay_2.jfif","vijay_3.jfif","kamal_rajini.jfif"]26intf = gr.Interface(fn=classify_image,inputs=image,outputs=label,examples=examples)27intf.launch(inline=False)28 29 30 31# import gradio as gr32# import tensorflow as tf33# import pickle34# import matplotlib.image as mpim35# model = pickle.load(open("mark_1.pkl", "r+b"))36# print("htlot")37# categories = ("jute","maize","rice","sugarcane","wheat")38# def classify_image(img):39# img = mpim.imread(img)40# img = tf.image.resize(img,size=(224,224))41# pred = model.predict(tf.expand_dims(img,axis=0))42# pred_label = pred.argmax()43# pred_prob = pred.max()44# return dict(zip(categories,map(float,pred[0])))45 46# image = gr.inputs.Image(shape=(224,224))47# label = gr.outputs.Label()48# examples = ["jute_1.jfif","jute_2.jfif","maize.jfif","maize_2.jfif","rice_1.jfif","rice_2.jfif","sugarcane_1.jfif","sugarcane_2.jfif","wheat_1.jfif","wheat_2.jfif"]49# intf = gr.Interface(fn=classify_image,inputs=image,outputs=label,examples=examples)50# intf.launch(inline=False)