关于精度测量

时间:2019-07-02 16:00:14

标签: pytorch

我在计算每个训练步骤的设计模型的精确度时遇到问题,该模型的精确度为0.5。它具有一个输出神经元,对番茄撕裂是否有用。

我尝试最后使用BCEWithLogitsloss()删除和添加辍学层和损失函数,但没有任何改善。

代码部分已粘贴

model_conv = torchvision.models.vgg16(pretrained=True)
for param in model_conv.parameters():
    param.requires_grad = False

# Parameters of newly constructed modules have requires_grad=True by default
num_ftrs = model_conv.classifier[6].out_features
model_conv.classifier = nn.Sequential(model_conv.classifier, nn.ReLU(inplace=True),
                                      nn.Linear(num_ftrs,1),nn.Sigmoid())

print(model_conv)
model_conv = model_conv.to(device)

criterion = nn.MSELoss()

# Observe that only parameters of final layer are being optimized as
# opposed to before.
optimizer_conv = optim.SGD(model_conv.classifier[2].parameters(), lr=0.001, momentum=0.9)

# Decay LR by a factor of 0.1 every 7 epochs
exp_lr_scheduler = lr_scheduler.StepLR(optimizer_conv, step_size=7, gamma=0.1)

######################################################################
# Train and evaluate
# ^^^^^^^^^^^^^^^^^^
#
# On CPU this will take about half the time compared to previous scenario.
# This is expected as gradients don't need to be computed for most of the
# network. However, forward does need to be computed.
#

model_conv = train_model(model_conv, criterion, optimizer_conv,
                         exp_lr_scheduler, num_epochs=25)

我希望准确度应在每个步骤中都发生变化,但不会改变。

0 个答案:

没有答案