Редактирование протобора тензорного потока в узле GraphDef - PullRequest
0 голосов
/ 28 февраля 2020

При преобразовании graphdef (.pb) в tenorflow-lite (.tflite) я столкнулся с проблемой типа данных:

RuntimeError: Inputs and outputs not all float|uint8|int16 types.Node number 2 (ADD) failed to invoke.

Решение, по-видимому, состоит в том, чтобы отредактировать узел, который является не плавать | uint8 | int16. После выделения этого узла, который выглядит следующим образом:

{'name': 'add_10', 'index': 7205, 'shape': array([2], dtype=int32), 'dtype': <class 'numpy.int64'>, 'quantization': (0.0, 0)}

, я сталкиваюсь с той же проблемой:

RuntimeError: Inputs and outputs not all float|uint8|int16 types.Node number 2 (ADD) failed to invoke.

И снова проверяю график:

{'name': 'add_10', 'index': 7205, 'shape': array([2], dtype=int32), 'dtype': <class 'numpy.int64'>, 'quantization': (0.0, 0)}

Это говорит о том, что тип данных узла не изменяется. Вот мой код редактирования:

import tensorflow as tf
from tensorflow.python.tools import freeze_graph
from tensorflow.python.tools import optimize_for_inference_lib

inputGraph = tf.GraphDef()
with tf.gfile.Open("out.pb", "rb") as f:
    data2read = f.read()
    inputGraph.ParseFromString(data2read)

graph = tf.Graph()

with graph.as_default():
    tf.import_graph_def(inputGraph)

x = tf.contrib.graph_editor.get_tensors(graph)

for t in x:
    if t.name == 'import/add_10:0':
        print(t)
        tf.cast(t, tf.int32)

outputGraph = optimize_for_inference_lib.optimize_for_inference(
                graph.as_graph_def(),
                input_node_names=["import/image"],
                output_node_names=["action"],
                placeholder_type_enum=tf.float32.as_datatype_enum)

f = tf.gfile.FastGFile("out_opt_edited.pb", "w")
f.write(outputGraph.SerializeToString())      

Любая помощь / предложения приветствуются! Спасибо:)

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...