Skip to content

Commit 34a52de

Browse files
authored
Merge branch 'master' into patch-1
2 parents 5db7ff3 + 3a3aaab commit 34a52de

File tree

204 files changed

+30000
-549
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

204 files changed

+30000
-549
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
## Description
2+
3+
This repository contains classification pipeline for experiments with tricks listed in
4+
["Bag of Tricks for Image Classification with Convolutional Neural Networks"](https://arxiv.org/abs/1812.01187). Visit [our blogpost](https://www.learnopencv.com/bag-of-tricks-for-image-classification-lets-check-if-it-is-working-or-not/) for more details.
5+
6+
The pipeline is based on [pytorch-lightning framework](https://github.com/PyTorchLightning/pytorch-lightning).
7+
8+
### Installation
9+
10+
1. Clone the repository;
11+
2. Set up the virtual environment;
12+
3. If you are going to run experiments with mixed-precision:
13+
14+
- Check you CUDA version with `nvcc --version`;
15+
- Install pytorch 1.5.1 compiled with CUDA version which you have installed. In our case it is CUDA 10.1 so the
16+
pytorch should be installed with
17+
`pip install torch==1.5.1+cu101 -f https://download.pytorch.org/whl/torch_stable.html`;
18+
- Install Nvidia Apex by following [the official instructions](https://github.com/NVIDIA/apex#quick-start);
19+
Otherwise:
20+
- Run `pip install torch==1.5.1` to install PyTorch
21+
22+
4. Run `pip install -r requirements.txt`
23+
24+
### Dataset
25+
26+
Please, follow the instruction to prepare the dataset:
27+
28+
- Download zip-archive from kaggle ([link](https://www.kaggle.com/dansbecker/food-101/));
29+
- Unzip the data;
30+
- Use `split_food-101.py` to split Food-101 into train/test folders. This script will parse `train.txt` and `test.txt`
31+
and copy images into corresponding sub-folders. Note that we hard-coded the classes which we are going to use.
32+
33+
### Training
34+
35+
To train model launch
36+
37+
```
38+
python main.py --gpus [gpus_number] --max_epochs [epoch_number] --data-root [path_to_dataset] --amp_level [optimization_level] (only for mixed-precision with apex)
39+
```
40+
41+
You can turn on any trick by adding the corresponding key:
42+
43+
```
44+
--use-smoothing for label smoothing;
45+
--use-mixup for mixup augmentation;
46+
--use-cosine-scheduler for Cosine LR Scheduler;
47+
--use-knowledge-distillation for Knowledge Distillation;
48+
```
49+
50+
_Note:_ If you want to train the model on GPU you should always use `--gpus` key, without it the pytorch lightning
51+
console log will show you that the GPU is used but the training will be performed on CPU.
52+
53+
For Knowledge Distillation, please, download the teacher weights from
54+
[Dropbox](https://www.dropbox.com/s/za5eeyhhy6pmpd2/bag_of_tricks_resnet50_teacher.ckpt?dl=0).
55+
56+
Run `python main.py --help` to see all possible arguments. This command will also show you the arguments for pytorch
57+
lightning Trainer. Please, see the
58+
[official documentation](https://pytorch-lightning.readthedocs.io/en/0.8.5/trainer.html#trainer-flags) for details about
59+
them.
60+
61+
### Testing
62+
63+
To evaluate a trained model launch
64+
65+
```
66+
python main.py --gpus [gpus_number] --data-root [path_to_dataset] -e --checkpoint [path_to_checkpoint]
67+
```
68+
69+
### Colab Notebook
70+
71+
You can also train a colab-based version of this model:
72+
73+
[Open in Colab](https://colab.research.google.com/github/spmallick/learnopencv/blob/master/Bag-Of-Tricks-For-Image-Classification/bag-of-tricks-colab.ipynb)
74+
75+
## AI Courses by OpenCV
76+
77+
Want to become an expert in AI? [AI Courses by OpenCV](https://opencv.org/courses/) is a great place to start.
78+
79+
<a href="https://opencv.org/courses/">
80+
<p align="center">
81+
<img src="https://www.learnopencv.com/wp-content/uploads/2020/04/AI-Courses-By-OpenCV-Github.png">
82+
</p>
83+
</a>

0 commit comments

Comments
 (0)