smaciu commited on
Commit
a2c2d56
·
1 Parent(s): 3f28275

Push FastAI model using huggingface_hub.

Browse files
Files changed (2) hide show
  1. README.md +14 -82
  2. model.pkl +2 -2
README.md CHANGED
@@ -1,100 +1,32 @@
1
  ---
2
  tags:
3
  - fastai
4
- license: apache-2.0
5
- datasets:
6
- - smaciu/bee-wings-large
7
- - smaciu/bee-wings-small
8
- metrics:
9
- - accuracy
10
- library_name: fastai
11
- pipeline_tag: image-classification
12
  ---
13
 
14
- # HoneyBee wings image classifier
15
 
16
- Model trained based on Fastai vision ResNet18 architecture on Collection of wing images for conservation of honey bees (Apis mellifera) biodiversity in Europe https://zenodo.org/record/7244070
17
 
 
 
18
 
19
- ## Model description
20
-
21
- Model was trained on 2 A-100 GPU using progressive image resizing achieving following results:
22
-
23
- Accuracy:
24
-
25
- ![Accuracy.png](https://s3.amazonaws.com/moonup/production/uploads/648377324e2ed429a675fcde/tZf3MT9-jpy7b06Moulpl.png)
26
-
27
- Confusion matrix:
28
-
29
- ![Confussion_matrix.png](https://s3.amazonaws.com/moonup/production/uploads/648377324e2ed429a675fcde/0P8ti0bEF1ISKncgZR9DJ.png)
30
-
31
- Most Confused:
32
 
33
- ![Most_confused.png](https://s3.amazonaws.com/moonup/production/uploads/648377324e2ed429a675fcde/KjX1g85cFMt_3Neq8lemx.png)
34
 
35
- ### How to use for inference
36
 
37
- ```python
38
 
39
- from fastai.vision.all import *
40
- from huggingface_hub import from_pretrained_fastai
41
- def label_func(f): return f.name[:2]
42
-
43
- learn = from_pretrained_fastai("smaciu/bee-wings-classifier")
44
 
45
- def predict_image(image_path):
46
- img = PILImage.create(image_path)
47
- bee,_,probs = learn.predict(img)
48
- return bee, max(probs)
49
 
50
- # modify the 'path_to_image' with your own path
51
- cat, prob = predict_image('path_to_image')
52
- print(f"Honey bee from: {cat}. {100*prob.item():.2f}%")
53
 
54
- ```
 
55
 
 
 
56
 
57
  ## Training and evaluation data
58
-
59
- ```python
60
-
61
- from fastai.vision.all import *
62
-
63
- from huggingface_hub import from_pretrained_fastai
64
-
65
- from datasets import load_dataset
66
-
67
- def label_func(f): return f.name[:2]
68
-
69
- dataset = load_dataset("smaciu/bee-wings-large", split='train')
70
-
71
- def get_items(o):
72
- return range(len(dataset))
73
-
74
- def get_x(i):
75
- return dataset[i]['image']
76
-
77
- def get_y(i):
78
- return dataset[i]['label']
79
-
80
- bee_wing_stats =([0.7641, 0.7641, 0.7641], [0.1771, 0.1771, 0.1771]) # dataset mean and std to normalise
81
-
82
- # 2. Create a FastAI DataBlock
83
- dls = DataBlock(
84
- blocks=(ImageBlock, CategoryBlock),
85
- get_items=get_items,
86
- get_x=get_x, # function to get the image file path
87
- get_y=get_y, # function to get the image label
88
- splitter=RandomSplitter(valid_pct=0.2), # random split with 20% in validation set
89
- item_tfms=Resize(460), # item transforms
90
- batch_tfms= [Normalize.from_stats(*bee_wing_stats)]).dataloaders(dataset,
91
- bs=64, num_workers=num_cpus(),
92
- pin_memory=True).to('device')
93
-
94
- learn = from_pretrained_fastai("smaciu/bee-wings-classifier").to_channelslast()
95
-
96
- learn.dls = dls
97
-
98
- learn.fit_one_cycle(1, lr_max=1.4858086386360967e-08)
99
-
100
- ```
 
1
  ---
2
  tags:
3
  - fastai
 
 
 
 
 
 
 
 
4
  ---
5
 
6
+ # Amazing!
7
 
8
+ 🥳 Congratulations on hosting your fastai model on the Hugging Face Hub!
9
 
10
+ # Some next steps
11
+ 1. Fill out this model card with more information (see the template below and the [documentation here](https://huggingface.co/docs/hub/model-repos))!
12
 
13
+ 2. Create a demo in Gradio or Streamlit using 🤗 Spaces ([documentation here](https://huggingface.co/docs/hub/spaces)).
 
 
 
 
 
 
 
 
 
 
 
 
14
 
15
+ 3. Join the fastai community on the [Fastai Discord](https://discord.com/invite/YKrxeNn)!
16
 
17
+ Greetings fellow fastlearner 🤝! Don't forget to delete this content from your model card.
18
 
 
19
 
20
+ ---
 
 
 
 
21
 
 
 
 
 
22
 
23
+ # Model card
 
 
24
 
25
+ ## Model description
26
+ More information needed
27
 
28
+ ## Intended uses & limitations
29
+ More information needed
30
 
31
  ## Training and evaluation data
32
+ More information needed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
model.pkl CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:c6c5e69b0d07b42ade288a3811a230f1c563e139aa7547f57d7241bed68a34b0
3
- size 47334545
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d7e638205484e0270e23c799248c7bda6bdfd0136c1f0dd963051ce3fb0eb119
3
+ size 244369577