gitlab run成功 但无法访问_机器学习100天-Day2104 Tensorboard无法访问问题

43abcbd3ac0587ad435d7e0cbf99371a.png

按照教程中的要求,是有一个tensorboard对训练结果进行可视化的,但是一直无法成功显示。

无法访问Tensorboard问题

我们将记录保存在项目根目录下的tf.logs文件夹中

root_logdir = r"./tf_logs"

以教程示例代码为例。

import numpy as npfrom sklearn.datasets import fetch_california_housingimport tensorflow as tffrom sklearn.preprocessing import StandardScalerhousing = fetch_california_housing()m, n = housing.data.shapeprint("数据集:{}行,{}列".format(m,n))housing_data_plus_bias = np.c_[np.ones((m, 1)), housing.data]scaler = StandardScaler()scaled_housing_data = scaler.fit_transform(housing.data)scaled_housing_data_plus_bias = np.c_[np.ones((m, 1)), scaled_housing_data]from datetime import datetimenow = datetime.utcnow().strftime("%Y%m%d%H%M%S")root_logdir = r"./tf_logs"logdir = "{}/run-{}/".format(root_logdir, now)n_epochs = 1000learning_rate = 0.01X = tf.placeholder(tf.float32, shape=(None, n + 1), name="X")y = tf.placeholder(tf.float32, shape=(None, 1), name="y")theta = tf.Variable(tf.random_uniform([n + 1, 1], -1.0, 1.0, seed=42), name="theta")y_pred = tf.matmul(X, theta, name="predictions")error = y_pred - ymse = tf.reduce_mean(tf.square(error), name="mse")optimizer = tf.train.GradientDescentOptimizer(learning_rate=learning_rate)training_op = optimizer.minimize(mse)init = tf.global_variables_initializer()mse_summary = tf.summary.scalar('MSE', mse)file_writer = tf.summary.FileWriter(logdir, tf.get_default_graph())n_epochs = 10batch_size = 100n_batches = int(np.ceil(m / batch_size))def fetch_batch(epoch, batch_index, batch_size): np.random.seed(epoch * n_batches + batch_index) # not shown in the book indices = np.random.randint(m, size=batch_size) # not shown X_batch = scaled_housing_data_plus_bias[indices] # not shown y_batch = housing.target.reshape(-1, 1)[indices] # not shown return X_batch, y_batchwith tf.Session() as sess: # not shown in the book sess.run(init) # not shown for epoch in range(n_epochs): # not shown for batch_index in range(n_batches): X_batch, y_batch = fetch_batch(epoch, batch_index, batch_size) if batch_index % 10 == 0: summary_str = mse_summary.eval(feed_dict={X: X_batch, y: y_batch}) step = epoch * n_batches + batch_index file_writer.add_summary(summary_str, step) sess.run(training_op, feed_dict={X: X_batch, y: y_batch}) best_theta = theta.eval()file_writer.close()print(best_theta)

在运行完毕后,可以看到项目文件夹中出现tf.logs文件夹。

972c8c41320cd1978e5b688a76cb18eb.png

按照教程

  • 打开pycharm 的terminal,转入项目文件夹,输入
tensorboard --logdir=/Users/01/Desktop/机器学习作业/sklearn+tensorflow/tf_logs/run-20190124025648

也就是你生成的那个文件夹名称

  • 回车后启动tensorboard。
1bb70685d6846a4384ed2c270aae3584.png
  • 将http:……输入浏览器,就应该是可以了,然而……
66eb9057f2ce2d334eaee0cdd9f4ade1.png

问题出在哪里,本来以为是端口问题,我试着换成8080端口依旧不行,搁置两天要放弃后,突然想起来tensorboard就是一个服务器显示页面,localhost是否可以?启动后输入万年localhost:8080,搞定。

717ac5b41781dd87e7fb89044f30890d.png
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值