dennisjooo commited on
Commit
9aa8dc0
1 Parent(s): d128c80

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +133 -0
README.md ADDED
@@ -0,0 +1,133 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ base_model: google/efficientnet-b2
4
+ metrics:
5
+ - accuracy
6
+ pipeline_tag: image-classification
7
+ tags:
8
+ - biology
9
+ - vision
10
+ - image-classification
11
+ widgets:
12
+ - src: https://upload.wikimedia.org/wikipedia/commons/thumb/4/45/Eopsaltria_australis_-_Mogo_Campground.jpg/640px-Eopsaltria_australis_-_Mogo_Campground.jpg
13
+ example_title: Eastern Yellow Robin
14
+ - src: https://peregrinefund.org/sites/default/files/styles/raptor_banner_600x430/public/2019-11/raptor-er-bald-eagle-portrait-screaming-james-bodkin.jpg?itok=ruN52TUp
15
+ example_title: Bald Eagle
16
+ ---
17
+
18
+ # Bird Classifier EfficientNet-B2
19
+
20
+ ## Model Description
21
+
22
+ This model is a fine-tuned version of [google/efficientnet-b2](https://huggingface.co/google/efficientnet-b2)
23
+ on the [gpiosenka/100-bird-species](https://www.kaggle.com/datasets/gpiosenka/100-bird-species) dataset available on Kaggle.
24
+ The dataset used to train the model was taken on September 24th, 2023.
25
+
26
+ In theory, the accuracy for a random guess on this dataset is 0.0019047619 (essentially 1/525).
27
+ The model performed significantly well on all three sets with result being:
28
+
29
+ - **Training**: 0.999480
30
+ - **Validation**: 0.985904
31
+ - **Test**: 0.991238
32
+
33
+ ## Intended Uses
34
+
35
+ You can use the raw model for image classification. See the [model hub](https://huggingface.co/models?search=efficientnet) to look for
36
+ fine-tuned versions on a task that interests you.
37
+
38
+ Here is an example of the model in action using a picture of a bird
39
+
40
+ ```python
41
+ # Importing the libraries needed
42
+ import torch
43
+ import urllib.request
44
+ from PIL import Image
45
+ from transformers import EfficientNetImageProcessor, EfficientNetForImageClassification
46
+
47
+ # Determining the file URL
48
+ url = 'https://images.unsplash.com/photo-1444464666168-49d633b86797?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8Mnx8YmlyZHxlbnwwfHwwfHx8MA%3D%3D&w=1000&q=80'
49
+
50
+ # Opening the image using PIL
51
+ img = Image.open(urllib.request.urlretrieve(url)[0])
52
+
53
+ # Loading the model and preprocessor from HuggingFace
54
+ preprocessor = EfficientNetImageProcessor.from_pretrained("dennisjooo/Birds-Classifier-EfficientNetB2")
55
+ model = EfficientNetForImageClassification.from_pretrained("dennisjooo/Birds-Classifier-EfficientNetB2")
56
+
57
+ # Preprocessing the input
58
+ inputs = preprocessor(img, return_tensors="pt")
59
+
60
+ # Running the inference
61
+ with torch.no_grad():
62
+ logits = model(**inputs).logits
63
+
64
+ # Getting the predicted label
65
+ predicted_label = logits.argmax(-1).item()
66
+ print(model.config.id2label[predicted_label])
67
+ ```
68
+
69
+ Or alternatively you can streamline it using Huggingface's Pipeline
70
+
71
+ ```python
72
+ # Importing the libraries needed
73
+ import torch
74
+ import urllib.request
75
+ from PIL import Image
76
+ from transformers import pipeline
77
+
78
+ # Determining the file URL
79
+ url = 'https://images.unsplash.com/photo-1444464666168-49d633b86797?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8Mnx8YmlyZHxlbnwwfHwwfHx8MA%3D%3D&w=1000&q=80'
80
+
81
+ # Opening the image using PIL
82
+ img = Image.open(urllib.request.urlretrieve(url)[0])
83
+
84
+ # Loading the model and preprocessor using Pipeline
85
+ pipe = pipeline("image-classification", model="dennisjooo/Birds-Classifier-EfficientNetB2")
86
+
87
+ # Running the inference
88
+ result = pipe(img)[0]
89
+
90
+ # Printing the result label
91
+ print(result['label'])
92
+ ```
93
+
94
+ ## Training and Evaluation
95
+
96
+ ### Data
97
+
98
+ The dataset was taken from [gpiosenka/100-bird-species](https://www.kaggle.com/datasets/gpiosenka/100-bird-species) on Kaggle.
99
+ It contains a set of 525 bird species, with 84,635 training images, 2,625 each for validation and test images.
100
+ Every image in the dataset is a 224 by 224 RGB image.
101
+
102
+ The training process used the same split provided by the author.
103
+ For more details, please refer to the [author's Kaggle page](https://www.kaggle.com/datasets/gpiosenka/100-bird-species).
104
+
105
+ ### Training Procedure
106
+
107
+ The training was done using PyTorch on Kaggle's free P100 GPU. The process also includes the usage of Lightning and Torchmetrics libraries.
108
+
109
+ ### Preprocessing
110
+ Each image is preprocessed according to the the orginal author's [config](https://huggingface.co/google/efficientnet-b2/blob/main/preprocessor_config.json).
111
+
112
+ The training set was also augmented using:
113
+
114
+ - Random rotation of 10 degrees with probability of 50%
115
+ - Random horizontal flipping with probability of 50%
116
+
117
+ ### Training Hyperparameters
118
+
119
+ The following are the hyperparameters used for training:
120
+
121
+ - **Training regime:** fp32
122
+ - **Optimizer**: Adam with default betas
123
+ - **Learning rate**: 1e-3
124
+ - **Learning rate scheduler**: Reduce on plateau which monitors validation loss with patience of 2 and decay rate of 0.1
125
+ - **Batch size**: 64
126
+ - **Early stopping**: Monitors validation accuracy with patience of 10
127
+
128
+ ### Results
129
+
130
+ The image below is the result of the training process both on the training and validation set:
131
+
132
+ ![Training results](https://drive.google.com/uc?export=view&id=1cf1gPGiP9ItoFDGcyrXxC7OHdxTYkYlM)
133
+