【发布时间】: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