ganesh1410 commited on
Commit
031b4b5
·
1 Parent(s): 7087444

feat: add the generated model

Browse files
Files changed (2) hide show
  1. app.py +19 -7
  2. cats_classifier.pkl +3 -0
app.py CHANGED
@@ -1,11 +1,10 @@
1
  import gradio as gr
2
  from fastai.vision.all import *
3
 
 
 
4
 
5
  def get_data():
6
- # Label function
7
- def is_cat(x:string): return x[0].isupper()
8
-
9
  # Read the dataset from fastai
10
  path = untar_data(URLs.PETS)/'images'
11
  return ImageDataLoaders.from_name_func(
@@ -18,9 +17,22 @@ if __name__ == '__main__':
18
  dls = get_data()
19
 
20
  # Train the model with vision_learner
21
- learn = vision_learner(dls, resnet34, metrics=error_rate)
22
- learn.fine_tune(1)
23
 
24
- demo = gr.Interface(fn=learn.predict, inputs="image", outputs="text")
25
- demo.launch()
 
 
 
 
 
26
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
  from fastai.vision.all import *
3
 
4
+ # Label function
5
+ def is_cat(x:string): return x[0].isupper()
6
 
7
  def get_data():
 
 
 
8
  # Read the dataset from fastai
9
  path = untar_data(URLs.PETS)/'images'
10
  return ImageDataLoaders.from_name_func(
 
17
  dls = get_data()
18
 
19
  # Train the model with vision_learner
20
+ # learn = vision_learner(dls, resnet34, metrics=error_rate)
21
+ # learn.fine_tune(1)
22
 
23
+ # #Export the model
24
+ # learn.path = Path('.')
25
+ # learn.export(
26
+ # 'cats_classifier.pkl'
27
+ # )
28
+
29
+ model = load_learner('cats_classifier.pkl')
30
 
31
+ def predict(image):
32
+ img = PILImage.create(image)
33
+ pred,pred_idx,probs = model.predict(img)
34
+ # print('tt',pred,pred_idx,probs)
35
+ return f"Probability it's a cat: {probs[1].item():.6f}"
36
+
37
+ demo = gr.Interface(fn=model.predict, inputs="image", outputs='text')
38
+ demo.launch()
cats_classifier.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3ae938ddb9d7daf92b295528b5dd019303dea1cc2cc090e01bf230ac0e4b00c5
3
+ size 87564116