TensorFlow中常见的错误解释及解决方法
10,239 阅读
1、AttributeError: 'tuple' object has no attribute 'ndims'
使用TensorFlow中的keras接口来建立模型,然后调用的时候出现上述AttributeError: 'tuple' object has no attribute 'ndims'错误。这时候需要检查input的数据是否是Tensor格式。我之前遇到这个问题一直以为是keras的input不支持list的原因(我自定义的Layer,输入是多个array组合的list),最终发现是我的输入数据是两个numpy array组成的list,只需要把numpy array list转换成tensor的list即可。 如:
input1 = np.zeors((3,3))
input2 = np.zeors((4,2))
customer_layer = CustomerLayer()
# 如下使用方法会报错
res = customer_layer([input1,input2])
上述代码会出错,需要将两个input转换成tensor
