我正在尝试使用深度学习进行肺部检测,但遇到了一些错误。
我有一个 keras 模型,我将在下面附上。我得到的错误如下:
ValueError: Input 0 is incompatible with layer model: expected shape=(None, 1, 512, 512), found shape=(2, 3, 512, 512)
我拥有的模型如下:
def get_unet():
inputs = Input((1,img_rows, img_cols))
conv1 = Convolution2D(32, 3, 1, activation='relu', padding='same')(inputs)
conv1 = Convolution2D(32, 3, 1, activation='relu', padding='same')(conv1)
pool1 = MaxPooling2D(pool_size=(2, 2))(conv1)
conv2 = Convolution2D(64, 3, 1, activation='relu', padding='same')(pool1)
conv2 = Convolution2D(64, 3, 1, activation='relu', padding='same')(conv2)
pool2 = MaxPooling2D(pool_size=(2, 2))(conv2)
conv3 = Convolution2D(128, 3, 1, activation='relu', padding='same')(pool2)
conv3 = Convolution2D(128, 3, 1, activation='relu', padding='same')(conv3)
pool3 = MaxPooling2D(pool_size=(2, 2), padding='same')(conv3)
conv4 = Convolution2D(256, 3, 1, activation='relu', padding='same')(pool3)
conv4 = Convolution2D(256, 3, 1, activation='relu', padding='same')(conv4)
pool4 = MaxPooling2D(pool_size=(2, 2), padding='same')(conv4)
conv5 = Convolution2D(512, 3, 1, activation='relu', padding='same')(pool4)
conv5 = Convolution2D(512, 3, 1, activation='relu', padding='same')(conv5)
up6 = concatenate([UpSampling2D(size=(2, 2))(conv5), conv4], axis=1)
conv6 = Convolution2D(256, 3, 1, activation='relu', padding='same')(up6)
conv6 = Convolution2D(256, 3, 1, activation='relu', padding='same')(conv6)
up7 = concatenate([UpSampling2D(size=(2, 2))(conv6), conv3], axis=1)
conv7 = Convolution2D(128, 3, 1, activation='relu', padding='same')(up7)
conv7 = Convolution2D(128, 3, 1, activation='relu', padding='same')(conv7)
up8 = concatenate([UpSampling2D(size=(2, 2))(conv7), conv2], axis=1)
conv8 = Convolution2D(64, 3, 1, activation='relu', padding='same')(up8)
conv8 = Convolution2D(64, 3, 1, activation='relu', padding='same')(conv8)
up9 = concatenate([UpSampling2D(size=(2, 2))(conv8), conv1], axis=1)
conv9 = Convolution2D(32, 3, 1, activation='relu', padding='same')(up9)
conv9 = Convolution2D(32, 3, 1, activation='relu', padding='same')(conv9)
conv10 = Convolution2D(1, 1, 1, activation='sigmoid')(conv9)
model = Model(inputs=inputs, outputs=conv10)
print(model.summary())
model.compile(optimizer=Adam(lr=1.0e-5), loss=dice_coef_loss, metrics=[dice_coef])
return model
我知道模型的输入是 (1,512,512),图像的输入是 (3,512,512)。我只是一个初学者,我不知道该怎么做。但是,我不想更改模型的结构并希望保持原样。我也不想改变模型输入的形状。所以请给我一些建议来改变图像尺寸,使它们与模型的输入尺寸相匹配!谢谢