AttributeError: module 'numpy.core.multiarray' has no attribute 'get_ndarray_c_version' theano keras

本文介绍了解决Theano与NumPy版本不兼容导致的错误module'numpy.core.multiarray'hasnoattribute'get_ndarray_c_version'的方法。提供两种解决方案,一种是下载并手动安装特定版本的Theano,另一种是在Theano源代码中修改特定行以适配当前的NumPy版本。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

import theano 之后 出现   module 'numpy.core.multiarray' has no attribute 'get_ndarray_c_version' 

 

https://stackoverflow.com/questions/55046335/numpy-attributeerror-with-theano-module-numpy-core-multiarray-has-no-attribut

This is a known bug presumably caused by changes introduced in NumPy. A fix for this was introduced in Theano v1.0.4. So, either you need to upgrade to at least that version of Theano, or downgrade NumPy to below v1.16.

stackoverflow 某大神的解释如上。

 

conda list 后查看了下  theano 版本为 1.0.3  ,输入 conda update theano 没有用。

numpy降版本不方便。

 

解决办法:

------------------------------------------------------------------------------------------------------------------

https://anaconda.org/conda-forge/theano/files  下载对应的离线安装包

比如我的是win64 下载的是 win-64/theano-1.0.4-py27hc56fc5f_1000.tar.bz2  

到下载的文件夹 shift+右击 进入 powershell 

输入 :

conda install --use-local theano-1.0.4-py27hc56fc5f_1000.tar.bz2

------------------------------------------------------------------------------------------------------------------

上述方法会导致 prompt 闪退 

"Did not find VS in registry or in VS140COMNTOOLS env var - exiting"

具体修复方法 :

conda uninstall vs2015_win-64

https://stackoverflow.com/questions/53635462/anaconda-prompt-closes-immediately-the-system-was-unable-to-find-the-specified

 

 

新解决办法:

到    Anaconda3\pkgs\theano-1.0.3-py37_0\Lib\site-packages\theano\gof  文件夹下面,打开 cc.py 文件。

定位到1376行(ctrl+g),注释掉

sig.append('NPY_ABI_VERSION=0x%X' %
        np.core.multiarray._get_ndarray_c_version())

如图:

https://github.com/MichalDanielDobrzanski/DeepLearningPython35/issues/20

https://www.wandouip.com/t5i268914/

我现在的版本号是Keras version: 3.10.0 TensorFlow version: 2.19.0 然后报错如下: AttributeError Traceback (most recent call last) Cell In[20], line 47 6 callbacks = [ 7 # 早停回调:当验证损失10个epoch未改善(变化<0.0001)时终止训练 8 # 参数说明: (...) 37 tf.keras.callbacks.TensorBoard(log_dir=path_for_logs) 38 ] 40 # 执行模型训练 41 # 参数说明: 42 # finalaugimg - 增强后的训练图像数据(形状应为(num_samples, 512, 512, 1)) (...) 45 # batch_size=7 - 较小批量,适用于显存有限情况(建议根据GPU容量调整) 46 # epochs=100 - 最大训练轮次(实际可能因早停提前终止) ---> 47 results = model.fit(finalaugimg, 48 finalaugmask/255, # 标签归一化操作(若标签为0/1应跳过) 49 validation_split=0.1, 50 batch_size=7, 51 epochs=10, 52 callbacks=callbacks) File ~\AppData\Roaming\Python\Python39\site-packages\keras\src\utils\traceback_utils.py:122, in filter_traceback.<locals>.error_handler(*args, **kwargs) 119 filtered_tb = _process_traceback_frames(e.__traceback__) 120 # To get the full stack trace, call: 121 # `keras.config.disable_traceback_filtering()` --> 122 raise e.with_traceback(filtered_tb) from None 123 finally: 124 del filtered_tb Cell In[18], line 33, in focal_loss.<locals>.focal_loss_fixed(y_true, y_pred) 30 pt_0 = tf.where(tf.equal(y_true, 0), 1 - y_pred, tf.ones_like(y_pred)) # 修正负样本pt计算 32 # 计算正样本损失项 ---> 33 pos_loss = -K.mean(alpha * K.pow(1. - pt_1, gamma) * K.log(pt_1 + K.epsilon())) 35 # 计算负样本损失项(修正后) 36 neg_loss = -K.mean((1 - alpha) * K.pow(1. - pt_0, gamma) * K.log(pt_0 + K.epsilon())) # 使用修正后的pt_0 AttributeError: module 'keras.backend' has no attribute 'mean'
最新发布
08-15
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值