def main(): args = ArgsInit().args if args.use_gpu: device = torch.device("cuda:" + str(args.device)) if torch.cuda.is_available() else torch.device("cpu") else: device = torch.device("cpu") dataset = OGBNDataset(dataset_name=args.dataset) args.num_tasks = dataset.num_tasks args.nf_path = dataset.extract_node_features(args.aggr) evaluator = Evaluator(args.dataset) valid_data_list = [] for i in range(args.num_evals): parts = dataset.random_partition_graph(dataset.total_no_of_nodes, cluster_number=args.valid_cluster_number) valid_data = dataset.generate_sub_graphs(parts, cluster_number=args.valid_cluster_number) valid_data_list.append(valid_data) model = DeeperGCN(args) model.load_state_dict(torch.load(args.model_load_path)['model_state_dict']) model.to(device) result = multi_evaluate(valid_data_list, dataset, model, evaluator, device) print(result) model.print_params(final=True)
def main(): args = ArgsInit().args if args.use_gpu: device = torch.device("cuda:" + str(args.device)) if torch.cuda.is_available( ) else torch.device("cpu") else: device = torch.device('cpu') dataset = PygGraphPropPredDataset(name=args.dataset) args.num_tasks = dataset.num_tasks print(args) if args.feature == 'full': pass elif args.feature == 'simple': print('using simple feature') # only retain the top two node/edge features dataset.data.x = dataset.data.x[:, :2] dataset.data.edge_attr = dataset.data.edge_attr[:, :2] split_idx = dataset.get_idx_split() evaluator = Evaluator(args.dataset) train_loader = DataLoader(dataset[split_idx["train"]], batch_size=args.batch_size, shuffle=False, num_workers=args.num_workers) valid_loader = DataLoader(dataset[split_idx["valid"]], batch_size=args.batch_size, shuffle=False, num_workers=args.num_workers) test_loader = DataLoader(dataset[split_idx["test"]], batch_size=args.batch_size, shuffle=False, num_workers=args.num_workers) model = DeeperGCN(args) model.load_state_dict(torch.load(args.model_load_path)['model_state_dict']) model.to(device) train_result = eval(model, device, train_loader, evaluator)[dataset.eval_metric] valid_result = eval(model, device, valid_loader, evaluator)[dataset.eval_metric] test_result = eval(model, device, test_loader, evaluator)[dataset.eval_metric] print({ 'Train': train_result, 'Validation': valid_result, 'Test': test_result }) model.print_params(final=True)
def main(): args = ArgsInit().args if args.use_gpu: device = torch.device("cuda:" + str(args.device)) if torch.cuda.is_available( ) else torch.device("cpu") else: device = torch.device('cpu') if args.not_extract_node_feature: dataset = PygGraphPropPredDataset(name=args.dataset, transform=add_zeros) else: extract_node_feature_func = partial(extract_node_feature, reduce=args.aggr) dataset = PygGraphPropPredDataset(name=args.dataset, transform=extract_node_feature_func) args.num_tasks = dataset.num_classes evaluator = Evaluator(args.dataset) split_idx = dataset.get_idx_split() train_loader = DataLoader(dataset[split_idx["train"]], batch_size=args.batch_size, shuffle=False, num_workers=args.num_workers) valid_loader = DataLoader(dataset[split_idx["valid"]], batch_size=args.batch_size, shuffle=False, num_workers=args.num_workers) test_loader = DataLoader(dataset[split_idx["test"]], batch_size=args.batch_size, shuffle=False, num_workers=args.num_workers) print(args) model = DeeperGCN(args) model.load_state_dict(torch.load(args.model_load_path)['model_state_dict']) model.to(device) train_accuracy = eval(model, device, train_loader, evaluator) valid_accuracy = eval(model, device, valid_loader, evaluator) test_accuracy = eval(model, device, test_loader, evaluator) print({ 'Train': train_accuracy, 'Validation': valid_accuracy, 'Test': test_accuracy }) model.print_params(final=True)
def main(): args = ArgsInit().args if args.use_gpu: device = torch.device("cuda:" + str(args.device)) if torch.cuda.is_available( ) else torch.device("cpu") else: device = torch.device('cpu') dataset = PygNodePropPredDataset(name=args.dataset) data = dataset[0] split_idx = dataset.get_idx_split() evaluator = Evaluator(args.dataset) x = data.x.to(device) y_true = data.y.to(device) edge_index = data.edge_index.to(device) edge_index = to_undirected(edge_index, data.num_nodes) if args.self_loop: edge_index = add_self_loops(edge_index, num_nodes=data.num_nodes)[0] args.in_channels = data.x.size(-1) args.num_tasks = dataset.num_classes print(args) model = DeeperGCN(args) model.load_state_dict(torch.load(args.model_load_path)['model_state_dict']) model.to(device) result = test(model, x, edge_index, y_true, split_idx, evaluator) train_accuracy, valid_accuracy, test_accuracy = result print({ 'Train': train_accuracy, 'Validation': valid_accuracy, 'Test': test_accuracy }) model.print_params(final=True)
def main(): args = ArgsInit().args if args.use_gpu: device = torch.device("cuda:" + str(args.device)) if torch.cuda.is_available( ) else torch.device("cpu") else: device = torch.device('cpu') dataset = PygLinkPropPredDataset(name=args.dataset) data = dataset[0] # Data(edge_index=[2, 2358104], edge_weight=[2358104, 1], edge_year=[2358104, 1], x=[235868, 128]) split_edge = dataset.get_edge_split() evaluator = Evaluator(args.dataset) x = data.x.to(device) edge_index = data.edge_index.to(device) args.in_channels = data.x.size(-1) args.num_tasks = 1 print(args) model = DeeperGCN(args).to(device) predictor = LinkPredictor(args).to(device) model.load_state_dict(torch.load(args.model_load_path)['model_state_dict']) model.to(device) predictor.load_state_dict( torch.load(args.predictor_load_path)['model_state_dict']) predictor.to(device) hits = ['Hits@10', 'Hits@50', 'Hits@100'] result = test(model, predictor, x, edge_index, split_edge, evaluator, args.batch_size) for k in hits: train_result, valid_result, test_result = result[k] print('{}--Train: {}, Validation: {}, Test: {}'.format( k, train_result, valid_result, test_result))
data3.pos = data3.x #plot_pointcloud(trg_mesh, "Target mesh") #plot_pointcloud(block1, "Source mesh") #plt.show() # We will learn to deform the source mesh by offsetting its vertices # The shape of the deform parameters is equal to the total number of vertices in src_mesh# #deform_verts = torch.full(src_mesh.verts_packed().shape, 0.0, device=device, requires_grad=True) #model = GCN() print(device) #TODO: more features gcn1 = DeeperGCN(3, 128, 3, 12) gcn1.to(device) gcn2 = DeeperGCN(128 + 3, 128, 3, 12) gcn2.to(device) gcn3 = DeeperGCN(128 + 3, 128, 3, 12) gcn3.to(device) # The optimizer optimizer = torch.optim.Adam(list(gcn1.parameters()) + list(gcn2.parameters()) + list(gcn3.parameters()), lr=0.0001) #optimizer = torch.optim.SGD([deform_verts], lr=1.0, momentum=0.9) # Number of optimization steps Niter = 5001
ax.set_title(title) ax.view_init(190, 30) plt.show() #plot_pointcloud(trg_mesh, "Target mesh") #plot_pointcloud(src_mesh, "Source mesh") plt.show() # We will learn to deform the source mesh by offsetting its vertices # The shape of the deform parameters is equal to the total number of vertices in src_mesh# #deform_verts = torch.full(block1.verts_packed().shape, 0.0, device=device, requires_grad=True) #model = GCN() #print(device) model = DeeperGCN(3, 128, 3, 5) model.to(device) # The optimizer optimizer = torch.optim.SGD(model.parameters(), lr=0.001, momentum=0.9) #optimizer = torch.optim.SGD([deform_verts], lr=0.2, momentum=0.9) # Number of optimization steps Niter = 3001 # Weight for the chamfer loss w_chamfer = 1.0 # Weight for mesh edge loss w_edge = 0.1 #1.0 # Weight for mesh normal consistency w_normal = 1.6e-4 #0.01 # Weight for mesh laplacian smoothing w_laplacian = 0.3 #0.1