weixin_42605365
Anele.L
采纳率18.2%
2019-09-29 16:26

theano 运行报错 安装了MingGW依然不行

20

想用theano运行regularization
安装了MingGW c++complier依然报错

from sklearn.datasets import load_boston 
import theano.tensor as T 
import numpy as np 
import matplotlib.pyplot as plt 
import theano

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)

def minmax_normalization(data):
    xs_max = np.max(data, axis=0)
    xs_min = np.min(data, axis=0)
    xs = (1-0)*(data - xs_min)/(xs_max - xs_min) + 0
    return xs

np.random.seed(100)
x_dataset = load_boston()
x_data = x_dataset.data
# minmax normalization, rescale the inputs
x_data = minmax_normalization(x_data)
y_data = x_dataset.target[:,np.newaxis]

#cross validation, train test data split
x_train, y_train = x_data[:400], y_data[:400]
x_test, y_test = x_data[400:], y_data[400:]

x = T.dmatrix('x')
y = T.dmatrix('y')

l1 = Layer(x, 13, 50, T.tanh)
l2 = Layer(l1.outputs, 50, 1, None)

#compute cost
cost = T.mean(T.square(l2.outputs - y))
#cost = T.mean(T.square(l2.outputs - y)) + 0.1*((l1.W**2).sum() + (l2.W**2).sum()) #l2 regulization
#cost = T.mean(T.square(l2.outputs - y)) + 0.1*(abs(l1.W).sum() + abs(l2.W).sum()) #l1 regulization
gW1, gb1, gW2, gb2 = T.grad(cost, [l1.W,l1.b,l2.W,l2.b]) #gradient descend

learning_rate = 0.01
train = theano.function(inputs=[x,y], 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)])

compute_cost = theano.function(inputs=[x,y], outputs=cost)

#record cost
train_err_list = []
test_err_list = []
learning_time = []
for i in range(1000):
    if 1%10 == 0:
        #record cost
        train_err_list.append(compute_cost(x_train,y_train))
        test_err_list.append(compute_cost(x_test,y_test))
        learning_time.append(i)

#plot cost history
plt.plot(learning_time, train_err_list, 'r-')
plt.plot(learning_time, test_err_list,'b--')
plt.show()

#作者:morvan 莫凡
https://morvanzhou.github.io

报错如下:
You can find the C code in this temporary file: C:\Users\Elena\AppData\Local\Temp\theano_compilation_error_cns9ecbh
Traceback (most recent call last):
File "c:\Users\Elena\PycharmProjects\theano\regularization.py", line 2, in
import theano.tensor as T
File "C:\Users\Elena\Anaconda3\lib\site-packages\theano__init__.py", line 110, in
from theano.compile import (
File "C:\Users\Elena\Anaconda3\lib\site-packages\theano\compile__init__.py", line 12, in
from theano.compile.mode import *
File "C:\Users\Elena\Anaconda3\lib\site-packages\theano\compile\mode.py", line 11, in
import theano.gof.vm
File "C:\Users\Elena\Anaconda3\lib\site-packages\theano\gof\vm.py", line 674, in
from . import lazylinker_c
File "C:\Users\Elena\Anaconda3\lib\site-packages\theano\gof\lazylinker_c.py", line 140, in
preargs=args)
File "C:\Users\Elena\Anaconda3\lib\site-packages\theano\gof\cmodule.py", line 2396, in compile_str
(status, compile_stderr.replace('\n', '. ')))
Exception: Compilation failed (return status=1): C:\Users\Elena\AppData\Local\Theano\compiledir_Windows-10-10.0.17134-SP0-Intel64_Family_6_Model_142_Stepping_9_GenuineIntel-3.6.5-64\lazylinker_ext\mod.cpp:1:0: sorry, unimplemented: 64-bit mode not compiled in
. #include

终端显示gcc有安装
图片说明

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • caozhy 回答这么多问题就耍赖把我的积分一笔勾销了 2年前

    版本不匹配,你安装的编译器是32bit的

    点赞 评论 复制链接分享

为你推荐