首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >关于机器学习的问题,跟着敲了一段代码,报错了,求告诉为什么这样?

关于机器学习的问题,跟着敲了一段代码,报错了,求告诉为什么这样?

提问于 2020-07-10 17:06:56
回答 0关注 0查看 704

代码,我怕是我代码敲错了,从视频课程的git那 拉下来的代码 仍然报错,如下


代码语言:javascript
复制
from __future__ import print_function
import theano
import theano.tensor as T
import numpy as np
import matplotlib.pyplot as plt


class Layer(object):
    def __init__(self, inputs, in_size, out_size, activation_function=None):
        self.W = theano.shared(np.random.normal(0, 1, (in_size, out_size)))
        self.b = theano.shared(np.zeros((out_size,)) + 0.1)
        self.Wx_plus_b = T.dot(inputs, self.W) + self.b
        self.activation_function = activation_function
        if activation_function is None:
            self.outputs = self.Wx_plus_b
        else:
            self.outputs = self.activation_function(self.Wx_plus_b)


# Make up some fake data
x_data = np.linspace(-1, 1, 300)[:, np.newaxis]
noise = np.random.normal(0, 0.05, x_data.shape)
y_data = np.square(x_data) - 0.5 + noise  # y = x^2 - 0.5

# show the fake data
# plt.scatter(x_data, y_data)
plt.show()

# determine the inputs dtype
x = T.dmatrix("x")
y = T.dmatrix("y")

# add layers
l1 = Layer(x, 1, 10, T.nnet.relu)
l2 = Layer(l1.outputs, 10, 1, None)

# compute the cost
cost = T.mean(T.square(l2.outputs - y))

# compute the gradients
gW1, gb1, gW2, gb2 = T.grad(cost, [l1.W, l1.b, l2.W, l2.b])

# apply gradient descent
learning_rate = 0.05
train = theano.function(
    inputs=[x, y],
    outputs=[cost],
    updates=[(l1.W, l1.W - learning_rate * gW1),
             (l1.b, l1.b - learning_rate * gb1),
             (l2.W, l2.W - learning_rate * gW2),
             (l2.b, l2.b - learning_rate * gb2)])

# prediction
predict = theano.function(inputs=[x], outputs=l2.outputs)

# plot the real data
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax.scatter(x_data, y_data)
plt.ion()
plt.show()

for i in range(1000):
    # training
    err = train(x_data, y_data)
    if i % 50 == 0:
        # to visualize the result and improvement
        try:
            ax.lines.remove(lines[0])
        except Exception:
            pass
        prediction_value = predict(x_data)
        # plot the prediction
        lines = ax.plot(x_data, prediction_value, 'r-', lw=5)
        plt.pause(.5)

下面是错误

F:\pytest\venv\Scripts\python.exe F:/pytest/newfiles.py

You can find the C code in this temporary file: C:\Users\gjc\AppData\Local\Temp\theano_compilation_error_86cutf1g

library mkl_rt is not found.

Traceback (most recent call last):

File "F:/pytest/newfiles.py", line 51, in <module>

(l2.b, l2.b - learning_rate * gb2)])

File "F:\pytest\venv\lib\site-packages\theano\compile\function.py", line 317, in function

output_keys=output_keys)

File "F:\pytest\venv\lib\site-packages\theano\compile\pfunc.py", line 486, in pfunc

output_keys=output_keys)

File "F:\pytest\venv\lib\site-packages\theano\compile\function_module.py", line 1841, in orig_function

fn = m.create(defaults)

File "F:\pytest\venv\lib\site-packages\theano\compile\function_module.py", line 1715, in create

input_storage=input_storage_lists, storage_map=storage_map)

File "F:\pytest\venv\lib\site-packages\theano\gof\link.py", line 699, in make_thunk

storage_map=storage_map)[:3]

File "F:\pytest\venv\lib\site-packages\theano\gof\vm.py", line 1091, in make_all

impl=impl))

File "F:\pytest\venv\lib\site-packages\theano\gof\op.py", line 955, in make_thunk

no_recycling)

File "F:\pytest\venv\lib\site-packages\theano\gof\op.py", line 858, in make_c_thunk

output_storage=node_output_storage)

File "F:\pytest\venv\lib\site-packages\theano\gof\cc.py", line 1217, in make_thunk

keep_lock=keep_lock)

File "F:\pytest\venv\lib\site-packages\theano\gof\cc.py", line 1157, in __compile__

keep_lock=keep_lock)

File "F:\pytest\venv\lib\site-packages\theano\gof\cc.py", line 1624, in cthunk_factory

key=key, lnk=self, keep_lock=keep_lock)

File "F:\pytest\venv\lib\site-packages\theano\gof\cmodule.py", line 1189, in module_from_key

module = lnk.compile_cmodule(location)

File "F:\pytest\venv\lib\site-packages\theano\gof\cc.py", line 1527, in compile_cmodule

preargs=preargs)

File "F:\pytest\venv\lib\site-packages\theano\gof\cmodule.py", line 2396, in compile_st

(status, compile_stderr.replace('\n', '. ')))

Exception: ('The following error happened while compiling the node', Dot22(x, <TensorType(float64, matrix)>), '\n', 'Compilation failed (return status=1): F:/MyDrivers/x86_64-8.1.0-release-posix-seh-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lmkl_rt\r. collect2.exe: error: ld returned 1 exit status. ', '[Dot22(x, <TensorType(float64, matrix)>)]')

Process finished with exit code 1

求大神解答 ,萌新很懵= = gcc环境也有

回答

和开发者交流更多问题细节吧,去 写回答
相关文章

相似问题

相关问答用户
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档