简体   繁体   English

VGG16转移学习不同的输出

[英]VGG16 Transfer Learning varying output

Observed strange behavior when using VGG16 for transfer learning. 使用VGG16进行转移学习时观察到奇怪的行为。

model = VGG16(weights='imagenet',include_top=True)
model.layers.pop()
model.layers.pop()

for layer in model.layers:
    layer.trainable=False

new_layer = Dense(2,activation='softmax')
inp = model.input
out = new_layer(model.layers[-1].output)

model = Model(inp,out)

However, when model.predict(image) is used, the output is varying in terms of classification,ie, sometime it classifies image as Class 1 and next time the same image is classified as Class 2. 然而,当使用model.predict(image) ,输出在分类方面是变化的,即,有时它将图像分类为类1并且下一次将相同图像分类为类2。

It is because you didn't set seed. 这是因为你没有设定种子。 Try this 试试这个

import numpy as np
seed_value = 0
np.random.seed(seed_value)

model = VGG16(weights='imagenet',include_top=True)
model.layers.pop()
model.layers.pop()

for layer in model.layers:
    layer.trainable=False

new_layer = Dense(2, activation='softmax',
                  kernel_initializer=keras.initializers.glorot_normal(seed=seed_value),
                  bias_initializer=keras.initializers.Zeros())
inp = model.input
out = new_layer(model.layers[-1].output)

model = Model(inp,out)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Tensorflow:从vgg16 .tfmodel文件转移学习 - Tensorflow: transfer learning from vgg16 .tfmodel file 使用 CNN 和 VGG16 迁移学习进行图像分类的结果不佳 - Poor results on image classification with CNN and VGG16 transfer learning VGG16 Model 输出尺寸不正确 - 迁移学习 - VGG16 Model Outputs Incorrect dimension - Transfer Learning 如何在迁移学习 vgg16 模型中获得准确率、召回率、f1 分数? - How to get precision, recall, f1 score in transfer learning vgg16 model? 无法使用 VGG16 预训练模型实现多类迁移学习 - Unable to implement the multi class transfer learning using VGG16 pre-trained model Keras VGG16传输学习图像分类带来的极高损失 - Extremely High Loss with Keras VGG16 transfer learning Image Classification 在 CIFAR 10 数据集上使用 VGG16 进行迁移学习:训练和测试精度非常高但预测错误 - Transfer Learning Using VGG16 on CIFAR 10 Dataset: Very High Training and Testing Accuracy But Wrong Predictions 生成Vgg16的中间层输出 - Generating Intermediate layer output of Vgg16 为什么模型没有在keras中使用预训练的vgg16进行学习? - Why is the model not learning with pretrained vgg16 in keras? 如何在pytorch中获得预训练的VGG16的特定层输出 - How to get a particular layer output of a pretrained VGG16 in pytorch
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM