在centos系统(虚拟机)上用tensorflow框架模拟分布式训练显示不出结果,是操作问题还是代码问题?

银月亮 发布于 2018/10/13 19:52
阅读 47
收藏 0

本人小白,希望得到大家指导!!

我在centos7(有界面)上用python2.7,最新版的tensorflow框架,用的是自带的python IDLE编辑器。

我写了三个.py文件,分别是work1.py ,work2.py,client.py。模仿的是https://blog.csdn.net/u010159842/article/details/58605865   这个人的csdn博客。我的操作是:1、输入命令 idle(进入python IDLE编辑器)2、点击 file 、open... 依次通过这个操作打开三个.py文件。3、依次点击 run module 来运行 work1.py,work2.py,client.py。在命令行显示started server with target 。。。。2222 ,started server with target 。。。。2223 ,但是运行了client.py之后却什么都没有输出,没有像博客说的那样输出两个结果,是我的操作出问题了?还是代码问题?并没有报错啊?这里是 client.py的代码

import tensorflow as tf
import numpy as np

train_x = np.linspace(-1,1,101)
train_y = 2*train_x + np.random.randn(*train_x.shape)*0.33+10

x = tf.placeholder("float")
y = tf.placeholder("float")
w = tf.Variable(0.0,name="weight")
b = tf.Variable(0.0,name="reminder")

init_op = tf.global_variables_initializer()
cost_op = tf.square(y-tf.multiply(x,w)-b)
train_op = tf.train.GradientDescentOptimizer(0.01).minimize(cost_op)

with tf.Session("grpc://localhost:2222") as sess:
    with tf.device("/job:worker/task:0"):
        sess.run(init_op)

        for i in range(10):
            for (a,b) in zip(train_x,train_y):
                sess.run(train_op,feed_dict={x:a,y:b})

        print(sess.run(w))
        print(sess.run(b))

这里是work1.py的代码

import tensorflow as tf

worker1 = "192.168.157.130:2222"

worker2 = "192.168.157.130:2223"

worker_hosts = [worker1, worker2]

cluster_spec = tf.train.ClusterSpec({ "worker": worker_hosts})

server = tf.train.Server(cluster_spec, job_name="worker", task_index=0)

server.join()

这里是work2.py的代码

import tensorflow as tf

worker1 = "192.168.157.130:2222"

worker2 = "192.168.157.130:2223"

worker_hosts = [worker1, worker2]

cluster_spec = tf.train.ClusterSpec({ "worker": worker_hosts})

server = tf.train.Server(cluster_spec, job_name="worker", task_index=1)

server.join()

-------------------------是这个博客用的代码太旧了吗?一些被丢弃的函数我已经改了呀

希望得到大神的指点,指出问题所在,谢谢大家!!!

加载中
返回顶部
顶部