编码问题
Q1:ValueError: setting an array element with a sequence.
keras冲突使用,检查keras的导入,如果出现使用tensorflow.keras方式引用和keras引用混合就会出现这个问题。
解决:统一为用一个引入,如果是在TensorFlow框架下,建议使用tensorflow.keras。
Q2:ValueError: setting an array element with a sequence.
这个问题是由于数组append的时候,前后数组 shape不一致导致的,必须一致的才能append.
Q3:TypeError: Input ‘b’ of ‘MatMul’ Op has type float32 that does not match type float64 of argument ‘a’
这个问题是因为版本问题,运行到矩阵相乘时会遇到上面的报错。
由于两个相乘矩阵类型不匹配,调试一下发现x矩阵为tf.float64,W矩阵为tf.float32,改类型用tf.cast()函数。如矩阵相乘操作为
y=tf.matmul(x,W)
则修改为:
y = tf.matmul(tf.cast(x,tf.float32),W)
Q4:AttributeError: module ‘tensorflow’ has no attribute ‘get_default_graph’
这个问题与第一个问题类似,造成这个问题的原因是Keras的版本以及与TensorFlow中冲突,解决办法就是修正Keras的引入,以及从Keras中引入的包,都分别改为
from tensorflow import keras
from tensorflow.keras.* import * # *对应所需要的包名
Q5:将list写入csv文件每一条记录后出现空行
打开文件时,添加“ newline=‘’ ”,如:
with open('data.csv','w',newline='') as my_file: