|
from fastai.vision.all import * |
|
import gradio as gr |
|
|
|
learn = load_learner("model_2.pkl") |
|
|
|
categories = learn.dls.vocab |
|
for index, category in enumerate(categories): |
|
if category == "Random Anime Photos": |
|
categories[index] = "Others" |
|
|
|
|
|
def classify_image(img): |
|
pred, idx, probs = learn.predict(img) |
|
return dict(zip(categories, map(float, probs))) |
|
|
|
|
|
image = gr.inputs.Image(shape=(360, 360)) |
|
label = gr.outputs.Label() |
|
examples = [ |
|
"Luffy.jpg", |
|
"Naruto-Kurama-Mode.png", |
|
"Goku.jpg", |
|
"Ichigo.jpeg", |
|
"Robin.jpeg" |
|
] |
|
|
|
title = "Top 10 Shounen Anime Protagonists Classifier" |
|
description = "Fine tuned a resnet152 image classifier such that it is able to recognize protagonists of top 10 Shounen Animes.<br>" |
|
article = """ |
|
Animes and its protagonists this image classifier will recognize: |
|
|
|
1. One Piece - Monkey D. Luffy |
|
2. Naruto: Shippuden - Naruto Uzumaki |
|
3. My Hero Academia - Izuku Midoriya |
|
4. Dragon Ball Z - Son Goku aka Kakarot |
|
5. Fairy Tail - Natsu Dragneel |
|
6. Yu Yu Hakusho - Yusuke Urameshi |
|
7. Bleach - Ichigo Kurosaki |
|
8. Hunter X Hunter - Gon Freecss |
|
9. Fullmetal Alchemist - Edward Elric |
|
10. Attack on Titan - Eren Yeager |
|
|
|
Rest all other anime characters will be classified as others. |
|
""" |
|
|
|
|
|
intf = gr.Interface( |
|
fn=classify_image, |
|
inputs=image, |
|
outputs=label, |
|
examples=examples, |
|
title=title, |
|
description=description, |
|
article=article, |
|
theme="huggingface", |
|
) |
|
intf.launch(inline=False) |
|
|