gpt4 book ai didi

python-3.x - 如何修复当我尝试在终端上运行构建图时弹出的张量板错误

转载 作者:行者123 更新时间:2023-11-30 09:16:38 25 4
gpt4 key购买 nike

我试图使用张量板查看我的线性回归代码图,但它给出了许多我找不到解决方法的错误。此外,我还在配备 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__'

最佳答案

运行:

tensorboard --logdir="event_logs/"

这是您存储张量板应加载的文件的位置。看一下代码中的这一行:

fw = tf.summary.FileWriter('./event_logs', sess.graph)

我猜您的项目目录名为 machine_learning,这就是您尝试运行的原因:

tensorboard --logdir="machine_learning/"

但这完全是错误的。

关于python-3.x - 如何修复当我尝试在终端上运行构建图时弹出的张量板错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54452322/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com