Python 如何从一开始就让我的VGG模型更精确?

Python 如何从一开始就让我的VGG模型更精确?,python,tensorflow,keras,deep-learning,vgg-net,Python,Tensorflow,Keras,Deep Learning,Vgg Net,我试图做一个图像分类任务,为此我使用VGG模型。现在,我使用了3个阶段,因为我不希望训练花费太多时间,但从一开始我的模型就给出了非常糟糕的准确性。谁能告诉我怎样才能使这个模型更准确?这就是为什么我在创建模型时: from tensorflow.keras import layers import tensorflow as tf base_model = VGG16(input_shape = (224, 224, 3), # Shape of our images include_to

我试图做一个图像分类任务,为此我使用VGG模型。现在,我使用了3个阶段,因为我不希望训练花费太多时间,但从一开始我的模型就给出了非常糟糕的准确性。谁能告诉我怎样才能使这个模型更准确?这就是为什么我在创建模型时:


from tensorflow.keras import layers 
import tensorflow as tf 

base_model = VGG16(input_shape = (224, 224, 3), # Shape of our images
include_top = False, # Leave out the last fully connected layer
weights = 'imagenet')


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


# Flatten the output layer to 1 dimension
x = layers.Flatten()(base_model.output)

# Add a fully connected layer with 512 hidden units and ReLU activation
x = layers.Dense(512, activation='relu')(x)

# Add a dropout rate of 0.5
x = layers.Dropout(0.5)(x)

# Add a final sigmoid layer for classification
x = layers.Dense(1, activation='sigmoid')(x)

model = tf.keras.models.Model(base_model.input, x)

model.compile(optimizer = tf.keras.optimizers.RMSprop(lr=0.0001), loss = 'binary_crossentropy',metrics = ['acc'])

history = model.fit(train_generator, validation_data = validation_generator, steps_per_epoch = 100, epochs = 3)

我真的希望我的模型现在更准确。

我想你可能希望你的模型像这样

preprocess_input = tf.keras.applications.vgg16.preprocess_input
input=Input((224,224,3))
x=preprocess_input(input)
x=base_model = tf.keras.applications.VGG16( include_top=False, input_shape=(224,224,3),
                                                                pooling='average', weights='imagenet')(x)
preds=Dense(1, activation='sigmoid')(x)
model=Model(inputs=input, outputs=preds)
model.summary()

每个历元的步骤数和验证步骤数通常设置为样本数//批次大小。在model.fit中将这些值保留为None,它将在内部确定正确的值。同时设置verbose=1,这样您可以在每个历元后看到训练结果。

请显示模型生成的一些数据。fit抱歉,我对ML不太熟悉&我真的不知道您的意思,是历元完成后的内容吗?是数据模型。fit在训练期间生成的。还可以尝试将你的辍学率降低到0.1或0.2。使用0.5,你将在训练中消除一半的神经元。