报错集锦(一)

一些交叉学科痛苦人的五花八门的报错集锦。

1.行列标识不清


  File "pandas\_libs\index.pyx", line 132, in pandas._libs.index.IndexEngine.get_loc (pandas\_libs\index.c:5280)
  File "pandas\_libs\index.pyx", line 154, in pandas._libs.index.IndexEngine.get_loc (pandas\_libs\index.c:5126)
  File "pandas\_libs\hashtable_class_helper.pxi", line 759, in pandas._libs.hashtable.Int64HashTable.get_item (pandas\_libs\hashtable.c:14031)
  File "pandas\_libs\hashtable_class_helper.pxi", line 765, in pandas._libs.hashtable.Int64HashTable.get_item (pandas\_libs\hashtable.c:13975)


 自学的痛苦就是基础不扎实,还好有万能的csdn,其实仔细看看英文也能发现是索引有问题,这个时候换一个数据集debug一下基本上可以看出来不同点,就是索引的设置数大于实际数据的行数或列数。

2.各个包之间调用出现问题



  File "D:\ANA\envs\py36\lib\site-packages\tensorflow_core\python\keras\engine\base_layer.py", line 2029, in <lambda>
    inbound_layers = nest.map_structure(lambda t: t._keras_history.layer,
AttributeError: 'tuple' object has no attribute 'layer'


可能原因:代码中同一个模型添加的网络层来自tensorflow.keras,和keras两个地方。
建议:1.如果使用tensorflow2.0以上版本,使用tenorflow自带的keras来建模。
其中keras相应模块对应在tensorflow.keras的位置参考tf.keras。找到它们,全部更换成tenorflow自带的。
常用的有:参考文章AttributeError: ‘tuple‘ object has no attribute ‘layer‘

from tensorflow.keras.layers import (
    Input, Dense, Conv2D, MaxPooling2D, AveragePooling2D, ZeroPadding2D,
    Flatten, Activation, GlobalAveragePooling2D, GlobalMaxPooling2D, add)
# from keras.layers.normalization import BatchNormalization
from tensorflow.keras.layers import BatchNormalization
from tensorflow.keras.models import Model
from tensorflow.keras import initializers
# from keras.engine import Layer, InputSpec
from tensorflow.keras.layers import Layer, InputSpec
# from keras.engine.topology import get_source_inputs
from tensorflow.keras.utils import get_source_inputs

3.TypeError: unhashable type: 'numpy.ndarray'

错误原因:不可哈希

如果数据的类型可以被改变,则该数据不可哈希,反之可以哈希。

可哈希的元素有:int、float、str、tuple
不可哈希的元素有:list、set、dict

半路出家学习深度学习的难处就在于一个很简单的代码很容易出问题。

model = Model(inputs=[inp1, inp2], outputs=out)  # inp1和inp2作为输入,输出为out的模型实例化
plot_model(model, to_file='RateCNN.png')  # 保存网络模型结构图
history = model.fit(x={img, rate}, y=label, epochs=40)

可以看出图中的x={img, rate},这里将输入组合成了字典,导致代码运行出现错误。

将其改成x=[img, rate]即可。

4.plot_model(auto_encoder, to_file='model.png')


OSError: `pydot` failed to call GraphViz.Please install GraphViz (https://www.graphviz.org/) and ens


keras模型可视化失败,安装三个包,

pip install graphviz

pip install pydot

pip install pydot_ng

还是不行,去官网下载最新版的zip安装,注意环境路径配置好。Keras模型可视化教程及关键问题解决

这里出现的一个问题是:当天配置好了,环境路径也没问题,还是不能解决,需要重启电脑一下。。。。离谱但就是这样。

5.keras ‘InputLayer‘ object is not iterable

接上一个问题:引用的包存在问题,切换成tfkeras的plot_model

from tensorflow.keras.utils import plot_model

6.ValueError: invalid literal for int() with base 10

需要将字符串‘6.000000000000000E9’转换成数字,直接使用int()会报错,因字符串中包含小数点,需转换成float()型,即int(float())。

7.TypeError: ‘float‘ object cannot be interpreted as an integer

想生成一串以0.01为间隔的列表,使用fre=np.linspace(2,6,0.01)出现了报错,因为函数中的起始点,终止点,间隔均是整数值。而想要生成小数位间隔的列表,可以通过以下:

    fre = list(np.arange(2, 6.01, 0.01))

8.TypeError: ufunc 'bitwise_and' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

  if语句中&连接符前后的两个条件需用括号括起来。

        if (S[i] >= -3) & (S_0[i] >= -3):

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值