Spaces:
Runtime error
Runtime error
# Human or Animal application in gradio. | |
import gradio as gr | |
from fastai.vision.all import * | |
import skimage | |
def label_func(filename): | |
if 'human' in Path(filename).parts[-2]: | |
return 'human' | |
elif 'animal' in Path(filename).parts[-2]: | |
return 'animal' | |
loaded_generic_model = load_learner('model_generic.pkl') | |
loaded_special_model = load_learner('model_special.pkl') | |
def predict_human_or_animal(img): | |
im = PILImage.create(img) | |
generic_class, generic_class_id, generic_probs = loaded_generic_model.predict(img) | |
special_class, special_class_id, special_probs = loaded_special_model.predict(img) | |
return {generic_class: float(generic_probs[generic_class_id])}, {special_class: float(special_probs[special_class_id])} | |
examples = ['human_1.jpeg', 'human_2.jpeg', 'animal_1.jpeg', 'animal_2.jpeg'] | |
title = "Human or Animal classifiers" | |
description = "Human or Animal classification signal from two models. First output is from a generic model trained with generic images whereas second output is from a specialized model trained with images of hard positives." | |
intf = gr.Interface(fn=predict_human_or_animal, inputs="image", outputs=["label", "label"],title=title,description=description,examples=examples).launch(share=True) | |