# # -*- coding: utf-8 -*- | |
# """app creation.ipynb | |
# Automatically generated by Colaboratory. | |
# Original file is located at | |
# https://colab.research.google.com/drive/1c8HIdMTAJxhNiPY7_kmzP78yFiwdhh8Q | |
# """ | |
# import gradio as gr | |
# from fastai import * | |
# from fastai.vision.all import * | |
# # import pathlib | |
# # temp = pathlib.PosixPath | |
# # pathlib.PosixPath = pathlib.WindowsPath | |
# model = load_learner("models/recgonizer_model.pkl") | |
# labels = ['Ayre', 'Catla', 'Chital', 'Ilish', 'Kachki', 'Kajoli', 'Koi', 'Magur', 'Mola Dhela', 'Mrigal', 'Pabda', 'Pangash', 'Poa', 'Puti', 'Rui', 'Shing', 'Silver Carp', 'Taki', 'Telapia', 'Tengra'] | |
# def recognize_image(image_path): | |
# label, _, probs = model.predict(image_path) | |
# return dict(zip(labels, map(float, probs))) | |
# inputs = gr.inputs.Image(shape=(224,224)) | |
# outputs = gr.outputs.Label() | |
# examples = [ | |
# 'test images/unknown_01.jpg', | |
# 'test images/unknown_02.png', | |
# 'test images/unknown_03.jpg', | |
# 'test images/unknown_04.jpg', | |
# 'test images/unknown_05.jpg', | |
# 'test images/unknown_06.jpg', | |
# 'test images/unknown_07.jpg', | |
# 'test images/unknown_08.jpg', | |
# 'test images/unknown_09.jpg', | |
# 'test images/unknown_10.jpg', | |
# 'test images/unknown_11.jpg', | |
# 'test images/unknown_12.png', | |
# 'test images/unknown_13.jpg', | |
# 'test images/unknown_14.png', | |
# 'test images/unknown_15.png', | |
# 'test images/unknown_16.png', | |
# 'test images/unknown_17.jpg' | |
# ] | |
# interface = gr.Interface(fn=recognize_image, inputs = inputs, outputs=outputs, examples = examples) | |
# interface.launch() | |
# -*- coding: utf-8 -*- | |
"""app creation.ipynb | |
Automatically generated by Colaboratory. | |
Original file is located at | |
https://colab.research.google.com/drive/1c8HIdMTAJxhNiPY7_kmzP78yFiwdhh8Q | |
""" | |
import numpy as np | |
import gradio as gr | |
from fastai import * | |
from fastai.vision.all import * | |
import pathlib | |
temp = pathlib.PosixPath | |
pathlib.PosixPath = pathlib.WindowsPath | |
model = load_learner("models/recgonizer_model.pkl") | |
labels = ['Ayre', 'Catla', 'Chital', 'Ilish', 'Kachki', 'Kajoli', 'Koi', 'Magur', 'Mola Dhela', 'Mrigal', 'Pabda', 'Pangash', 'Poa', 'Puti', 'Rui', 'Shing', 'Silver Carp', 'Taki', 'Telapia', 'Tengra'] | |
def recognize_image(image_path): | |
label, _, probs = model.predict(image_path) | |
# return dict(zip(labels, map(float, probs))) | |
print(f"Category with most probability: {np.argmax(probs)}") | |
return image_path, dict(zip(labels, map(float, probs))) | |
# inputs = gr.inputs.Image(shape=(224,224)) | |
# outputs = gr.outputs.Label() | |
examples = [ | |
'test images/unknown_01.jpg', | |
'test images/unknown_02.png', | |
'test images/unknown_03.jpg', | |
'test images/unknown_04.jpg', | |
'test images/unknown_05.jpg', | |
'test images/unknown_06.jpg', | |
'test images/unknown_07.jpg', | |
'test images/unknown_08.jpg', | |
'test images/unknown_09.jpg', | |
'test images/unknown_10.jpg', | |
'test images/unknown_11.jpg', | |
'test images/unknown_12.png', | |
'test images/unknown_13.jpg', | |
'test images/unknown_14.png', | |
'test images/unknown_15.png', | |
'test images/unknown_16.png', | |
'test images/unknown_17.jpg' | |
] | |
interface = gr.Interface(fn=recognize_image, inputs = gr.Image(), outputs = [gr.Image(height=224, width=224), gr.Label(num_top_classes=5)] , examples = examples) | |
interface.launch() | |