forked from foamliu/Car-Recognition
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.template
105 lines (75 loc) · 4.52 KB
/
README.template
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# Car Recognition
This repository is to do car recognition by fine-tuning ResNet-152 with Cars Dataset from Stanford.
## Dependencies
- [NumPy](http://docs.scipy.org/doc/numpy-1.10.1/user/install.html)
- [Tensorflow](https://www.tensorflow.org/versions/r0.8/get_started/os_setup.html)
- [Keras](https://keras.io/#installation)
- [OpenCV](https://opencv-python-tutroals.readthedocs.io/en/latest/)
## Dataset
We use the Cars Dataset, which contains 16,185 images of 196 classes of cars. The data is split into 8,144 training images and 8,041 testing images, where each class has been split roughly in a 50-50 split.
![image](https://github.com/foamliu/Car-Recognition/raw/master/images/random.jpg)
You can get it from [Cars Dataset](https://ai.stanford.edu/~jkrause/cars/car_dataset.html):
```bash
$ cd Car-Recognition
$ wget http://imagenet.stanford.edu/internal/car196/cars_train.tgz
$ wget http://imagenet.stanford.edu/internal/car196/cars_test.tgz
$ wget --no-check-certificate https://ai.stanford.edu/~jkrause/cars/car_devkit.tgz
```
## ImageNet Pretrained Models
Download [ResNet-152](https://drive.google.com/file/d/0Byy2AcGyEVxfeXExMzNNOHpEODg/view?usp=sharing) into models folder.
## Usage
### Data Pre-processing
Extract 8,144 training images, and split them by 80:20 rule (6,515 for training, 1,629 for validation):
```bash
$ python pre_process.py
```
### Train
```bash
$ python train.py
```
If you want to visualize during training, run in your terminal:
```bash
$ tensorboard --logdir path_to_current_dir/logs
```
![image](https://github.com/foamliu/Car-Recognition/raw/master/images/train.jpg)
### Analysis
Update "model_weights_path" in "utils.py" with your best model, and use 1,629 validation images for result analysis:
```bash
$ python analyze.py
```
#### Validation acc:
**88.70%**
#### Confusion matrix:
![image](https://github.com/foamliu/Car-Recognition/raw/master/images/confusion_matrix.jpg)
### Test
```bash
$ python test.py
```
Submit predictions of test data set (8,041 testing images) at [Cars Dataset](https://ai.stanford.edu/~jkrause/cars/car_dataset.html), evaluation result:
#### Test acc:
**88.88%**
![image](https://github.com/foamliu/Car-Recognition/raw/master/images/test.jpg)
### Demo
Download [pre-trained model](https://github.com/foamliu/Car-Recognition/releases/download/v1.0/model.96-0.89.hdf5) into "models" folder then run:
```bash
$ python demo.py --i [image_path]
```
If no argument, a sample image is used:
![image](https://github.com/foamliu/Car-Recognition/raw/master/images/samples/07647.jpg)
```bash
$ python demo.py
class_name: Lamborghini Reventon Coupe 2008
prob: 0.9999994
```
1 | 2 | 3 | 4 |
|---|---|---|---|
|![image](https://github.com/foamliu/Car-Recognition/raw/master/images/0_out.png) | ![image](https://github.com/foamliu/Car-Recognition/raw/master/images/1_out.png) | ![image](https://github.com/foamliu/Car-Recognition/raw/master/images/2_out.png)|![image](https://github.com/foamliu/Car-Recognition/raw/master/images/3_out.png) |
|$(result_0)|$(result_1)|$(result_2)|$(result_3)|
|![image](https://github.com/foamliu/Car-Recognition/raw/master/images/4_out.png) | ![image](https://github.com/foamliu/Car-Recognition/raw/master/images/5_out.png) | ![image](https://github.com/foamliu/Car-Recognition/raw/master/images/6_out.png)|![image](https://github.com/foamliu/Car-Recognition/raw/master/images/7_out.png) |
|$(result_4)|$(result_5)|$(result_6)|$(result_7)|
|![image](https://github.com/foamliu/Car-Recognition/raw/master/images/8_out.png) | ![image](https://github.com/foamliu/Car-Recognition/raw/master/images/9_out.png) | ![image](https://github.com/foamliu/Car-Recognition/raw/master/images/10_out.png)|![image](https://github.com/foamliu/Car-Recognition/raw/master/images/11_out.png)|
|$(result_8)|$(result_9)|$(result_10)|$(result_11)|
|![image](https://github.com/foamliu/Car-Recognition/raw/master/images/12_out.png) | ![image](https://github.com/foamliu/Car-Recognition/raw/master/images/13_out.png)| ![image](https://github.com/foamliu/Car-Recognition/raw/master/images/14_out.png)|![image](https://github.com/foamliu/Car-Recognition/raw/master/images/15_out.png)|
|$(result_12)|$(result_13)|$(result_14)|$(result_15)|
|![image](https://github.com/foamliu/Car-Recognition/raw/master/images/16_out.png) | ![image](https://github.com/foamliu/Car-Recognition/raw/master/images/17_out.png)|![image](https://github.com/foamliu/Car-Recognition/raw/master/images/18_out.png) | ![image](https://github.com/foamliu/Car-Recognition/raw/master/images/19_out.png)|
|$(result_16)|$(result_17)|$(result_18)|$(result_19)|