Need help with keras-finetuning?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.


Training an InceptionV3-based image classifier with your own dataset

130 Stars 36 Forks 18 Commits 7 Opened issues

Services available

Need anything else?

Training an InceptionV3-based image classifier with your own dataset

Based on the Fine-tune InceptionV3 on a new set of classes example in


Very latest (>=1.0.8 from source) Keras, scipy, pillow. opencv2 is only used in the toy webcam app. See for installation instructions on OS X.


Structure your image files in the following directory hierarchy. Sub-sub directories are allowed and traversed:


It depends on the domain, but a few hundred images per class can already give good results.

Run the training:

python data_dir model

The standard output provides information about the state of the training, and the current accuracy. Accuracy is measured on a random 20% validation set. During training, Keras outputs the accuracy on the augmented validation dataset (

). After a training round, the validation accuracy on non-augmented data is printed.

The files

etc. give a visual confusion matrix about the progress of the training.
is created after the newly created dense layers were trained, and the rest during fine-tuning.

The model is saved in three files, named


Webcam integration

If you train the model with the labeled faces of your friends and relatives, you can test your classifier in a toy app.

python model

This does face detection on the webcam stream, and tags the detected faces according to the neural model. It looks for the

files in the current directory. The file
must also be there.

Webcam data is quite different from photos, so to let the model generalize, set

heavy_augmentation = True
. For other applications,
heavy_augmentation = False
might be preferable.

Apple Photos: a great source of training data for face recognition

OS X Photos users can find high quality training data in the Photos Libraries of that application. Mihály Köles and I have reverse engineered the database format of Photos, and the result is an easy-to-use tool for building your personalized face recognition training datasets from Photos Libraries:

bash "$HOME/Pictures/Photos Library.photoslibrary" photos_library_dataset

The output of the above script is the

directory that has exactly the right layout to be used as input for the training script:
python photos_library_dataset model
python model

Of course, very small label classes won't generalize well to unseen data. It might make sense to consolidate their contents into the generic

label class, which contains faces not yet labeled by Apple Photos:
mv photos_library_dataset/too_small_class/* photos_library_dataset/unknown
rmdir photos_library_dataset/too_small_class

If you simply remove the

directory from the dataset before training, that leads to a "closed world" model that assumes that everyone appearing on your webcam stream has his or her Photos label.

The Photos Library data layout

For those interested, here's a bit more information about the Photos data layout. (Look into the source code of
for all relevant detail.)
contains the manually and semi-automatically tagged faces cropped from your photos, and the
sqlite3 databases describe the correspondence between persons and cropped photos. The relevant tables for our purposes are
, and

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.