This is a convenient wrapper for feature extraction or classification in TensorFlow. Given well known pre-trained models on ImageNet, the extractor runs over a list or directory of images. Optionally, features can be saved as HDF5 file. It supports all the pre-trained models listed on the official page.
TensorFlow models tested:
- Inception v1-v4
- ResNet v1 and v2
- VGG 16-19
- TensorFlow (tested with version 1.3)
- TensorFlow Models
- The usual suspects:
numpy,scipy. - Optionally
h5pyfor saving features to HDF5 file
- Checkout the TensorFlow
modelsrepository somewhere on your machine. The path where you checkout the repository will be denoted<checkout_dir>/models
git clone https://github.com/tensorflow/models/
- Add the directory
<checkout_dir>/research/slimto the$PYTHONPATHvariable. Or add a line to your.bashrcfile.
export PYTHONPATH="<checkout_dir>/research/slim:$PYTHONPATH"
- Download the model checkpoints from the official page.
There are two example files, one for classification and one for feature extraction.
ResNet-v1-101
example_feat_extract.py
--network resnet_v1_101
--checkpoint ./checkpoints/resnet_v1_101.ckpt
--image_path ./images_dir/
--out_file ./features.h5
--num_classes 1000
--layer_names resnet_v1_101/logits
ResNet-v2-101
example_feat_extract.py
--network resnet_v2_101
--checkpoint ./checkpoints/resnet_v2_101.ckpt
--image_path ./images_dir/
--out_file ./features.h5
--layer_names resnet_v2_101/logits
--preproc_func inception
Inception-v4
example_feat_extract.py
--network inception_v4
--checkpoint ./checkpoints/inception_v4.ckpt
--image_path ./images_dir/
--out_file ./features.h5
--layer_names Logits
Inception-ResNet-v2
example_feat_extract.py \
--network inception_resnet_v2 \
--checkpoint ../../checkpoints/inception_resnet_v2_2016_08_30.ckpt \
--image_path ../../data/FashionMNIST_28x28/ \
--out_file ../../data/FashionMNIST_28x28.inception_resnet_v2.h5 \
--num_classes 1001 \
--preproc_func inception \
--layer_names Logits \
VGG-16
example_feat_extract.py \
--network vgg_16 \
--checkpoint ../../checkpoints/vgg_16.ckpt \
--image_path ../../data/FashionMNIST_28x28/ \
--out_file ../../data/FashionMNIST_28x28.vgg_16.h5 \
--num_classes 1000 \
--layer_names vgg_16/fc6 \
ResNet-v1-101
example_feat_extract.py
--network resnet_v1_101
--checkpoint ./checkpoints/resnet_v1_101.ckpt
--image_path ./imagenet/
--out_file ./imagenet.resnet_v1_101.global_pool.h5
--num_classes 1000
--layer_names global_pool
--class_by_class yes
example_classification.py
--network resnet_v1_101
--checkpoint ./checkpoints/resnet_v1_101.ckpt
--image_path ./images_dir/
--num_classes 1000
--logits_name resnet_v1_101/logits
Save image file names to HDF5 fileSupport for multi-threaded preprocessing