当我使用tf版本1.13.1将pb转换为tflite时,它显示 dim不匹配 错误,但是当我使用1.14转换时,它成功保存了tflite文件。但是当我在文档中使用测试代码时,它只会显示 core dumped 。
以下是输出:
用1.13.1转换
ture_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2019-09-23 14:33:07.069746: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 3696000000 Hz
2019-09-23 14:33:07.072588: I tensorflow/compiler/xla/service/service.cc:150] XLA service 0x564ecd24a790 executing computations on platform Host. Devices:
2019-09-23 14:33:07.072658: I tensorflow/compiler/xla/service/service.cc:158] StreamExecutor device (0): <undefined>, <undefined>
Ignore 'tcmalloc: large alloc' warnings.
Traceback (most recent call last):
File "pb-to-tflite.py", line 9, in <module>
tflite_model = converter.convert()
File "/home/dm/anaconda3/envs/s-t3/lib/python3.6/site-
packages/tensorflow/lite/python/lite.py", line 455, in convert
**converter_kwargs)
File "/home/dm/anaconda3/envs/s-t3/lib/python3.6/site-
packages/tensorflow/lite/python/convert.py", line 442, in toco_convert_impl
input_data.SerializeToString())
File "/home/dm/anaconda3/envs/s-t3/lib/python3.6/site-packages/tensorflow/lite/python/convert.py", line 205, in toco_convert_protos
"TOCO failed. See console for info.\n%s\n%s\n" % (stdout, stderr))
tensorflow.lite.python.convert.ConverterError: TOCO failed. See console for info.
2019-09-23 14:33:21.269591: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] Before Removing unused ops: 529 operators, 854 arrays (0 quantized)
2019-09-23 14:33:21.275653: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After Removing unused ops pass 1: 527 operators, 849 arrays (0 quantized)
2019-09-23 14:33:21.283483: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] Before general graph transformations: 527 operators, 849 arrays (0 quantized)
2019-09-23 14:33:21.330461: F tensorflow/lite/toco/graph_transformations/propagate_fixed_sizes.cc:117] Check failed: dim_x == dim_y (512 vs. 10)Dimensions must match
Aborted (core dumped)
换算成1.14
2019-09-23 14:38:45.285133: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:716] Optimization results for grappler item: graph_to_optimize
2019-09-23 14:38:45.285519: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:718] constant folding: Graph size after: 440 nodes (-112), 631 edges (-112), time = 213.324ms.
2019-09-23 14:38:45.285580: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:718] constant folding: Graph size after: 440 nodes (0), 631 edges (0), time = 54.184ms.
以及当我使用下面的代码进行测试
import tensorflow as tf
import numpy as np
# Load TFLite model and allocate tensors.
interpreter = tf.lite.Interpreter(model_path="converted_model.tflite")
interpreter.allocate_tensors()
# Get input and output tensors.
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()
print(input_details)
print(output_details)
# Test model on random input data.
input_shape = input_details[0]['shape']
input_data = np.array(np.random.random_sample(input_shape), dtype=np.float32)
print(input_data.shape)
interpreter.set_tensor(input_details[0]['index'], input_data)
interpreter.invoke()
# The function `get_tensor()` returns a copy of the tensor data.
# Use `tensor()` in order to get a pointer to the tensor.
output_data = interpreter.get_tensor(output_details[0]['index'])
print(output_data)
它只是显示
[{'name': 'input', 'index': 95, 'shape': array([ 1, 257, 400, 1], dtype=int32), 'dtype': <class 'numpy.float32'>, 'quantization': (0.0, 0)}]
[{'name': 'lambda_1/l2_normalize', 'index': 96, 'shape': array([ 1, 512], dtype=int32), 'dtype': <class 'numpy.float32'>, 'quantization': (0.0, 0)}]
(1, 257, 400, 1)
Aborted (core dumped)
,我可以使用netron打开生成的tflite文件 the network structure it shows
有人可以给我些帮助吗?