代码之家  ›  专栏  ›  技术社区  ›  SDG

试图重塑我的numpy数组以获得额外的维度

  •  0
  • SDG  · 技术社区  · 5 年前

    我目前正在使用这个代码来获取一个图像的灰度图像表示,并以 (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)

    __________________________________________________________________________________________________
    conv2d_19 (Conv2D)              (None, 512, 370, 1)  17          activation_18[0][0]
    
    2 回复  |  直到 5 年前
        1
  •  1
  •   Daniel Möller    5 年前
    • reshape 工作不到位!
    • 形状必须是元组。

    .

    mask_instance = mask_instance.reshape((target_size[0], target_size[1], 1))
    
        2
  •  0
  •   SDG    5 年前

    好像 np.reshape() mask_instance = np.expand_dims(mask_instance, axis=2) . 轴是2,因为后端在上一个模型上运行。