【问题标题】:How do i reshape my dataset to train a CNN我如何重塑我的数据集以训练 CNN
【发布时间】:2021-10-30 08:20:18
【问题描述】:

您好,我有一个 80x60 的 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

【问题讨论】:

    标签: python numpy tensorflow machine-learning keras


    【解决方案1】:

    当您说ds_negatives = ["/content/drive/MyDrive/Colab Notebooks/negative_depth.txt"] 时,您并没有将ds_negatives 设置为该文件的内容,而只是设置为包含文件路径的字符串。因此,列表(以及您从中创建的 np 数组)仅包含一项。根据您阅读文本文件的方式,您应该使用 open("path", "r").read().readlines()

    【讨论】:

      【解决方案2】:

      您需要将图像加载到列表或数组中。尝试在以下脚本中使用“imread”和“append”函数:

      imagesWithLabels = []
      for filename in listdir('C:/AI/images/cats'):
          # load image
          img_data =   image.imread('C:/AI/images/cats/' +\
          filename)
          # store loaded image in a list
          imagesWithLabels.append((img_data,0))
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-04-27
        • 1970-01-01
        • 1970-01-01
        • 2021-01-17
        • 2018-12-10
        • 2020-08-27
        • 1970-01-01
        • 2019-04-15
        相关资源
        最近更新 更多