我正在尝试使用Keras中的MobileNet权重将转移学习应用于MNIST . Keras文档使用MobileNet https://keras.io/applications/#mobilenet

Mobilenet接受224x224x3作为输入,但MNIST是28x28x1 . 我正在创建一个Lambda图层,它可以将28x28x1图像转换为224x224x3并将其作为输入发送到MobileNet . 以下代码导致

TypeError: Model 的输入图层必须是 InputLayer 个对象 . 收到的输入:Tensor("lambda_2/ResizeNearestNeighbor:0",shape =(?,224,224,3),dtype = float32) . 输入0(从0开始)源自图层类型 Lambda .

height = 28
width = 28
input_image = Input(shape=(height,width,1))

def resize_image_to_inception(x):
    x = K.repeat_elements(x, 3, axis=3)
    x = K.resize_images(x, 8, 8, data_format="channels_last")
    return x

input_image_ = Lambda(resize_image_to_inception, output_shape=(224, 224, 3))(input_image)
print(type(input_image_))
base_model = MobileNet(input_tensor=input_image_, weights='imagenet', include_top=False)