版本: Tensorflow v1.9.0-rc2-5420-g411b9ba 1.11.0-rc1(摘自github repo,2018年10月9日)
操作系统: Ubuntu 16.04.5 LTS
Python 3.5.2
我有一个tensorflow模型,有两种格式,第一种是冻结图定义(pb)文件,第二种是Keras模型(h5)文件。
通过pb文件:
toco --graph_def_file=./model.pb --output_file=./model.tflite --inference_type=FLOAT --input_type=FLOAT --input_arrays=input_1 --output_arrays=out0 --allow_custom_operators
收益:
2018-10-09 12:24:55.039391: I tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.cc:39] Before Removing unused ops: 5705 operators, 7732 arrays (0 quantized)
2018-10-09 12:24:55.664965: I tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.cc:39] Before general graph transformations: 5705 operators, 7732 arrays (0 quantized)
2018-10-09 12:24:56.867861: I tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 1: 4908 operators, 9078 arrays (0 quantized)
2018-10-09 12:24:57.400037: F tensorflow/contrib/lite/toco/graph_transformations/propagate_fixed_sizes.cc:1442] Check failed: axis < input_shape.dimensions_count() (90746776 vs. 4)
Aborted (core dumped)'
None
有趣的是,错误的90746776(轴)值在连续调用之间发生了变化
通过h5文件
toco --keras_model_file=./model.h5 --output_file=./model.tflite --inference_type=FLOAT --input_type=FLOAT --input_arrays=input_1 --output_arrays=out0 --allow_custom_ops
收益:
Traceback (most recent call last):
File "/home/joseph/.local/bin/toco", line 11, in <module>
sys.exit(main())
File "/home/joseph/.local/lib/python3.5/site-packages/tensorflow/contrib/lite/python/tflite_convert.py", line 412, in main
app.run(main=run_main, argv=sys.argv[:1])
File "/home/joseph/.local/lib/python3.5/site-packages/tensorflow/python/platform/app.py", line 125, in run
_sys.exit(main(argv))
File "/home/joseph/.local/lib/python3.5/site-packages/tensorflow/contrib/lite/python/tflite_convert.py", line 408, in run_main
_convert_model(tflite_flags)
File "/home/joseph/.local/lib/python3.5/site-packages/tensorflow/contrib/lite/python/tflite_convert.py", line 100, in _convert_model
converter = _get_toco_converter(flags)
File "/home/joseph/.local/lib/python3.5/site-packages/tensorflow/contrib/lite/python/tflite_convert.py", line 87, in _get_toco_converter
return converter_fn(**converter_kwargs)
File "/home/joseph/.local/lib/python3.5/site-packages/tensorflow/contrib/lite/python/lite.py", line 368, in from_keras_model_file
keras_model = _keras.models.load_model(model_file)
File "/home/joseph/.local/lib/python3.5/site-packages/tensorflow/python/keras/engine/saving.py", line 230, in load_model
model = model_from_config(model_config, custom_objects=custom_objects)
File "/home/joseph/.local/lib/python3.5/site-packages/tensorflow/python/keras/engine/saving.py", line 310, in model_from_config
return deserialize(config, custom_objects=custom_objects)
File "/home/joseph/.local/lib/python3.5/site-packages/tensorflow/python/keras/layers/serialization.py", line 64, in deserialize
printable_module_name='layer')
File "/home/joseph/.local/lib/python3.5/site-packages/tensorflow/python/keras/utils/generic_utils.py", line 173, in deserialize_keras_object
list(custom_objects.items())))
File "/home/joseph/.local/lib/python3.5/site-packages/tensorflow/python/keras/engine/network.py", line 1298, in from_config
process_layer(layer_data)
File "/home/joseph/.local/lib/python3.5/site-packages/tensorflow/python/keras/engine/network.py", line 1284, in process_layer
layer = deserialize_layer(layer_data, custom_objects=custom_objects)
File "/home/joseph/.local/lib/python3.5/site-packages/tensorflow/python/keras/layers/serialization.py", line 64, in deserialize
printable_module_name='layer')
File "/home/joseph/.local/lib/python3.5/site-packages/tensorflow/python/keras/utils/generic_utils.py", line 173, in deserialize_keras_object
list(custom_objects.items())))
File "/home/joseph/.local/lib/python3.5/site-packages/tensorflow/python/keras/engine/sequential.py", line 340, in from_config
model.add(layer)
File "/home/joseph/.local/lib/python3.5/site-packages/tensorflow/python/training/checkpointable/base.py", line 474, in _method_wrapper
method(self, *args, **kwargs)
File "/home/joseph/.local/lib/python3.5/site-packages/tensorflow/python/keras/engine/sequential.py", line 175, in add
output_tensor = layer(self.outputs[0])
File "/home/joseph/.local/lib/python3.5/site-packages/tensorflow/python/keras/engine/base_layer.py", line 746, in __call__
self.build(input_shapes)
File "/home/joseph/.local/lib/python3.5/site-packages/tensorflow/python/keras/layers/wrappers.py", line 213, in build
self.layer.build(tuple(child_input_shape))
File "/home/joseph/.local/lib/python3.5/site-packages/tensorflow/python/keras/layers/core.py", line 933, in build
raise ValueError('The last dimension of the inputs to `Dense` '
ValueError: The last dimension of the inputs to `Dense` should be defined. Found `None`.
任何帮助或提示,我将不胜感激!预先谢谢你。