[英]How do i reshape my dataset to train a CNN
您好,我有一個 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
當您說ds_negatives = ["/content/drive/MyDrive/Colab Notebooks/negative_depth.txt"]
您不是將ds_negatives
設置ds_negatives
文件的內容,而只是將其設置為包含文件路徑的字符串。 因此列表(以及您從中創建的 np 數組)僅包含一項。 根據您想如何閱讀文本文件,您應該使用open("path", "r").read()
或.readlines()
您需要將圖像加載到列表或數組中。 嘗試在以下腳本中使用“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))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.