小编Jun*_*Ali的帖子

“模型”层的输入 0 与该层不兼容:预期形状=(无, 512, 512, 3),发现形状=(512, 512, 3)

我正在训练二进制类的 Unet 分割模型。数据集加载到张量流数据管道中。图像呈 (512, 512, 3) 形状,掩模呈 (512, 512, 1) 形状。该模型期望输入的形状为 (512, 512, 3)。但我收到以下错误。“模型”层的输入 0 与该层不兼容:预期形状=(无, 512, 512, 3),发现形状=(512, 512, 3)

这是元数据数据框中的图像。

元数据数据框

随机采样索引来选择训练集和验证集

num_samples = train_metadata.shape[0]
train_indices = np.random.choice(range(num_samples), int(num_samples * 0.8), replace=False)

valid_indices = list(set(range(num_samples)) - set(train_indices))

train_samples = train_metadata.iloc[train_indices, ]
valid_samples = train_metadata.iloc[valid_indices, ]
Run Code Online (Sandbox Code Playgroud)

方面

IMG_WIDTH = 512
IMG_HEIGHT = 512
IMG_CHANNELS = 3
Run Code Online (Sandbox Code Playgroud)

训练图像的解析函数

def parse_function_train_images(image_path):
    image_path = image_path
    mask_path = tf.strings.regex_replace(image_path, "sat", "mask")
    mask_path = tf.strings.regex_replace(mask_path, "jpg", "png")

    image = tf.io.read_file(image_path)
    image = tf.image.decode_jpeg(image, channels=3)
    image …
Run Code Online (Sandbox Code Playgroud)

python neural-network image-segmentation keras tensorflow

5
推荐指数
1
解决办法
1883
查看次数