【发布时间】:2019-07-31 07:12:24
【问题描述】:
model = ResNet50(weights='imagenet', include_top=False, input_shape=(224, 224, 3))
上面的代码允许我使用 imagenet 的权重,但我想使用我自己的 imagenet 权重,我应该在我的代码中进行哪些更改以允许我只在自己的数据集上训练最后一层?这是我的模型的代码:
def mini_XCEPTION(input_shape, num_classes, l2_regularization=0.01): 正则化 = l2(l2_regularization) # 根据 img_input = 输入(输入形状) x = Conv2D(8, (3, 3), strides=(1, 1), kernel_regularizer=regularization, use_bias=False)(img_input) x = BatchNormalization()(x) x = 激活('relu')(x) x = Conv2D(8, (3, 3), strides=(1, 1), kernel_regularizer=regularization, use_bias=False)(x) x = BatchNormalization()(x) x = 激活('relu')(x) # 模块 1 残差 = Conv2D(16, (1, 1), strides=(2, 2), padding='same', use_bias=False)(x) 残差 = BatchNormalization()(残差) x = SeparableConv2D(16, (3, 3), padding='same', kernel_regularizer=正则化, use_bias=False)(x) x = BatchNormalization()(x) x = 激活('relu')(x) x = SeparableConv2D(16, (3, 3), padding='same', kernel_regularizer=正则化, use_bias=False)(x) x = BatchNormalization()(x) x = MaxPooling2D((3, 3), strides=(2, 2), padding='same')(x) x = layers.add([x, 残差]) # 模块 2 残差 = Conv2D(32, (1, 1), strides=(2, 2), padding='same', use_bias=False)(x) 残差 = BatchNormalization()(残差) x = SeparableConv2D(32, (3, 3), padding='same', kernel_regularizer=正则化, use_bias=False)(x) x = BatchNormalization()(x) x = 激活('relu')(x) x = SeparableConv2D(32, (3, 3), padding='same', kernel_regularizer=正则化, use_bias=False)(x) x = BatchNormalization()(x) x = MaxPooling2D((3, 3), strides=(2, 2), padding='same')(x) x = layers.add([x, 残差]) # 模块 3 残差 = Conv2D(64, (1, 1), strides=(2, 2), padding='same', use_bias=False)(x) 残差 = BatchNormalization()(残差) x = SeparableConv2D(64, (3, 3), padding='same', kernel_regularizer=正则化, use_bias=False)(x) x = BatchNormalization()(x) x = 激活('relu')(x) x = SeparableConv2D(64, (3, 3), padding='same', kernel_regularizer=正则化, use_bias=False)(x) x = BatchNormalization()(x) x = MaxPooling2D((3, 3), strides=(2, 2), padding='same')(x) x = layers.add([x, 残差]) # 模块 4 残差 = Conv2D(128, (1, 1), strides=(2, 2), padding='same', use_bias=False)(x) 残差 = BatchNormalization()(残差) x = SeparableConv2D(128, (3, 3), padding='same', kernel_regularizer=正则化, use_bias=False)(x) x = BatchNormalization()(x) x = 激活('relu')(x) x = SeparableConv2D(128, (3, 3), padding='same', kernel_regularizer=正则化, use_bias=False)(x) x = BatchNormalization()(x) x = MaxPooling2D((3, 3), strides=(2, 2), padding='same')(x) x = layers.add([x, 残差]) x = Conv2D(num_classes, (3, 3), # kernel_regularizer=正则化, 填充='相同')(x) x = GlobalAveragePooling2D()(x) 输出=激活('softmax',名称='预测')(x) 模型 = 模型(img_input,输出) 返回模型【问题讨论】:
-
您在这里提问时需要标记或至少提及您正在使用的第三方模块——我做了一些猜测......
标签: python keras neural-network