【发布时间】:2019-11-10 20:36:24
【问题描述】:
我目前正在使用此代码来获取图像的灰度图像表示,并以(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]
【问题讨论】:
-
mask_instance = mask_instance[:, :, np.newaxis]是向数组添加尾随维度的另一种方式。
标签: python-3.x numpy opencv keras