示例#1
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("--model_dir", type=str, help="path to the model directories")
    parser.add_argument("--reps", type=int, default=10, help="Number of eval repetitions")
    parser.add_argument("--steps", type=int, default=150, help="Number of steps in each walk")
    parser.add_argument("--seed", type=int, default=0, help="the random seed for torch and numpy")
    parser.add_argument("--split", type=str, default='test', choices={'test', 'val'}, help="split to evaluate on")
    parser.add_argument("--batch_size", type=int, default=50, help="Batch size used for testing")
    args = parser.parse_args()
    torch.manual_seed(args.seed)
    np.random.seed(args.seed)

    _, val_graphs, test_graphs = load_split_data()
    iter = CRaWlLoader(test_graphs if args.split == 'test' else val_graphs, batch_size=args.batch_size, num_workers=8)

    mean_list, std_list = [], []
    model_list = sorted(list(glob(args.model_dir)))
    for model_dir in model_list:
        print(f'Evaluating {model_dir}...')
        model = CRaWl.load(model_dir)
        mean, std = test(model, iter, repeats=args.reps, steps=args.steps)

        mean_list.append(mean)
        std_list.append(std)

    print(f'Mean Score {np.mean(mean_list):.5f} (+-{np.std(mean_list):.5f} CMD) (+-{np.mean(std_list):.5f} IMD)')
示例#2
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("--config",
                        type=str,
                        default='configs/MNIST/default.json',
                        help="path to config file")
    parser.add_argument("--name",
                        type=str,
                        default='0',
                        help="path to config file")
    parser.add_argument("--gpu",
                        type=int,
                        default=0,
                        help="id of gpu to be used for training")
    parser.add_argument("--seed",
                        type=int,
                        default=0,
                        help="the random seed for torch and numpy")
    args = parser.parse_args()
    torch.manual_seed(args.seed)
    np.random.seed(args.seed)

    device = torch.device(
        f"cuda:{args.gpu}" if torch.cuda.is_available() else "cpu")
    print(f"Using device: {device}")

    with open(args.config, 'r') as f:
        config = json.load(f)

    model_dir = f'models/MNIST/{config["name"]}/{args.name}'

    train_graphs, val_graphs, _ = load_split_data()
    train_iter = CRaWlLoader(train_graphs,
                             batch_size=config['batch_size'],
                             num_workers=8,
                             shuffle=True)
    val_iter = CRaWlLoader(val_graphs, batch_size=100, num_workers=8)

    model = CRaWl(model_dir,
                  config,
                  num_node_feat,
                  num_edge_feat,
                  num_classes,
                  loss=CrossEntropyLoss())
    model.save()
    train(model, train_iter, val_iter, device=device)
示例#3
0
                        type=int,
                        default=0,
                        help="the random seed for torch and numpy")
    args = parser.parse_args()
    torch.manual_seed(args.seed)
    np.random.seed(args.seed)

    device = torch.device(
        f"cuda:{args.gpu}" if torch.cuda.is_available() else "cpu")
    print(f"Using device: {device}")

    with open(args.config, 'r') as f:
        config = json.load(f)

    model_dir = f'models/{args.data}/{config["name"]}/{args.name}'

    num_node_feat, num_edge_feat, num_classes = NODE_FEAT[
        args.data], EDGE_FEAT[args.data], OUT_DIM[args.data]

    train_iter, val_iter, _ = get_split_data(args.data, args.split_dir, config,
                                             args.fold)

    model = CRaWl(model_dir,
                  config,
                  num_node_feat,
                  num_edge_feat,
                  num_classes,
                  loss=CrossEntropyLoss)
    model.save()
    train(model, train_iter, val_iter)
示例#4
0
    parser.add_argument("--name",
                        type=str,
                        default='0',
                        help="name of the model")
    parser.add_argument("--gpu",
                        type=int,
                        default=0,
                        help="id of gpu to be used for training")
    parser.add_argument("--seed",
                        type=int,
                        default=0,
                        help="the random seed for torch and numpy")
    args = parser.parse_args()
    torch.manual_seed(args.seed)
    np.random.seed(args.seed)

    device = torch.device(
        f"cuda:{args.gpu}" if torch.cuda.is_available() else "cpu")
    print(f"Using device: {device}")

    with open(args.config, 'r') as f:
        config = json.load(f)

    model_dir = f'models/ZINC/{config["name"]}/{args.name}'

    train_iter, val_iter = load_split_data(config)

    model = CRaWl(model_dir, config, num_node_feat, num_edge_feat, num_classes,
                  L1Loss())
    model.save()
    train_regression(model, train_iter, val_iter)
