TF-slim
is a new lightweight high-level API of TensorFlow (tensorflow.contrib.slim)
for defining, training and evaluating complex
models. This directory contains
code for training and evaluating several widely used Convolutional Neural
Network (CNN) image classification models using TF-slim.
It contains scripts that will allow
you to train models from scratch or fine-tune them from pre-trained network
weights. It also contains code for downloading standard image datasets,
converting them
to TensorFlow's native TFRecord format and reading them in using TF-Slim's
data reading and queueing utilities.
^ ResNet V2 models use Inception pre-processing and input image size of 299 (use
--preprocessing_name inception --eval_image_size 299 when using
eval_image_classifier.py). Performance numbers for ResNet V2 models are
reported on the ImageNet validation set.
(#) More information and details about the NASNet architectures are available at this README
All 16 float MobileNet V1 models reported in the MobileNet Paper and all 16 quantized TensorFlow Lite compatible MobileNet V1 models can be found here.
(^#) More details on MobileNetV2 models can be found here.
(*): Results quoted from the paper.
1. Create a file structure like this for your data
$TRAIN_DIR/dog/image0.jpeg
$TRAIN_DIR/dog/image1.jpg
$TRAIN_DIR/dog/image2.png
...
$TRAIN_DIR/cat/weird-image.jpeg
$TRAIN_DIR/cat/my-image.jpeg
$TRAIN_DIR/cat/my-image.JPG
...
$VALIDATION_DIR/dog/imageA.jpeg
$VALIDATION_DIR/dog/imageB.jpg
$VALIDATION_DIR/dog/imageC.png
...
$VALIDATION_DIR/cat/weird-image.PNG
$VALIDATION_DIR/cat/that-image.jpg
$VALIDATION_DIR/cat/cat.JPG
...
and a label file:
daisy
dandelion
roses
sunflowers
tulips
2. Convert the file structure to tf_records:
python download_and_convert_data.py \
--input_dataset_dir=data/random \
--output_dataset_dir=data/random_tf \
--num_of_shards=5 \
--num_of_threads=5
3. Convert the file structure to tf_records: Change the training and validation split size in datasets/standard_dataset.py
4. Download an imagenet pretrained network according to your requirements from the above link:
wget http://download.tensorflow.org/models/inception_v3_2016_08_28.tar.gz
and the extract it to a directory defined by the checkpoint_path in Step 4.
5. Train your classifier using:
python train_image_classifier.py \
--train_dir=inception_v3_logs \
--dataset_dir=random_tf \
--dataset_name=standard \
--dataset_split_name=train \
--model_name=inception_v3 \
--checkpoint_path=checkpoints/inception_v3.ckpt \
--checkpoint_exclude_scopes=InceptionV3/Logits,InceptionV3/AuxLogits \
--trainable_scopes=InceptionV3/Logits \
--optimizer=adam \
--log_every_n_steps=100 \
- class balanced cross entropy
- custom data augmentation pipeline definitions
- Cylcic Learning Rates