NoName commited on
Commit
9fad519
1 Parent(s): e2cec64

Add application file

Browse files
Files changed (1) hide show
  1. app.py +7 -6
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import gradio as gr
2
  from fastai.vision.all import *
 
3
 
4
  #import pathlib
5
  #temp = pathlib.PosixPath
@@ -8,16 +9,16 @@ from fastai.vision.all import *
8
  catergories = ('bunny girl', 'cat neko girl', 'fox kitsune girl', 'wolfgirl')
9
 
10
  def load_model_and_predict(img):
11
- #img = PILImage.create(image_path)
12
- pred, idx, probs = learn.predict(img)
13
- #return pred, probs
14
- return dict(zip(catergories, map(float,probs)))
15
 
16
  model_path = "export_resnet18_e12_3.pkl"
17
  learn = load_learner(model_path)
18
 
19
- image = gr.inputs.Image(shape=(224, 224))
20
  label = gr.outputs.Label()
21
 
22
- iface = gr.Interface(fn=load_model_and_predict, inputs=image, outputs=label, title='兽耳娘分类器', description='这是一个基于resnet18训练的玩具模型,可以将输入的~二次元~图画分类为:bunny girl/兔兔、cat neko girl/猫娘、fox kitsune girl/狐娘、wolfgirl/狼娘。 \n 每类均使用15张随机画作或冻鳗截图训练,该模型的分类正确率受裁剪方法、图画构图、角色姿势等多种因素影响,准确率难以保证,仅供娱乐。 \n 08/28/23')
23
  iface.launch()
 
1
  import gradio as gr
2
  from fastai.vision.all import *
3
+ from PIL import Image
4
 
5
  #import pathlib
6
  #temp = pathlib.PosixPath
 
9
  catergories = ('bunny girl', 'cat neko girl', 'fox kitsune girl', 'wolfgirl')
10
 
11
  def load_model_and_predict(img):
12
+ squished_img = Image.fromarray(img).resize((224, 224))
13
+ pil_img = PILImage.create(squished_img)
14
+ pred, idx, probs = learn.predict(pil_img)
15
+ return dict(zip(catergories, map(float, probs)))
16
 
17
  model_path = "export_resnet18_e12_3.pkl"
18
  learn = load_learner(model_path)
19
 
20
+ image = gr.inputs.Image(shape=(None, None))
21
  label = gr.outputs.Label()
22
 
23
+ 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')
24
  iface.launch()