animimichk / app.py
NoName
Add application file
9fad519
import gradio as gr
from fastai.vision.all import *
from PIL import Image
#import pathlib
#temp = pathlib.PosixPath
#pathlib.PosixPath = pathlib.WindowsPath
catergories = ('bunny girl', 'cat neko girl', 'fox kitsune girl', 'wolfgirl')
def load_model_and_predict(img):
squished_img = Image.fromarray(img).resize((224, 224))
pil_img = PILImage.create(squished_img)
pred, idx, probs = learn.predict(pil_img)
return dict(zip(catergories, map(float, probs)))
model_path = "export_resnet18_e12_3.pkl"
learn = load_learner(model_path)
image = gr.inputs.Image(shape=(None, None))
label = gr.outputs.Label()
iface = gr.Interface(fn=load_model_and_predict, inputs=image, outputs=label, title='兽耳娘分类器', description='❕❕Tip:将图片裁切为正方形并切去复杂背景以获取更高准确率。❕❕ \n\n 这是一个基于 resnet18 训练的玩具模型,可以将输入的~二次元~图画分类为:bunny girl/兔兔、cat neko girl/猫娘、fox kitsune girl/狐娘、wolfgirl/狼娘。 \n 每类均使用15张随机画作或冻鳗截图训练,该模型的分类正确率受裁剪方法、图画构图、角色姿势等多种因素影响,准确率难以保证,仅供娱乐。 \n Version1.1 08/28/23')
iface.launch()