5

我有一个模型,可以从图像中提取 512 个特征(-1,1 之间的数字)。我使用这里的说明将这个模型转换为 tflite 浮点格式 https://github.com/tensorflow/tensorflow/tree/master/tensorflow/contrib/lite

我使用原始模型和 tflite 模型对同一图像进行推理。

我得到了不同的向量结果,我期望得到非常相似的结果,因为我没有使用量化格式。据我了解,tf-lite 应该只提高推理性能时间而不影响特征计算。

我的问题这正常吗?其他人遇到过这个吗?我在任何地方都没有找到任何关于这个的话题。

用代码更新。

我有这个我训练过的网络(删除了许多项目,因为我无法共享完整的网络)placeholder = tf.placeholder(name='input', dtype=tf.float32,shape=[None, 128,128, 1])

with slim.arg_scope([slim.conv2d, slim.separable_conv2d],
                      activation_fn=tf.nn.relu, normalizer_fn=slim.batch_norm):
    net = tf.identity(placeholder)
    net = slim.conv2d(net, 32, [3, 3], scope='conv11')
    net = slim.separable_conv2d(net, 64, [3, 3], scope='conv12')
    net = slim.max_pool2d(net, [2, 2], scope='pool1')  # 64x64

    net = slim.separable_conv2d(net, 128, [3, 3], scope='conv21')
    net = slim.max_pool2d(net, [2, 2], scope='pool2')  # 32x32
    net = slim.separable_conv2d(net, 256, [3, 3], scope='conv31')

    net = slim.max_pool2d(net, [2, 2], scope='pool3')  # 16x16
    net = slim.separable_conv2d(net, 512, [3, 3], scope='conv41')
    net = slim.max_pool2d(net, [2, 2], scope='pool4')  # 8x8
    net = slim.separable_conv2d(net, 1024, [3, 3], scope='conv51')
    net = slim.avg_pool2d(net, [8, 8], scope='pool5')  # 1x1
    net = slim.dropout(net)
    net = slim.conv2d(net, feature_vector_size, [1, 1], activation_fn=None, normalizer_fn=None, scope='features')
    embeddings = tf.nn.l2_normalize(net, 3, 1e-10, name='embeddings') 

bazel-bin/tensorflow/contrib/lite/toco/toco --input_file=/tmp/network_512.pb --input_format=TENSORFLOW_GRAPHDEF --output_format=TFLITE --output_file=/tmp/tffiles/network_512.tflite --inference_type=FLOAT --input_type=FLOAT --input_arrays=input --output_arrays=embeddings --input_shapes=1,128,128,1

我在 python 中使用 tensorflow 运行 network_512.pb,使用https://github.com/tensorflow/tensorflow/tree/master/tensorflow/contrib/lite/java/demo 中的代码运行 network_512.tflite,我在其中修改了代码以加载我的联网并运行它。

4

1 回答 1

0

我发现的更新。我所做的测试是使用演示应用程序 tensorflow 提供并将其更改为使用我的服装模型并提取特征,我注意到特征值的差异。

一旦我在最新的 android 上手动编译了 tf-lite c++ lib,并使用我使用的相同流程(到目前为止是 TF-C API)运行流程,我得到了几乎相同的功能结果。

没有时间调查差异从何而来。但我现在很开心。

于 2018-04-02T14:42:43.750 回答