你好,我有一个由80×60的32FC1图像组成数据集,我正在尝试重塑这个数据集以便转换和标记它,从而用于训练CNN。但是在我重塑数据集时,遇到了以下错误:
arraynegativos= ds_negatives.reshape(( n_negatives_img, img_width, img_height))arraypositivos= ds_positives.reshape((n_positives_img, img_width, img_height))AttributeError: 'list' object has no attribute 'reshape'
因此,我将我的ds_negative转换为numpy数组,像这样:
ds_negatives1 = np.array(ds_negatives)
但它给我这个错误:
cannot reshape array of size 1 into shape (26308,80,60)
所以现在我有点困惑,我该如何转换我的数据集以达到重塑的目的呢?
这是脚本的链接,以便你能更好地查看。
https://colab.research.google.com/drive/1KzoHXA8Y6lcyvq7K7segFfJp2AIw9P45?usp=sharing
回答:
当你说ds_negatives = ["/content/drive/MyDrive/Colab Notebooks/negative_depth.txt"]
时,你并不是将ds_negatives
设置为该文件的内容,而是简单地将其设置为包含文件路径的字符串。因此,这个列表(以及你从中创建的numpy数组)只包含一个项目。根据你希望如何读取文本文件,你应该使用类似open("path", "r").read()
或.readlines()
的方法。