【问题标题】:Issues running my Tensorflow model on GPU在 GPU 上运行我的 Tensorflow 模型的问题
【发布时间】:2018-10-13 14:00:23
【问题描述】:

我是 TensorFlow 的新手。我有一个在 CPU 上运行的 Tensorflow 代码,但我正在尝试将其更改为在 GPU 上运行。我在某处添加了tf.device('/device:GPU:0') 语句,但显然它不起作用,而且我没有看到日志。

怎么改?

#...some stuff
g_in = tf.Graph()
with gfile.FastGFile(path + name + '.pb', 'rb') as f:
    graph_def = tf.GraphDef()
    graph_def.ParseFromString(f.read())
    tf.import_graph_def(graph_def, name="")
    g_in = tf.get_default_graph()
    print(g_in)

with g_in.as_default(), tf.device('/device:GPU:0'):
    sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
    input = sess.graph.get_tensor_by_name("cnn/input_1:0")
    output = sess.graph.get_tensor_by_name("mymodel:0")

【问题讨论】:

    标签: python-3.x tensorflow machine-learning


    【解决方案1】:

    如果您安装了tensorflow-gpu,Tensorflow 将默认在 GPU 上运行。
    with tf.device('/device:GPU:0') 用于在您不想在默认情况下运行它时选择要使用的 GPU。 pip freeze 应该告诉你你有哪个安装。如果它只显示tensorflow 而不是tensorflow-gpu,那么你需要卸载它,安装CUDA 并重新安装tensorflow-gpu

    【讨论】:

      猜你喜欢
      • 2018-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-11
      • 1970-01-01
      • 2017-12-03
      • 2018-11-08
      相关资源
      最近更新 更多