Exemplo n.º 1
0
        dataset[0].nodes.data['test_mask']].numpy()
    accs = []

    model_hp, decoder_hp = get_encoder_decoder_hp(args.model)

    for seed in tqdm(range(args.repeat)):

        solver = AutoNodeClassifier(
            feature_module=None,
            graph_models=(args.model, ),
            ensemble_module=None,
            max_evals=1,
            hpo_module='random',
            trainer_hp_space=fixed(
                **{
                    "max_epoch": args.epoch,
                    "early_stopping_round": args.epoch + 1,
                    "lr": args.lr,
                    "weight_decay": args.weight_decay,
                }),
            model_hp_spaces=[{
                "encoder": fixed(**model_hp),
                "decoder": fixed(**decoder_hp)
            }])

        solver.fit(dataset, evaluation_method=['acc'], seed=seed)
        output = solver.predict(dataset)
        acc = (output == label).astype('float').mean()
        accs.append(acc)
    print('{:.4f} ~ {:.4f}'.format(np.mean(accs), np.std(accs)))
Exemplo n.º 2
0
import os
os.environ["AUTOGL_BACKEND"] = "dgl"

from autogl.datasets import build_dataset_from_name
from autogl.solver import AutoNodeClassifier
from autogl.module.train import NodeClassificationFullTrainer
from autogl.backend import DependentBackend

key = "y" if DependentBackend.is_pyg() else "label"

cora = build_dataset_from_name("cora")

solver = AutoNodeClassifier(graph_models=("gin", ),
                            default_trainer=NodeClassificationFullTrainer(
                                decoder=None,
                                init=False,
                                max_epoch=200,
                                early_stopping_round=201,
                                lr=0.01,
                                weight_decay=0.0,
                            ),
                            hpo_module=None,
                            device="auto")

solver.fit(cora, evaluation_method=["acc"])
result = solver.predict(cora)
print((result == cora[0].nodes.data[key][
    cora[0].nodes.data["test_mask"]].cpu().numpy()).astype('float').mean())