【问题标题】:Can a model trained using a GPU be used for inference on a CPU?可以使用 GPU 训练的模型在 CPU 上进行推理吗?
【发布时间】:2020-07-10 23:33:51
【问题描述】:

我想在 CPU 上运行推理;虽然我的机器有 GPU。 我想知道是否可以强制TensorFlow使用CPU而不是GPU?

默认情况下,TensorFlow会自动使用GPU进行推理,但是由于我的GPU不好(OOM'ed),不知道有没有设置强制Tensorflow使用CPU进行推理?

为了推断,我使用了:

tf.contrib.predictor.from_saved_model("PATH")

【问题讨论】:

    标签: tensorflow tensorflow-serving


    【解决方案1】:

    假设您使用的是 TensorFlow 2.0,请在 GitHub 上查看此问题:

    解决方案似乎是对 TensorFlow 隐藏 GPU 设备。您可以使用以下描述的方法之一来做到这一点:

    TensorFlow 2.0:

    my_devices = tf.config.experimental.list_physical_devices(device_type='CPU')
    tf.config.experimental.set_visible_devices(devices= my_devices, device_type='CPU')
    

    TensorFlow 2.1:

    tf.config.set_visible_devices([], 'GPU')
    

    (感谢 @ymodak 和 @henrysky,他们在 GitHub 问题上回答了问题。)

    【讨论】:

    • 实际上我只想在图表的一部分而不是全局范围内这样做?想知道有没有办法。
    • 啊,我明白了。我就是这种情况,最好将其作为另一个问题发布在 StackOverflow 上,因为我相信,我已经回答了您最初在这里提出的问题。
    猜你喜欢
    • 1970-01-01
    • 2019-08-11
    • 1970-01-01
    • 2018-11-29
    • 1970-01-01
    • 2022-06-14
    • 1970-01-01
    • 2020-02-09
    • 1970-01-01
    相关资源
    最近更新 更多