- Download dataset from here
- Uncompress the dataset to
PETA
, it should contain 10 subfolders like this
drwxrwxr-x 3 dola dola 4096 Oct 20 2014 3DPeS
drwxrwxr-x 3 dola dola 4096 Oct 20 2014 CAVIAR4REID
drwxrwxr-x 3 dola dola 4096 Oct 20 2014 CUHK
drwxrwxr-x 3 dola dola 4096 Oct 20 2014 GRID
drwxrwxr-x 3 dola dola 4096 Oct 20 2014 i-LID
drwxrwxr-x 3 dola dola 4096 Oct 20 2014 MIT
drwxrwxr-x 3 dola dola 4096 Oct 20 2014 PRID
drwxrwxr-x 3 dola dola 4096 Oct 20 2014 SARC3D
drwxrwxr-x 3 dola dola 4096 Oct 20 2014 TownCentre
drwxrwxr-x 3 dola dola 4096 Oct 20 2014 VIPeR
- organize the photos into two subfolders
male
andfemale
by running
python generate_dataset.py --peta_dir ./PETA --train_dir ./train
- train with tensorflow.hub Inception v3
python ~/ws/hub/examples/image_retraining/retrain.py \
--image_dir train \
--output_graph model/gender_graph.pb \
--output_labels model/gender_labels.txt \
--how_many_training_steps 4000 \
- freeze the model with
strip_unused
andquantization
python ~/ws/tensorflow/tensorflow/python/tools/strip_unused.py \
--input_graph=./model/gender_graph.pb \
--output_graph=./model/stripped_gender_graph.pb \
--input_node_names=Placeholder \
--output_node_names=final_result \
--input_binary=true
and
python ~/ws/tensorflow/tensorflow/tools/quantization/quantize_graph.py \
--input=model/stripped_gender_graph.pb \
--output_node_names=final_result \
--output=model/quantized_stripped_gender_graph.pb \
--mode=weights
- deploy to the mobile tf_classify app and run by changing the following in
ClassifierActivity.java
private static final int INPUT_SIZE = 299;
private static final int IMAGE_MEAN = 128;
private static final float IMAGE_STD = 128;
private static final String INPUT_NAME = "Placeholder";
private static final String OUTPUT_NAME = "final_result";
private static final String MODEL_FILE = "file:///android_asset/quantized_stripped_gender_graph.pb";
private static final String LABEL_FILE =
"file:///android_asset/dog_retrained_labels.txt";