예제 #1
0
    def evaluate(model,idx):
        model.eval()
        output = model(features)
        loss_ =loss(output,labels,idx)
        acc_ = accuracy(output, labels,idx)

        return loss_.item(),acc_.item()
예제 #2
0
def test():
    model.eval()
    output = model(features, adj)
    loss_test = F.nll_loss(output[idx_test], labels[idx_test])
    acc_test = accuracy(output[idx_test], labels[idx_test])
    print("Test set results:", "loss= {:.4f}".format(loss_test.item()),
          "accuracy= {:.4f}".format(acc_test.item()))
예제 #3
0
def train(epoch):
    t = time.time()
    model.train()
    optimizer.zero_grad()

    output = model(features, adj)
    loss_train = F.nll_loss(output[idx_train], labels[idx_train])
    acc_train = accuracy(output[idx_train], labels[idx_train])

    loss_train.backward()
    optimizer.step()

    loss_val = F.nll_loss(output[idx_val], labels[idx_val])
    acc_val = accuracy(output[idx_val], labels[idx_val])

    print('Epoch: {:04d}'.format(epoch + 1),
          'loss_train: {:.4f}'.format(loss_train.item()),
          'acc_train: {:.4f}'.format(acc_train.item()),
          'loss_val: {:.4f}'.format(loss_val.item()),
          'acc_val: {:.4f}'.format(acc_val.item()),
          'time: {:.4f}s'.format(time.time() - t))
예제 #4
0
    def train(model,idx_train): 
        model.train()

        output = model(features)

        loss_train=loss(output,labels,idx_train)
        acc_train = accuracy(output, labels,idx_train)
        optimizer.zero_grad()
        loss_train.backward()

        optimizer.step()

        return loss_train.item(),acc_train.item()