示例#1
0
            x = F.relu(F.max_pool2d(self.conv1(x), 2))
            x = F.relu(F.max_pool2d(self.conv2(x), 2))
            x = x.view(-1, 320)
            x = F.relu(self.fc1(x))
            x = self.fc2(x)
            return F.log_softmax(x)

    model = Net()
    model.cuda()

    optimizer = optim.SGD(model.parameters(), lr=H.lr, momentum=H.momentum)

    train(
        model, optimizer, tn_loader, val_loader, H, S, inner_log,
        struct(val_acc=acc_metric(model, val_loader),
               val_loss=nll_metric(model, val_loader),
               tn_loss=nll_metric(model, tn_loader),
               tn_acc=acc_metric(model, tn_loader)))

    val_accs = [
        batch.val_acc for batch in inner_log.metrics() if 'val_acc' in batch
    ]
    val_losses = [
        batch.val_loss for batch in inner_log.metrics() if 'val_loss' in batch
    ]
    tn_accs = [
        batch.tn_acc for batch in inner_log.metrics() if 'tn_acc' in batch
    ]
    tn_losses = [
        batch.tn_loss for batch in inner_log.metrics() if 'tn_loss' in batch
    ]
示例#2
0
    def __init__(self):
        super(Net, self).__init__()
        self.features = vgg('vgg11')
        self.classifier = nn.Linear(512, 10)

    def forward(self, x):
        out = self.features(x)
        out = out.view(out.size(0), -1)
        out = self.classifier(out)
        out = F.log_softmax(out)
        return out


model = Net()
# model = Net()
model.cuda()

optimizer = optim.SGD(model.parameters(), lr=H.lr, momentum=H.momentum)

print('Beginning training')
train(model,
      optimizer,
      tn_loader,
      val_loader,
      H,
      S,
      log,
      struct(val_acc=acc_metric(model, val_loader),
             val_loss=nll_metric(model, val_loader)),
      param_log_freq=3)