zhiqiang
V2EX  ›  问与答

tensorflow predict 的 C++接口比 Python 速度还慢?

  •  
  •   zhiqiang · Jan 8, 2019 · 4310 views
    This topic created in 2680 days ago, the information mentioned may be changed or developed.

    tensorflow 提供了 C++和 Python 接口,测试了两个接口的速度,结果发现 C++比 Python 还慢。

    为什么呢,有人来说说不?

    我们只测试了 predict。模型是事先训练好的。在计算运行时间时,只统计两边调用 predict 函数的时间。

    6 replies    2019-01-09 09:38:58 +08:00
    luxinxin
        1
    luxinxin  
       Jan 8, 2019 via iPhone
    冷启动时间是否排除掉了,以及 cpp 和 python 接口是否用的是同样的 batch size
    zhiqiang
        2
    zhiqiang  
    OP
       Jan 8, 2019
    @luxinxin 你之前有类似的测试吗?

    我只统计了 tensorflow 的 predict 函数调用时间,tensorflow 启动和数据准备时间都被排除了。除非在 predict 函数内部的启动,这个也无法排除。

    batch size 一样。模型也一样。数据也一样。
    luxinxin
        3
    luxinxin  
       Jan 8, 2019 via iPhone
    我没做过类似的对比,要不你再试试先 predict 一千个样本,这样能把 predict 内部的启动因素也排除掉,然后再开始计时。
    zhiqiang
        4
    zhiqiang  
    OP
       Jan 8, 2019
    @luxinxin 我做了十万次然后对比的时间。。。
    glasslion
        5
    glasslion  
       Jan 8, 2019
    慢了多少? C++ 的 tensorflow 和 Python 的 tensorflow 是否完全一致(mkl 等)?
    zhiqiang
        6
    zhiqiang  
    OP
       Jan 9, 2019
    @glasslion 不多,一半到一倍吧。

    编译一致性这个我不清楚,怎么查?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1002 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 48ms · UTC 22:17 · PVG 06:17 · LAX 15:17 · JFK 18:17
    ♥ Do have faith in what you're doing.