default="../configs/nodeclf_ladies_reproduction.yml",
        help="configuration file to adopt",
    )
    argument_parser.add_argument("--seed", type=int, default=0, help="random seed")
    argument_parser.add_argument("--device", default=0, type=int, help="GPU device")

    arguments = argument_parser.parse_args()
    if torch.cuda.is_available():
        torch.cuda.set_device(arguments.device)
    seed = arguments.seed
    random.seed(seed)
    np.random.seed(seed)
    torch.manual_seed(seed)
    if torch.cuda.is_available():
        torch.cuda.manual_seed(seed)
        torch.backends.cudnn.deterministic = True
        torch.backends.cudnn.benchmark = False

    dataset = build_dataset_from_name(arguments.dataset)
    configs = yaml.load(
        open(arguments.configs, "r").read(),
        Loader=yaml.FullLoader
    )
    autoClassifier = AutoNodeClassifier.from_config(configs)
    # The running time is likely to exceed 1 hour when CiteSeer or Reddit dataset is adopted
    autoClassifier.fit(dataset, time_limit=24 * 3600, evaluation_method=[MicroF1])
    autoClassifier.get_leaderboard().show()
    predict_result = autoClassifier.predict_proba()
    res = autoClassifier.evaluate(metric=[MicroF1, 'acc'])
    print("Final Micro F1 {:.4f} Acc {:.4f}".format(res[0], res[1]))
Exemple #2
0
import os
os.environ["AUTOGL_BACKEND"] = "pyg"
import sys
sys.path.append('../')
from autogl.datasets import build_dataset_from_name
from autogl.solver import AutoNodeClassifier
from autogl.module.train import Acc
from autogl.solver.utils import set_seed
import argparse

if __name__ == '__main__':
    set_seed(202106)
    parser = argparse.ArgumentParser()
    parser.add_argument('--config', type=str, default='../configs/nodeclf_nas_gasso.yml')
    parser.add_argument('--dataset', choices=['cora', 'citeseer', 'pubmed'], default='citeseer', type=str)

    args = parser.parse_args()

    dataset = build_dataset_from_name(args.dataset)
    solver = AutoNodeClassifier.from_config(args.config)
    solver.fit(dataset)
    solver.get_leaderboard().show()
    print('acc on dataset', solver.evaluate())
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())
Exemple #4
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)))
Exemple #5
0
import autogl
from autogl.datasets import build_dataset_from_name
cora_dataset = build_dataset_from_name('cora', path='/home/qinyj/AGL/')

import torch
device = torch.device('cuda:5' if torch.cuda.is_available() else 'cpu')
#device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
from autogl.solver import AutoNodeClassifier
solver = AutoNodeClassifier(feature_module='deepgl',
                            graph_models=['gcn', 'gat'],
                            hpo_module='anneal',
                            ensemble_module='voting',
                            device=device)

solver.fit(cora_dataset, time_limit=3600)
solver.get_leaderboard().show()

from autogl.module.train import Acc
predicted = solver.predict_proba()
print(
    'Test accuracy: ',
    Acc.evaluate(
        predicted,
        cora_dataset.data.y[cora_dataset.data.test_mask].cpu().numpy()))