簡體   English   中英

試圖重塑我的Numpy數組以具有額外的尺寸

[英]Trying to reshape my numpy array to have an extra dimension

我目前正在使用此代碼來獲取圖像的灰度圖像表示形式,並以(512, 370, 1)數組的格式表示它。

img_instance = cv2.imread(df.iloc[i][x_col]) / 255.
img_instance = cv2.resize(img_instance, (target_size[1], target_size[0]))
mask_instance = cv2.imread(df.iloc[i][y_col], cv2.IMREAD_GRAYSCALE) / 255.
mask_instance = cv2.resize(mask_instance, (target_size[1], target_size[0]))
print(mask_instance.shape)
mask_instance.reshape(target_size[0], target_size[1], 1)
print(mask_instance.shape)

第一次打印時,我也得到(512, 370) ,然后在第二個打印語句中也得到(512, 370) 這對我來說是個問題,因為我正在嘗試構建Keras模型,在該模型中我有一個看起來像是我要將遮罩實例適合到的下一層的層。

__________________________________________________________________________________________________
conv2d_19 (Conv2D)              (None, 512, 370, 1)  17          activation_18[0][0]
  • reshape無法就地工作!
  • 形狀必須是元組。

mask_instance = mask_instance.reshape((target_size[0], target_size[1], 1))

似乎np.reshape()沒有添加尺寸,但是要使用的正確函數是mask_instance = np.expand_dims(mask_instance, axis=2) 軸為2,因為后端在通道最后一個模型上運行。

暫無
暫無

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

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