簡體   English   中英

ValueError:無法將輸入數組從形狀(50,50,3)廣播到形狀(50,50)

[英]ValueError: could not broadcast input array from shape (50,50,3) into shape (50,50)

試圖將數據集中的數據加載到數組 data[] 中,給我一個廣播錯誤。

代碼:

path = os.path.join(cur_path , r'Pothole_Image_Data')
print(path)
images = os.listdir(path)
for i in images   :
  try   :
     image =  Image.open(path + '\\'  + i )
     image = image.resize((50,50))
     image = np.array(image)
     data.append(image)
  except : 
    print("Image not found")

data = np.array(data)
print(data.shape)

錯誤:

  ValueError  Traceback (most recent call last)

   11         print("Image not found")
   ---> 13 data = np.array(data)
   14 print(data.shape)

ValueError: could not broadcast input array from shape (50,50,3) into shape (50,50)

圖像通常加載為 X * Y * 3(或 3 * X * Y)arrays,因為圖像存儲紅色、綠色和藍色像素值的值。 因此,要么將它們重塑為 50、50、3 數組(創建 4D N * 50 * 50 *3)數組,要么考慮如何合並 3 個顏色通道。

如果您想從中制作灰度圖片(可以存儲在 50x50 陣列中),請使用例如亮度方法:val = (0.3 * R) + (0.59 * G) + (0.11 * B)。

但這取決於您的應用程序。 我假設(考慮到您構建圖像陣列的方式)它將用於神經網絡? 然后我只使用3個頻道。 Tensorflow 可以處理,Conv2d 甚至有一個變量來設置通道數。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM