Python 为什么这一行会产生错误?
我对keras完全是新手,开始时,我试着遵循教程。我使用theano后端。 遗憾的是,我在这方面已经遇到了困难:Python 为什么这一行会产生错误?,python,machine-learning,theano,keras,mnist,Python,Machine Learning,Theano,Keras,Mnist,我对keras完全是新手,开始时,我试着遵循教程。我使用theano后端。 遗憾的是,我在这方面已经遇到了困难: model.add(Dense(num_pixels, input_dim=num_pixels, init='normal', activation='relu')) 它说: 用户警告:更新对Keras 2 API的Dense调用:Dense(784,input\u dim=784,activation=“relu”,kernel\u initializer=“normal”)
model.add(Dense(num_pixels, input_dim=num_pixels, init='normal', activation='relu'))
它说:
用户警告:更新对Keras 2 API的Dense调用:Dense(784,input\u dim=784,activation=“relu”,kernel\u initializer=“normal”)
“`调用Keras 2 API:'+签名)
信息(theano.gof.compilelock):刷新锁[…]
还会引发一个错误:
导入错误:DLL加载失败:动态链接库(DLL)
初始化例程失败
我做错了什么?每一个想法都非常受欢迎:D
以下是完整的错误回溯(部分为德语):
---------------------------------------------------------------------------
ImportError回溯(最近一次呼叫最后一次)
在()
---->1模型=基线_模型()
2.
3模型拟合(x_序列,y_序列,验证数据=(x_测试,y_测试),nb_历元=10,批量大小=200,详细度=2)
4.
5分=模型评估(x_检验、y_检验、详细度=0)
在基线_模型()中
2模型=顺序()?
3#输入层
---->4模型添加(密集(num_像素,input_dim=num_像素,init='normal',activation='relu'))
5#输出层
6模型添加(密集(num_类,init='normal',activation='softmax'))
C:\ProgramData\Anaconda3\lib\site packages\keras\models.py in add(self,layer)
420#并创建连接当前层的节点
421#到我们刚刚创建的输入层。
-->422层(x)
423
424如果len(层入站节点)!=1:
C:\ProgramData\Anaconda3\lib\site packages\keras\engine\topology.py in\uuuuuu调用(self,inputs,**kwargs)
526'`layer.build(批处理输入形状)`
527如果len(输入_形状)==1:
-->528自我构建(输入形状[0])
529其他:
530自我构建(输入形状)
C:\ProgramData\Anaconda3\lib\site packages\keras\layers\core.py内置(自,输入\u形状)
825 name='kernel',
826正则化器=self.kernel\u正则化器,
-->827约束=self.kernel\u约束)
828如果自我使用偏差:
829 self.bias=self.add_权重((self.units,),
C:\ProgramData\Anaconda3\lib\site packages\keras\engine\topology.py in add_weight(自身、形状、初始值设定项、名称、可训练、正则化器、约束)
362 """
363初始值设定项=初始值设定项.get(初始值设定项)
-->364 weight=K.variable(初始值设定项(shape),dtype=K.floatx(),name=name)
365如果正则化器不是无:
366自加损耗(正则化器(重量))
C:\ProgramData\Anaconda3\lib\site packages\keras\initializers.py in\uuuuuu call\uuuuuu(self、shape、dtype)
71定义调用(self、shape、dtype=None):
72返回K.random_normal(形状、自平均值、自标准差、,
--->73 dtype=dtype,seed=self.seed)
74
75 def get_配置(自):
C:\ProgramData\Anaconda3\lib\site packages\keras\backend\theano\u backend.py随机\正常(形状、平均值、标准差、数据类型、种子)
1935 seed=np.random.randint(110e6)
1936 rng=随机流(种子=种子)
->1937返回rng正常值(尺寸=形状,平均值=平均值,标准值=标准差,数据类型=数据类型)
1938
1939
C:\ProgramData\Anaconda3\lib\site packages\theano\sandbox\rng\u mrg.py正常(self、size、avg、std、ndim、dtype、nstream)
1572 n_样本=产品(尺寸)+(产品(尺寸)%2)
1573=自均匀(大小=(n_样本,),dtype=dtype,
->1574 N流=N流)
1575
1576如果为常数:
C:\ProgramData\Anaconda3\lib\site packages\theano\sandbox\rng\u mrg.py统一格式(self、size、low、high、ndim、dtype、nstream)
1352如果N流为无:
1353 n流=自身n_流(大小)
->1354 rstates=self.get_substream_rstates(n流,数据类型)
1355
1356如果self.use_cuda和dtype==“float32”:
C:\ProgramData\Anaconda3\lib\site packages\theano\configparser.py在res(*args,**kwargs)中
115 def res(*args,**kwargs):
116与自我:
-->117返回f(*args,**kwargs)
118返回res
119
C:\ProgramData\Anaconda3\lib\site packages\theano\sandbox\rng\u mrg.py在get\u substream\r状态中(self、n\u streams、dtype、inc\r状态)
1254#如果未编译multMatVect.dot#模,请编译它。
1255如果multMatVect.dot_模为无:
->1256多目标(rval[0],A1p72,M1,A2p72,M2)
1257
1258#这种调用Theano fct的方式是为了绕过Theano开销。
C:\ProgramData\Anaconda3\lib\site packages\theano\sandbox\rng\u mrg.py在multMatVect(v、A、m1、B、m2)中
64 o=点模()(A_-sym,s_-sym,m_-sym,A2_-sym,s2_-sym,m2_-sym)
65 multMatVect.dot_模=函数(
--->66[A_-sym,s_-sym,m_-sym,A2_-sym,s2_-sym,m2_-sym],o,profile=False)
67
68#这种调用Theano fct的方式是为了绕过Theano开销。
函数中的C:\ProgramData\Anaconda3\lib\site packages\theano\compile\function.py(输入、输出、模式、更新、给定、无默认更新、就地接受、名称、重建、允许输入、下传、配置文件、打开未使用的输入)
324 on_unused_input=on_unused_input,
325外形=外形,
-->326输出_键=输出_键)
327#如果我们有任何可变或可变的输入,我们需要添加标记检查_别名输入
328#借用已使用的定义输入
pfunc中的C:\ProgramData\Anaconda3\lib\site packages\theano\compile\pfunc.py(参数、输出、模式、更新、给定、,
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-59-12b29e43ecfe> in <module>()
----> 1 model = baseline_model()
2
3 model.fit(x_train, y_train, validation_data=(x_test, y_test), nb_epoch=10, batch_size=200, verbose=2)
4
5 scores = model.evaluate(x_test, y_test, verbose=0)
<ipython-input-57-16bc1d352f3b> in baseline_model()
2 model = Sequential() #RNN?
3 #InputLayer
----> 4 model.add(Dense(num_pixels, input_dim=num_pixels, init='normal', activation='relu'))
5 #OutputLayer
6 model.add(Dense(num_classes, init='normal', activation='softmax'))
C:\ProgramData\Anaconda3\lib\site-packages\keras\models.py in add(self, layer)
420 # and create the node connecting the current layer
421 # to the input layer we just created.
--> 422 layer(x)
423
424 if len(layer.inbound_nodes) != 1:
C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\topology.py in __call__(self, inputs, **kwargs)
526 '`layer.build(batch_input_shape)`')
527 if len(input_shapes) == 1:
--> 528 self.build(input_shapes[0])
529 else:
530 self.build(input_shapes)
C:\ProgramData\Anaconda3\lib\site-packages\keras\layers\core.py in build(self, input_shape)
825 name='kernel',
826 regularizer=self.kernel_regularizer,
--> 827 constraint=self.kernel_constraint)
828 if self.use_bias:
829 self.bias = self.add_weight((self.units,),
C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\topology.py in add_weight(self, shape, initializer, name, trainable, regularizer, constraint)
362 """
363 initializer = initializers.get(initializer)
--> 364 weight = K.variable(initializer(shape), dtype=K.floatx(), name=name)
365 if regularizer is not None:
366 self.add_loss(regularizer(weight))
C:\ProgramData\Anaconda3\lib\site-packages\keras\initializers.py in __call__(self, shape, dtype)
71 def __call__(self, shape, dtype=None):
72 return K.random_normal(shape, self.mean, self.stddev,
---> 73 dtype=dtype, seed=self.seed)
74
75 def get_config(self):
C:\ProgramData\Anaconda3\lib\site-packages\keras\backend\theano_backend.py in random_normal(shape, mean, stddev, dtype, seed)
1935 seed = np.random.randint(1, 10e6)
1936 rng = RandomStreams(seed=seed)
-> 1937 return rng.normal(size=shape, avg=mean, std=stddev, dtype=dtype)
1938
1939
C:\ProgramData\Anaconda3\lib\site-packages\theano\sandbox\rng_mrg.py in normal(self, size, avg, std, ndim, dtype, nstreams)
1572 n_samples = prod(size) + (prod(size) % 2)
1573 flattened = self.uniform(size=(n_samples,), dtype=dtype,
-> 1574 nstreams=nstreams)
1575
1576 if constant:
C:\ProgramData\Anaconda3\lib\site-packages\theano\sandbox\rng_mrg.py in uniform(self, size, low, high, ndim, dtype, nstreams)
1352 if nstreams is None:
1353 nstreams = self.n_streams(size)
-> 1354 rstates = self.get_substream_rstates(nstreams, dtype)
1355
1356 if self.use_cuda and dtype == 'float32':
C:\ProgramData\Anaconda3\lib\site-packages\theano\configparser.py in res(*args, **kwargs)
115 def res(*args, **kwargs):
116 with self:
--> 117 return f(*args, **kwargs)
118 return res
119
C:\ProgramData\Anaconda3\lib\site-packages\theano\sandbox\rng_mrg.py in get_substream_rstates(self, n_streams, dtype, inc_rstate)
1254 # If multMatVect.dot_modulo isn't compiled, compile it.
1255 if multMatVect.dot_modulo is None:
-> 1256 multMatVect(rval[0], A1p72, M1, A2p72, M2)
1257
1258 # This way of calling the Theano fct is done to bypass Theano overhead.
C:\ProgramData\Anaconda3\lib\site-packages\theano\sandbox\rng_mrg.py in multMatVect(v, A, m1, B, m2)
64 o = DotModulo()(A_sym, s_sym, m_sym, A2_sym, s2_sym, m2_sym)
65 multMatVect.dot_modulo = function(
---> 66 [A_sym, s_sym, m_sym, A2_sym, s2_sym, m2_sym], o, profile=False)
67
68 # This way of calling the Theano fct is done to bypass Theano overhead.
C:\ProgramData\Anaconda3\lib\site-packages\theano\compile\function.py in function(inputs, outputs, mode, updates, givens, no_default_updates, accept_inplace, name, rebuild_strict, allow_input_downcast, profile, on_unused_input)
324 on_unused_input=on_unused_input,
325 profile=profile,
--> 326 output_keys=output_keys)
327 # We need to add the flag check_aliased inputs if we have any mutable or
328 # borrowed used defined inputs
C:\ProgramData\Anaconda3\lib\site-packages\theano\compile\pfunc.py in pfunc(params, outputs, mode, updates, givens, no_default_updates, accept_inplace, name, rebuild_strict, allow_input_downcast, profile, on_unused_input, output_keys)
484 accept_inplace=accept_inplace, name=name,
485 profile=profile, on_unused_input=on_unused_input,
--> 486 output_keys=output_keys)
487
488
C:\ProgramData\Anaconda3\lib\site-packages\theano\compile\function_module.py in orig_function(inputs, outputs, mode, accept_inplace, name, profile, on_unused_input, output_keys)
1794 on_unused_input=on_unused_input,
1795 output_keys=output_keys).create(
-> 1796 defaults)
1797
1798 t2 = time.time()
C:\ProgramData\Anaconda3\lib\site-packages\theano\compile\function_module.py in create(self, input_storage, trustme, storage_map)
1660 theano.config.traceback.limit = theano.config.traceback.compile_limit
1661 _fn, _i, _o = self.linker.make_thunk(
-> 1662 input_storage=input_storage_lists, storage_map=storage_map)
1663 finally:
1664 theano.config.traceback.limit = limit_orig
C:\ProgramData\Anaconda3\lib\site-packages\theano\gof\link.py in make_thunk(self, input_storage, output_storage, storage_map)
697 return self.make_all(input_storage=input_storage,
698 output_storage=output_storage,
--> 699 storage_map=storage_map)[:3]
700
701 def make_all(self, input_storage, output_storage):
C:\ProgramData\Anaconda3\lib\site-packages\theano\gof\vm.py in make_all(self, profiler, input_storage, output_storage, storage_map)
1045 compute_map,
1046 no_recycling,
-> 1047 impl=impl))
1048 linker_make_thunk_time[node] = time.time() - thunk_start
1049 if not hasattr(thunks[-1], 'lazy'):
C:\ProgramData\Anaconda3\lib\site-packages\theano\gof\op.py in make_thunk(self, node, storage_map, compute_map, no_recycling, impl)
933 try:
934 return self.make_c_thunk(node, storage_map, compute_map,
--> 935 no_recycling)
936 except (NotImplementedError, utils.MethodNotDefined):
937 # We requested the c code, so don't catch the error.
C:\ProgramData\Anaconda3\lib\site-packages\theano\gof\op.py in make_c_thunk(self, node, storage_map, compute_map, no_recycling)
837 _logger.debug('Trying CLinker.make_thunk')
838 outputs = cl.make_thunk(input_storage=node_input_storage,
--> 839 output_storage=node_output_storage)
840 fill_storage, node_input_filters, node_output_filters = outputs
841
C:\ProgramData\Anaconda3\lib\site-packages\theano\gof\cc.py in make_thunk(self, input_storage, output_storage, storage_map, keep_lock)
1188 cthunk, in_storage, out_storage, error_storage = self.__compile__(
1189 input_storage, output_storage, storage_map,
-> 1190 keep_lock=keep_lock)
1191
1192 res = _CThunk(cthunk, init_tasks, tasks, error_storage)
C:\ProgramData\Anaconda3\lib\site-packages\theano\gof\cc.py in __compile__(self, input_storage, output_storage, storage_map, keep_lock)
1129 output_storage,
1130 storage_map,
-> 1131 keep_lock=keep_lock)
1132 return (thunk,
1133 [link.Container(input, storage) for input, storage in
C:\ProgramData\Anaconda3\lib\site-packages\theano\gof\cc.py in cthunk_factory(self, error_storage, in_storage, out_storage, storage_map, keep_lock)
1584 node.op.prepare_node(node, storage_map, None, 'c')
1585 module = get_module_cache().module_from_key(
-> 1586 key=key, lnk=self, keep_lock=keep_lock)
1587
1588 vars = self.inputs + self.outputs + self.orphans
C:\ProgramData\Anaconda3\lib\site-packages\theano\gof\cmodule.py in module_from_key(self, key, lnk, keep_lock)
1157 try:
1158 location = dlimport_workdir(self.dirname)
-> 1159 module = lnk.compile_cmodule(location)
1160 name = module.__file__
1161 assert name.startswith(location)
C:\ProgramData\Anaconda3\lib\site-packages\theano\gof\cc.py in compile_cmodule(self, location)
1487 lib_dirs=self.lib_dirs(),
1488 libs=libs,
-> 1489 preargs=preargs)
1490 except Exception as e:
1491 e.args += (str(self.fgraph),)
C:\ProgramData\Anaconda3\lib\site-packages\theano\gof\cmodule.py in compile_str(module_name, src_code, location, include_dirs, lib_dirs, libs, preargs, py_module, hide_symbols)
2345 open(os.path.join(location, "__init__.py"), 'w').close()
2346 assert os.path.isfile(lib_filename)
-> 2347 return dlimport(lib_filename)
2348
2349
C:\ProgramData\Anaconda3\lib\site-packages\theano\gof\cmodule.py in dlimport(fullpath, suffix)
300 warnings.filterwarnings("ignore",
301 message="numpy.ndarray size changed")
--> 302 rval = __import__(module_name, {}, {}, [module_name])
303 t1 = time.time()
304 import_time += t1 - t0
ImportError: DLL load failed: Eine DLL-Initialisierungsroutine ist fehlgeschlagen.