我试图使用tensorboard查看我的线性回归代码图,但它给出了许多我找不到解决方法的错误。另外,我还在使用Intel M5 CPU和Intel HD 5300 GPU的MacBook上运行代码。
程序运行正常,因此我重新检查了在创建和存储图形的部分中任何错字的代码。我什至重新安装了tensorflow(1.12.2),但弹出了相同的错误。另外,我在运行代码后就可以看到正在创建目录(在其中图形存储为“ logdir”)。
import tensorflow as tf
W = tf.Variable([.3], tf.float32)
b = tf.Variable([-.3], tf.float32)
x = tf.placeholder(tf.float32)
y = tf.placeholder(tf.float32)
lm = x * W + b
squared_delta = tf.square(lm - y)
cost = tf.reduce_sum(squared_delta)
optimize = tf.train.GradientDescentOptimizer(0.01)
train = optimize.minimize(cost)
init = tf.global_variables_initializer()
with tf.Session() as sess:
sess.run(init)
fw = tf.summary.FileWriter('./event_logs', sess.graph)
for i in range(100):
sess.run(train, {x: [1, 2, 3, 4], y: [0, -1, -2, -3]})
#print(' cost : ', sess.run(cost, {x: [1, 2, 3, 4], y: [0, -1, -2, -3]}))
print("Variables W and b: {} & {}".format(sess.run(W)[0], sess.run(b)[0]))
test_data = 3
print("Value for {} is {}".format(test_data, round((test_data * sess.run(W) + sess.run(b))[0])))
我希望看到一个简单的图形,但是...
Sarthaks-MacBook:PycharmProjects Xcalibre$ tensorboard --logdir="machine_learning/"
Traceback (most recent call last):
File "/Users/Xcalibre/anaconda3/bin/tensorboard", line 7, in <module>
from tensorboard.main import run_main
File "/Users/Xcalibre/anaconda3/lib/python3.7/site-packages/tensorboard/main.py", line 45, in <module>
from tensorboard import default
File "/Users/Xcalibre/anaconda3/lib/python3.7/site-packages/tensorboard/default.py", line 34, in <module>
import tensorflow as tf
File "/Users/Xcalibre/anaconda3/lib/python3.7/site-packages/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "/Users/Xcalibre/anaconda3/lib/python3.7/site-packages/tensorflow/python/__init__.py", line 47, in <module>
import numpy as np
File "/Users/Xcalibre/anaconda3/lib/python3.7/site-packages/numpy/__init__.py", line 142, in <module>
from . import core
File "/Users/Xcalibre/anaconda3/lib/python3.7/site-packages/numpy/core/__init__.py", line 59, in <module>
from . import numeric
File "/Users/Xcalibre/anaconda3/lib/python3.7/site-packages/numpy/core/numeric.py", line 3093, in <module>
from . import fromnumeric
File "/Users/Xcalibre/anaconda3/lib/python3.7/site-packages/numpy/core/fromnumeric.py", line 17, in <module>
from . import _methods
File "/Users/Xcalibre/anaconda3/lib/python3.7/site-packages/numpy/core/_methods.py", line 158, in <module>
_NDARRAY_ARRAY_FUNCTION = mu.ndarray.__array_function__
AttributeError: type object 'numpy.ndarray' has no attribute '__array_function__'
答案 0 :(得分:0)
运行:
tensorboard --logdir="event_logs/"
那是您存储张量板应该加载的文件的地方。看看代码中的这一行:
fw = tf.summary.FileWriter('./event_logs', sess.graph)
我想您的项目目录名为machine_learning
,这就是您尝试运行的原因:
tensorboard --logdir="machine_learning/"
但这完全是错误的。