【发布时间】:2021-03-04 15:52:57
【问题描述】:
我正在尝试执行图像分类任务,为此我正在使用 VGG 模型。现在,我正在使用 3 个 epoch,因为我不希望训练花费很多时间,但是从一开始我的模型就给出了非常糟糕的准确性。谁能告诉我如何使这个模型更准确?这就是我创建模型时的原因:
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)
我真的希望我的模型像现在这样更准确。
【问题讨论】:
-
请展示model.fit生成的部分数据
-
对不起,我是 ML 新手,不太明白你的意思,是 epochs 完成后的东西吗?
-
这是model.fit在训练期间产生的数据。还可以尝试将你的辍学率降低到 0.1 或 0.2。使用 0.5,您在训练期间消除了一半的神经元。
标签: python tensorflow keras deep-learning vgg-net