为什么这行代码会产生错误?

我是keras的新手,为了入门,我试图按照这个教程进行操作。我使用的是theano后端。不幸的是,我在这一行就遇到了困难:

model.add(Dense(num_pixels, input_dim=num_pixels, init='normal', activation='relu'))

它显示:

UserWarning: 更新您的 Dense 调用至 Keras 2 API: Dense(784, input_dim=784, activation="relu", kernel_initializer="normal") ‘` 调用至 Keras 2 API: ‘ + signature)

INFO (theano.gof.compilelock): 正在刷新锁 […]

同时也抛出了一个错误:ImportError: DLL 加载失败:动态链接库 (DLL) 初始化例程失败。

我做错了什么?任何建议都非常受欢迎 😀

这是完整的错误跟踪(部分为德语):

---------------------------------------------------------------------------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 inputsC:\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_origC:\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 inC:\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.orphansC:\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 - t0ImportError: DLL load failed: Eine DLL-Initialisierungsroutine ist fehlgeschlagen.

回答:

我通过简单地重新安装解决了这个问题。可能是之前的安装出了什么问题。对于Windows用户,我强烈推荐这个教程:http://efavdb.com/gpu-accelerated-theano-keras-with-windows-10/

Related Posts

L1-L2正则化的不同系数

我想对网络的权重同时应用L1和L2正则化。然而,我找不…

使用scikit-learn的无监督方法将列表分类成不同组别,有没有办法?

我有一系列实例,每个实例都有一份列表,代表它所遵循的不…

f1_score metric in lightgbm

我想使用自定义指标f1_score来训练一个lgb模型…

通过相关系数矩阵进行特征选择

我在测试不同的算法时,如逻辑回归、高斯朴素贝叶斯、随机…

可以将机器学习库用于流式输入和输出吗?

已关闭。此问题需要更加聚焦。目前不接受回答。 想要改进…

在TensorFlow中,queue.dequeue_up_to()方法的用途是什么?

我对这个方法感到非常困惑,特别是当我发现这个令人费解的…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注