mrspinn commited on
Commit
4d6887e
1 Parent(s): 8ad0f95

Add image classification functionality with FastAI

Browse files
Files changed (6) hide show
  1. .gitattributes +1 -0
  2. app.py +25 -0
  3. images/cat.jpg +3 -0
  4. images/catdog.jpg +3 -0
  5. images/dog.jpg +3 -0
  6. model.pkl +3 -0
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ *.jpg filter=lfs diff=lfs merge=lfs -text
app.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastai.vision.all import load_learner
2
+ import gradio as gr
3
+ import os
4
+
5
+ def is_cat(x): return x[0].isupper()
6
+
7
+ learn = load_learner('model.pkl')
8
+
9
+ categories = ('Dog', 'Cat')
10
+
11
+ def classify_image(img):
12
+ pred,idx,probs = learn.predict(img)
13
+ return dict(zip(categories, map(float, probs)))
14
+
15
+ image = gr.Image()
16
+ label = gr.Label()
17
+
18
+ # put all images from the images folder into the examples list
19
+ examples = []
20
+ for file in os.listdir("images"):
21
+ if file.endswith(".jpg"):
22
+ examples.append("images/" + file)
23
+
24
+ iface = gr.Interface(fn=classify_image, inputs="image", outputs="label", examples=examples)
25
+ iface.launch()
images/cat.jpg ADDED

Git LFS Details

  • SHA256: 267848bb0a9e30d138b16a81fc5c466dc315924677f284ac08565f6c135aeb82
  • Pointer size: 131 Bytes
  • Size of remote file: 171 kB
images/catdog.jpg ADDED

Git LFS Details

  • SHA256: 6f79dd75471565b7c1315626e2e5d947947354c47f3413d6b1d3eef5492cf83e
  • Pointer size: 130 Bytes
  • Size of remote file: 69.6 kB
images/dog.jpg ADDED

Git LFS Details

  • SHA256: 41ccef6e75ee9840eaf8bfc4791d5593f644d2926616f1867a8ba455b071e62f
  • Pointer size: 130 Bytes
  • Size of remote file: 73.5 kB
model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:99993089d49b046920f11f6fa2b8d997820513dd143c5954e05aacc12fd80313
3
+ size 47064766