Hi ,
I trained a tflite for image segmentation with MobileNetV3+DeeplabV3+PascalVOC, check out the model and compare with deepLab_v3, the diff input quantization, how to change the input quant to fit the input of Android tflite demo app, thanks a lot.
Attach pb tflite convert script
import os
import numpy as np
import tensorflow as tf
print(tf.__version__)
MODEL_FILE = "frozen_inference_graph_257.pb"
# Load the Tensorflow model
converter = tf.compat.v1.lite.TFLiteConverter.from_frozen_graph(
graph_def_file = MODEL_FILE,
input_arrays = ['sub_2'], # For the Xception model it needs to be `sub_7`, for MobileNet it would be `sub_2`
output_arrays = ['ResizeBilinear_2'],
input_shapes={'sub_2':[1,257,257,3]}
)
# Default Optimization is choosen
converter.optimizations = [tf.lite.Optimize.DEFAULT]
# Convert to TFLite Model
tflite_model = converter.convert()
# Save the model as tflite format.
tflite_path = "deeplabv3_mnv2_custom_257.tflite"
tflite_model_size = open(tflite_path, 'wb').write(tflite_model)
Procedure:
git clone --depth 1 https://github.com/tensorflow/models.git
curl -sc /tmp/cookie "https://drive.google.com/uc?export=download&id=1rATNHizJdVHnaJtt-hW9MOgjxoaajzdh" > /dev/null
CODE="$(awk '/_warning_/ {print $NF}' /tmp/cookie)"
curl -Lb /tmp/cookie "https://drive.google.com/uc?export=download&confirm=${CODE}&id=1rATNHizJdVHnaJtt-hW9MOgjxoaajzdh" -o pascal_voc_seg/VOCtrainval_11-May-2012.tar
sed -i -e "s/python .\/remove_gt_colormap.py/python3 .\/remove_gt_colormap.py/g" -i -e "s/python .\/build_voc2012_data.py/python3 .\/build_voc2012_data.py/g" download_and_convert_voc2012.sh
sh download_and_convert_voc2012.sh
mkdir -p deeplab/datasets/pascal_voc_seg/exp/train_on_train_set/train
mkdir -p deeplab/datasets/pascal_voc_seg/exp/train_on_train_set/eval
mkdir -p deeplab/datasets/pascal_voc_seg/exp/train_on_train_set/vis
export PATH_TO_TRAIN_DIR=${HOME}/deeplab/models/research/deeplab/datasets/pascal_voc_seg/exp/train_on_train_set/train
export PATH_TO_DATASET=${HOME}/deeplab/models/research/deeplab/datasets/pascal_voc_seg/tfrecord
export PYTHONPATH=${HOME}/deeplab/models/research:${HOME}/deeplab/models/research/deeplab:${HOME}/deeplab/models/research/slim:${PYTHONPATH}
python deeplab/train.py \
--logtostderr \
--training_number_of_steps=500000 \
--train_split="train" \
--model_variant="mobilenet_v3_small_seg" \
--decoder_output_stride=16 \
--train_crop_size="513,513" \
--train_batch_size=8 \
--dataset="pascal_voc_seg" \
--save_interval_secs=300 \
--save_summaries_secs=300 \
--save_summaries_images=True \
--log_steps=100 \
--train_logdir=${PATH_TO_TRAIN_DIR} \
--dataset_dir=${PATH_TO_DATASET}
python deeplab/export_model.py --model_variant="mobilenet_v3_small_seg" --crop_size=257 --crop_size=257 --checkpoint_path=${PATH_TO_TRAIN_DIR}/model.ckpt-1871 --export_path=./deeplabv3_mnv2_pascal_trainval/frozen_inference_graph_257.pb
`
examples/lite/examples/image_segmentation/android
git clone https://github.com/tensorflow/examples