迁移学习mobilenetV2遇到的问题

在迁移学习 MobilenetV2 的过程中遇到 ValueError 错误,原因是目标维度不匹配。通过调整 pooling 参数解决此问题,并了解到 Flatten 层的作用以及 Global Average Pooling 作为全连接层替代的讨论。此外,对于 predict_generator 的 batch_size 使用,理解到 len(test_generator) 实际上是样本数除以 batch_size 向上取整的结果,确保遍历所有样本,但可能存在的重复样本问题。
摘要由CSDN通过智能技术生成

1. 报错:ValueErrorError when checking target: expected dense_2 to have 4dimensions, but got array with shape (32,6) 

base_model = mobilenet_v2.MobileNetV2(
        include_top=False,
        weights='imagenet',
        input_tensor=None,
        input_shape=input_shape)


    # train only the top layers, i.e. freeze all convolutional layers
    for layer in base_model.layers:
        layer.trainable = False

    # add fc layers
    x = base_model.output
    x = Dense(256, activation="elu", kernel_regularizer=regularizers.l2(0.01))(x)
    x = Dropout(0.6)(x)
    x = BatchNormalization()(x)
    #######################################
    predictions = Dense(num_classes, activation="softmax")(x)

    # this is the model we will train
    model = Mod
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值