【问题标题】:Running Tensorflow model inference script on multiple GPU在多个 GPU 上运行 TensorFlow 模型推理脚本
【发布时间】:2020-02-11 10:51:55
【问题描述】:

我正在尝试从 tensorflow 对象检测 API 运行模型评分(推理图)以在多个 GPU 上运行它,尝试在主 GPU 中指定 GPU 编号,但它仅在单个 GPU 上运行。placed GPU utilization snapshot here

使用 tensorflow-gpu==1.13.1,您能否指出我在这里缺少的内容。

for i in range(2):
        with tf.device('/gpu:{}' . format(i)):
            tf_init()
            init = tf.global_variables_initializer
           with detection_graph.as_default():
              with tf.Session(config=tf.ConfigProto(log_device_placement=True)) as session:
                   call to #run_inference_multiple_images function

【问题讨论】:

    标签: tensorflow scoring multi-gpu


    【解决方案1】:

    this question 的回复应该会为您提供一些解决此问题的选项。

    除非另有说明,否则 TensorFlow 通常会占用所有可见的 GPU。因此,如果您还没有尝试过,您可以删除 with tf.device 行(假设您只有两个 GPU),TensorFlow 应该同时使用它们。

    否则,我认为最简单的方法是使用os.environ["CUDA_VISIBLE_DEVICES"] = "0,1" 设置环境变量。

    【讨论】:

    • 感谢您的回复,我尝试了指定的方法,但它仍然只在一个 GPU 上运行,还尝试在启动会话时添加以下配置 tf.ConfigProto(gpu_options.allow_growth = True) tf.ConfigProto(device_count = {'GPU': 2}) 在模型训练期间,当 num_clones 设置到 4,它已经利用了系统中的所有 GPU,不知道我在这里缺少什么。是不是跟 tensorflow-gpu 版本有关?
    • TF 分配所有 GPU,但可能不会全部使用。也许它已经决定不需要第二个进行推理?您可以尝试运行更大的模型。此外,使用with tf.device 选项需要您手动指定要运行张量的位置......将自动为您未指定的张量选择设备。也许this question 会有所帮助。
    猜你喜欢
    • 2019-09-18
    • 2018-04-02
    • 2019-06-12
    • 1970-01-01
    • 2018-05-27
    • 2019-10-12
    • 2020-10-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多