tensorflow-lite - 当我运行 tflite 文件时,它只显示“中止(核心转储)”
问题描述
当我使用 tf 版本 1.13.1 将 pb 转换为 tflite 时,它显示dim not match错误,但是当我使用 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 文件
有人可以帮我吗?
解决方案
推荐阅读
- python - pymysql - TypeError:字符串格式化期间并非所有参数都转换
- python-3.x - 有没有办法通过在该行的值中提供特定列来访问数据框的任何行?
- julia - 数组中存在的过滤器元素
- react-native - React Native , Redux - TypeError: (0 , _redux.createStore) 不是函数
- python - 不同线程中的输入,不会相互中断
- android - 重新安装后房间数据库抛出错误 - 房间无法验证数据完整性
- hybris - 在 Hybris Cloud 1905 中登录后 Smartedit 给出空白页面
- sas - 在 SAS 元数据中查找最近修改的作业:如何使 metadata_getnobj("Job?@MetadataUpdated > '01May2020:00:00:00'dt") 工作?
- dask - 使用 dask 搜索诊断文件系统性能的片段
- python-3.x - 在 matplotlib 中绘制数据框数据