Is it possible to use tf.contrib.quantize.create_training_graph
for model quantiation with already trained Keras model?
As I understand I can import tf.Graph
from Keras model, but can I finetune it after modification with tf.contrib.quantize.create_training_graph
?
I was able to call tf.contrib.quantize.create_training_graph(input_graph=K.get_session().graph, quant_delay=int(0))
after model definition and model load, but get:
2019-02-22 14:56:24.216742: W tensorflow/c/c_api.cc:686] Operation '{name:'global_average_pooling2d_1_1/Mean' id:3777 op device:{} def:{global_average_pooling2d_1_1/Mean = Mean[T=DT_FLOAT, Tidx=DT_INT32, keep_dims=false](conv2d_15_1/act_quant/FakeQuantWithMinMaxVars:0, global_average_pooling2d_1_1/Mean/reduction_indices)}}' was changed by updating input tensor after it was run by a session. This mutation will have no effect, and will trigger an error in the future. Either don't modify nodes after running them or create a new session.
At least I was able to save model with uint8 weights when converting to keras->tensorflow->tflite, as I understand input to model and inference is still fp32.
converter = tf.contrib.lite.TFLiteConverter.from_frozen_graph(
graph_def_file='tf_model.pb',
input_arrays=input_node_names,
output_arrays=output_node_names)
converter.post_training_quantize = True
tflite_model = converter.convert()