示例#5
0
    num_edge_feat = BondEncoder.dim()

    print('Loading Graphs...')

    if os.path.exists(PCKL_PATH):
        out_dim, train_graphs, valid_graphs, _ = torch.load(PCKL_PATH)
    else:
        out_dim, train_graphs, valid_graphs, test_graphs = load_graphs(
            ogb_data_name)
        os.makedirs('data/OGB', exist_ok=True)
        torch.save((out_dim, train_graphs, valid_graphs, test_graphs),
                   PCKL_PATH)

    train_iter = CRaWlLoader(train_graphs,
                             batch_size=config['batch_size'],
                             shuffle=True,
                             num_workers=10)
    valid_iter = CRaWlLoader(valid_graphs, batch_size=150, num_workers=10)

    model = CRaWl(model_dir,
                  config,
                  num_node_feat,
                  num_edge_feat,
                  out_dim,
                  node_feat_enc=AtomEncoder,
                  edge_feat_enc=BondEncoder,
                  loss=CrossEntropyLoss())

    print('Training...')
    train(model, train_iter, valid_iter)
示例#6
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("--config",
                        type=str,
                        default='configs/CSL/default.json',
                        help="path to config file")
    parser.add_argument("--seed",
                        type=int,
                        default=0,
                        help="the random seed for torch and numpy")
    parser.add_argument("--steps",
                        type=int,
                        default=150,
                        help="Number of steps in each walk")
    parser.add_argument("--reps",
                        type=int,
                        default=10,
                        help="Number of eval repetitions")
    parser.add_argument(
        "--use_lap_feat",
        action='store_true',
        default=False,
        help="Whether or not to use the Laplacian positional encodings")
    parser.add_argument(
        "--train",
        action='store_true',
        default=False,
        help=
        "Train new models. If not set, pre-trained models will be evaluated on the test data"
    )
    args = parser.parse_args()
    torch.manual_seed(args.seed)
    np.random.seed(args.seed)

    num_node_feat = 20 if args.use_lap_feat else 1
    num_edge_feat = 1
    num_classes = 10

    with open(args.config, 'r') as f:
        config = json.load(f)

    mean_list, std_list = [], []
    for f in range(5):
        train_iter, val_iter, test_iter = load_split_data(
            config, fold=f, use_lap_feat=args.use_lap_feat)

        model_dir = f'models/CSL/{config["name"]}/{f}'
        if args.train:
            model = CRaWl(model_dir,
                          config,
                          num_node_feat,
                          num_edge_feat,
                          num_classes,
                          loss=CrossEntropyLoss())
            train(model, train_iter, val_iter)
        else:
            model = CRaWl.load(model_dir)

        mean, std = test(model, test_iter, repeats=args.reps, steps=args.steps)

        mean_list.append(mean)
        std_list.append(std)

    print(
        f'Mean Test Score {np.mean(mean_list):.5f} (+-{np.std(mean_list):.5f}), Mean STD {np.mean(std_list):.5f}'
    )
示例#7
0
                        choices={'test', 'val'},
                        help="split to evaluate on")
    args = parser.parse_args()
    torch.manual_seed(args.seed)
    np.random.seed(args.seed)

    device = torch.device(f"cuda:0" if torch.cuda.is_available() else "cpu")
    print(f"Using device: {device}")

    print('Loading Graphs...')

    data = ZINC(DATA_PATH,
                subset=True,
                split=args.split,
                transform=feat_transform,
                pre_transform=preproc)
    iter = CRaWlLoader(data, batch_size=50, num_workers=4)

    mean_list, std_list = [], []
    model_list = sorted(list(glob(args.model_dir)))
    for model_dir in model_list:
        print(f'Evaluating {model_dir}...')
        model = CRaWl.load(model_dir)
        mean, std = test(model, iter, repeats=args.reps, steps=args.steps)

        mean_list.append(mean)
        std_list.append(std)

    print(
        f'Mean Score {np.mean(mean_list):.5f} (+-{np.std(mean_list):.5f} CMD) (+-{np.mean(std_list):.5f} IMD)'
    )