Example #1
0
h_dim = 128
model = nn.Sequential(nn.Linear(in_dim, h_dim), nn.ReLU(),
                      nn.Linear(h_dim, 10))
opt = optim.SGD(model.parameters(), lr=1.5)

loss_func = F.cross_entropy
learner = Learner(model,
                  opt,
                  loss_func,
                  data,
                  metrics=[accuracy],
                  callbacks=EarlyStopping(patience=3))

learner.fit(10)
learner.test(test_dl)
pred = learner.predict(x_valid)

print(pred.size())

learner.recorder.plot_loss()
learner.recorder.plot_metrics()
plt.show()

# # 1. ------ 数据
# x_train, y_train, x_valid, y_valid = mnist_data()
# train_ds, valid_ds = Dataset(x_train, y_train), Dataset(x_valid, y_valid)
# bs = 128
# train_dl = DataLoader(train_ds, batch_size=bs, shuffle=True)
# valid_dl = DataLoader(valid_ds, batch_size=bs, shuffle=True)
# data = DataBunch(train_dl, valid_dl)
Example #2
0
        for gcn in self.gcns:
            x = gcn(x, edge_index)
            x = F.relu(x)
        x, _, _, batch, _, _ = self.graph_pooling(x, edge_index, None, batch)
        x = global_max_pool(x, batch)
        outputs = self.dense(x)
        outputs = F.relu(outputs)
        outputs = self.out(outputs)
        return outputs

model = Model(dataset.item_num, 2)
opt = optim.SGD(model.parameters(), lr=0.5)


# 3. learner
learner = Learner(model, opt, F.cross_entropy, train_db, metrics=[accuracy])

# 4. fit
learner.fit(3)

# 5. test
learner.test(test_dl)

# 6. predict
pred = learner.predict(test_dl)
print(pred.size())

# 7. plot
learner.recorder.plot_metrics()
plt.show()
        self.conv2 = GCNConv(16, class_num)

    def forward(self, data):
        x, edge_index = data.x, data.edge_index
        x = self.conv1(x, edge_index)
        x = F.relu(x)
        x = self.conv2(x, edge_index)
        outputs = F.relu(x)
        return outputs

model = Model(dataset.num_node_features, dataset.num_classes)
opt = optim.SGD(model.parameters(), lr=0.5, weight_decay=0.01)


# 3. learner
learner = Learner(model, opt, masked_cross_entropy, data, metrics=[masked_accuracy])

# 4. fit
learner.fit(100)

# 5. test
learner.test(test_data)

# 6. predict
pred = learner.predict(dataset[0])
print(pred.size())

# 7. plot
learner.recorder.plot_metrics()
plt.show()