espejelomar commited on
Commit
615ea5b
1 Parent(s): 874b4e9

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +73 -0
app.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ from backend.util import import_fig, fastai_model, plot
4
+
5
+
6
+ def main():
7
+ st.title("Fastai for classifying")
8
+ st.markdown(
9
+ """
10
+
11
+ Hi! This is the demo for the [espejelomar/fastai-pet-breeds-classification](https://huggingface.co/espejelomar/fastai-pet-breeds-classification) fastai model. Created following the **amazing work of Jeremy Howard and Sylvain Gugger 🤗**.
12
+
13
+ ## Pet breeds classification model
14
+ Finetuned model on The Oxford-IIIT Pet Dataset. It was introduced in
15
+ [this paper](https://www.robots.ox.ac.uk/~vgg/publications/2012/parkhi12a/) and first released in
16
+ [this webpage](https://www.robots.ox.ac.uk/~vgg/data/pets/).
17
+ The pretrained model was trained on the ImageNet dataset, a dataset that has 100,000+ images across 200 differentclasses. It was introduced in [this paper](https://image-net.org/static_files/papers/imagenet_cvpr09.pdf) andavailable [in this webpage] (https:// image-net.org/download.php)
18
+
19
+
20
+ Disclaimer: The model was fine-tuned after [Chapter 5](https://github.com/fastai/fastbook/blob/master/05_pet_breeds.ipynb) of [Deep Learning for Coders with Fastai and Pytorch: AI Applications Without a PhD (2020)](https:/github.com/fastai/fastbook) written by Jeremy Howard and Sylvain Gugger.
21
+
22
+ """
23
+ )
24
+
25
+ image = import_fig()
26
+ outputs_df = fastai_model(image)
27
+
28
+ if outputs_df is not None:
29
+ # st.dataframe(outputs_df)
30
+ st.markdown(
31
+ """### Congratulations!!! Most likely you have uploaded a photo of a..."""
32
+ )
33
+ plot(outputs_df)
34
+
35
+ st.markdown(
36
+ """
37
+ ## Model description
38
+ The model was finetuned using the `cnn_learner` method of the fastai library suing a Resnet 34 backbone pretrained on the ImageNet dataset. The fastai library uses PyTorch for the undelying operations. `cnn_learner` automatically gets a pretrained model from a given architecture with a custom head that is suitable for the target data.
39
+ Resnet34 is a 34 layer convolutional neural network. It takes residuals from each layer and uses them in the subsequent connected layers.
40
+ Specifically the model was obtained:
41
+ ```
42
+ learn = cnn_learner(dls, resnet34, metrics=error_rate)
43
+ learn.fine_tune(2)
44
+ ```
45
+
46
+ ## Training data
47
+ The Resnet34 model was pretrained on [ImageNet](https://image-net.org/static_files/papers/imagenet_cvpr09.pdf), a dataset that has 100,000+ images across 200 different classes, and fine-tuned on [The Oxford-IIIT Pet Dataset](https://www.robots.ox.ac.uk/~vgg/data/ pets/).
48
+ ## Preprocessing
49
+ For more detailed information on the preprocessing procedure, refer to the [Chapter 5](https://github.com/fastai/fastbook/blob/ master/05_pet_breeds.ipynb) of [Deep Learning for Coders with Fastai and Pytorch: AI Applications Without a PhD (2020)](https:// github.com/fastai/fastbook).
50
+ Two main strategies are followed to presizing the images:
51
+ - Resize images to relatively "large" dimensions—that is, dimensions significantly larger than the target training dimensions.
52
+ - Compose all of the common augmentation operations (including a resize to the final target size) into one, and perform the combined operation on the GPU only once at the end of processing, rather than performing the operations individually and interpolating multiple times.
53
+ "The first step, the resize, creates images large enough that they have spare margin to allow further augmentation transforms on their inner regions without creating empty zones. This transformation works by resizing to a square, using a large crop size. On the training set, the crop area is chosen randomly, and the size of the crop is selected to cover the entire width or height of the image, whichever is smaller.
54
+ In the second step, the GPU is used for all data augmentation, and all of the potentially destructive operations are done together, with a single interpolation at the end." ([Howard and Gugger, 2020](https://github.com/fastai/fastbook))
55
+
56
+ ### BibTeX entry and citation info
57
+ ```bibtex
58
+ @book{howard2020deep,
59
+ author = {Howard, J. and Gugger, S.},
60
+ title = {Deep Learning for Coders with Fastai and Pytorch: AI Applications Without a PhD},
61
+ isbn = {9781492045526},
62
+ year = {2020},
63
+ url = {https://books.google.no/books?id=xd6LxgEACAAJ},
64
+ publisher = {O'Reilly Media, Incorporated},
65
+ }
66
+ ```
67
+
68
+ """
69
+ )
70
+
71
+
72
+ if __name__ == "__main__":
73
+ main()