【发布时间】:2019-03-19 06:56:33
【问题描述】:
我正在尝试使用 tensorflow lite toco 转换器来获取 tflite 图。 我使用 toco 命令行来获取 tflite 图。在转换过程中我没有收到任何错误,但是,我的转换似乎包含垃圾(输出为 nans)。我正在寻求有关如何调试此转换的想法。
我执行以下步骤:
-
加载 .ckpt 文件并转换为frozen_graph:
与 g.as_default()、g.device(device_t)、\ tf.Session(config=soft_config) 作为 sess: batch_shape = (batch_size,) + img_shape img_placeholder = tf.placeholder(tf.float32, shape=batch_shape, name='img_placeholder')
preds = transform(img_placeholder) saver = tf.train.Saver() saver.restore(sess, checkpoint_dir) frozen_graph_def = tf.graph_util.convert_variables_to_constants(sess,sess.graph_def,['transformer/up-sample/mul']) with open('frozeen_graph.pb', 'wb') as f: f.write(frozen_graph_def.SerializeToString())
问题:上面的代码是否等同于脚本tensorflow/python/tools/freeze_graph.py的使用?
当我使用上面的代码时,我还通过加载冻结图并通过它传递输入图像来检查冻结,并且输出看起来不错。所以看起来冻结是有效的。
- 使用 toco convert 命令行(在 tensorflow 版本 1.10 和 tensorflow nightly-gpu 中尝试过)
toco \ --graph_def_file=frozeen_graph.pb \
--output_file=converted_graph.lite \ --input_format=TENSORFLOW_GRAPHDEF \ --output_format=TFLITE \ --input_shape=1,256,256,3 \ --input_array=img_placeholder:0 \ --output_array=transformer/up-sample/mul:0 \ --inference_type=FLOAT \ --input_data_type=FLOAT
执行上述行时,我没有收到任何错误。请注意,我更改了图表以消除一些“不支持的操作”错误。
-
接下来,我使用 tensorflow lite 解释器来测试转换后的图形(使用 python API):
tflite_graph_filename = 'converted_graph.lite' # Load TFLite model and allocate tensors. interpreter = tf.contrib.lite.Interpreter(model_path=tflite_graph_filename) interpreter.allocate_tensors() # Get input and output tensors. input_details = interpreter.get_input_details() output_details = interpreter.get_output_details() input_shape = input_details[0]['shape'] X = np.zeros(input_shape,np.float32) X[0] = content_image input_data = X interpreter.set_tensor(input_details[0]['index'], input_data) interpreter.invoke() output_data = interpreter.get_tensor(output_details[0]['index'])不幸的是,output_data 都是 nanes ,
有人可以给我一些调试建议或进行这种转换的正确方法吗?
谢谢你, 瓦迪姆
【问题讨论】:
标签: tensorflow-lite