tensorflow2 对模型的图像输入作了预处理也遇到了一些问题也做出了一些解决方案

AttributeError: 'numpy.ndarray' object has no attribute 'append' python报错

  1. np.array数组不能进行append函数添加,所以使用了.tolist()方法将图片数组转化成列表形式进行添加

如:

Img_data = []

Img = np.array(img)

Img.tolist()

Img_data.append(img)

 

    UnimplementedError:不支持将字符串强制转换为浮点

  1. 输入标签不能以字符串的形式,所以将标签改成了 0,1,2,3,4,5,6的整数形式
  2. 运用fit函数需要很大的内存,对于笔记本来说不建议。所以使用了fit_generator函数进行实时生成

 

Input 0 of layer conv2d is incompatible with the layer: expected ndim=4, found ndim=3

  1. 因为输入卷积层的维度不符合标准,应该为四维的数组。而图片只有三维,加上batch_size就有四维了。
posted @ 2022-03-07 12:29  裴枫丶  阅读(176)  评论(0)    收藏  举报