我是TensorFlow的新手。我正在尝试使用tensorflow版本1.12 python3在ubuntu 16.04 LTS计算机上执行一个简单的代码。在Jupyter笔记本上运行以下代码。还尝试在终端上运行相同的代码,只是遇到相同的问题。
import numpy as np
import tensorflow as tf
cluster = tf.train.ClusterSpec({"local": ["localhost:2222", "localhost:2223"]})
x = tf.placeholder(tf.float32, 100)
with tf.device("/job:local/task:1"):
first_batch = tf.slice(x, [0], [50])
mean1 = tf.reduce_mean(first_batch)
with tf.device("/job:local/task:0"):
second_batch = tf.slice(x, [50], [-1])
mean2 = tf.reduce_mean(second_batch)
mean = (mean1 + mean2) / 2
with tf.Session("grpc://localhost:2222") as sess:
result = sess.run(mean, feed_dict={x: np.random.random(100)})
print(result)
当控件到达sess.run时,我的单元格挂起,我需要重新启动笔记本电脑。我在做什么错了?