1

我从这里下载了一个量化的移动网络,该图包含训练期间的假量化节点,以模拟测试时间输出。我想从这个网络的最后一个逐点卷积层收集输出。

量化的冻结模型包含额外的 fc、softmax 等层,这些层对我的应用程序没有用处。

我有以下用于加载图表的代码。

def load_graph(frozen_graph_filename):
    # We load the protobuf file from the disk and parse it to retrieve the
    # unserialized graph_def
    with tf.gfile.GFile(frozen_graph_filename, "rb") as f:
        graph_def = tf.GraphDef()
        graph_def.ParseFromString(f.read())

with tf.Graph().as_default() as graph:
    # The name var will prefix every op/nodes in your graph
    # Since we load everything in a new graph, this is not needed
    tf.import_graph_def(graph_def, name="prefix")
return graph

graph1 = load_graph("./quantized_fake.pb")

input = graph1.get_tensor_by_name('prefix/input:0')
output = graph1.get_tensor_by_name('prefix/MobilenetV1/MobilenetV1/Conv2d_13_pointwise/Conv2D_Fold:0')

然后使用 sess.run() 运行,但是我观察到卷积层的输出没有像在移动设备上运行时那样量化(8 位)。

在我的电脑上运行代码时,如何产生与在移动设备上产生的输出相同的输出。

tflite 文件可以用于 pc 上的推理吗?

4

1 回答 1

2

TensorFlow 假量化图实际上并未量化,它插入了模拟量化的FakeQuantization 操作。这些仅由 TensorFlow Lite 转换为完全量化的操作。这就是为什么运行 TensorFlow 假量化图只会产生浮点值而不是量化值的原因。

TensorFlow Lite 量化目前只有 CPU,可以在 PC 的 CPU 上运行。这是一个示例,说明如何调用 TFLite 解释器在您的 PC 上运行。

于 2018-05-01T23:00:14.190 回答