Skip to content

Commit 60dafe2

Browse files
committed
Fixed a type, added README
1 parent 79cfc99 commit 60dafe2

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed

README.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# PillRecogNet
2+
A convolutional neural network based on ```VGG16```, specialized in recognizing pills from images. This is Part 1 of my Undergraduate Thesis Project @ UniBo, where the Part 2 is an iOS application based on Metal Performance Shaders to run that ConvNet on Apple devices.
3+
4+
This network hasn't been trained from scratch but it uses ```VGG16``` pre-trained weights on ImageNet, together with *bottleneck feature*, *image augmentation*, *transfer learning* and *fine tuning* on a custom dataset made on purpose.
5+
6+
This repository contains all the scripts used to train the net and export its weights so that they can then be used inside the iOS app. Custom pill dataset and intermediate training results won't be provided since these scripts are fairly general, allowing anyone to use them on any dataset. Furthermore, example final trained model and weights can be downloaded from the [Releases](https://github.com/matteodelv/PillRecogNet/releases) page.
7+
A ```p2.xlarge``` instance on Amazon AWS has been used to perform training and fine tuning, lasting about few minutes for feature extraction and about an hour and half for fine tuning on a dataset of almost 1000 images of 1120x1120 pixels.
8+
9+
### Usage on a custom dataset
10+
Before starting to use these scripts, it is mandatory to have a dataset ready and split in ```train/validation/test``` groups, using the following path structure (image names are not important):
11+
12+
data
13+
├── test
14+
│   ├── Class1
15+
│   │   ├── test-image1.jpg
16+
│   │   └── ...
17+
│   ├── Class2
18+
│   │   ├── test-image1.jpg
19+
│   │   └── ...
20+
│   └── Class3
21+
│      ├── test-image1.jpg
22+
│      └── ...
23+
├── train
24+
│   ├── Class1
25+
│   │   ├── train-image1.jpg
26+
│   │   └── ...
27+
│   ├── Class2
28+
│   │   ├── train-image1.jpg
29+
│   │   └── ...
30+
│   └── Class3
31+
│      ├── train-image1.jpg
32+
│      └── ...
33+
└── validation
34+
├── Class1
35+
│   ├── validation-image1.jpg
36+
│   └── ...
37+
├── Class2
38+
│   ├── validation-image1.jpg
39+
│   └── ...
40+
└── Class3
41+
   ├── validation-image1.jpg
42+
   └── ...
43+
**NOTE:** Each class MUST have the same amount of samples in every split
44+
**NOTE:** Class1, Class2, Class3 will be the labels the network will recognize, so name your folder accordingly
45+
46+
After doing so, you can use the script and start training the network.
47+
48+
1. Edit ```settings.py``` accordingly to your dataset, specifying the number of train, validation and test samples, the batch size, the number of classes to recognize and the epochs for feature extraction and fine tuning
49+
2. Launch a terminal, change directory to the scripts folder and start the extraction part issuing these commands: ```cd path/to/downloaded/scripts``` and then ```python bottlenecking.py```
50+
3. After, custom top layers of the network are initialized and they have to be fine tuned, together the last convolutional block of ```VGG16```. Use the following command to do that: ```python fine-tuning.py```
51+
4. When fine tuning is over, you can evaluate the model by predicting on every test image. This is possible by issuing the command ```python model-evaluator.py```. A log file will be generated to check the results
52+
5. Finally, do ```python weights-converter.py``` to load the fine tuned model and extract its weights to use later with Metal Performance Shaders on iOS
53+
54+
**NOTE:** ```params``` will contain the weights in binary format for MPS, ```plots``` will contain the graphs for accuracy and loss, regarding the extraction and the fine tuning part, ```results``` will contain all the data regarding the trained network (mainly ```.npy``` and ```.h5``` files; the latter can be inspected using [HDFView](https://support.hdfgroup.org/products/java/release/download.html))
55+
56+
Feel free to edit the scripts to change optimizers, learning rates and every parameter that can better fit your dataset.
57+
58+
### Requirements
59+
* Python 2.7.14
60+
* Keras 2.0.8
61+
* TensorFlow 1.3.0
62+
* NumPy 1.13
63+
* MatPlotLib 2.1.0

settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
nb_train_samples = 528
1111
nb_validation_samples = 96
1212
botEpochs = 100
13-
ftEpochs = 1
13+
ftEpochs = 50
1414
batch_size = 16
1515
test_batch_size = 12
1616
num_classes = 12

0 commit comments

Comments
 (0)