text stringlengths 1 93.6k |
|---|
import logging
|
import os
|
import sys
|
import time
|
script_start = time.time()
|
def infer_gnn(tr_data, val_data, te_data, tr_inds, val_inds, te_inds, args, data_config):
|
#set device
|
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
#define a model config dictionary and wandb logging at the same time
|
wandb.init(
|
mode="disabled" if args.testing else "online",
|
project="your_proj_name",
|
config={
|
"epochs": args.n_epochs,
|
"batch_size": args.batch_size,
|
"model": args.model,
|
"data": args.data,
|
"num_neighbors": args.num_neighs,
|
"lr": extract_param("lr", args),
|
"n_hidden": extract_param("n_hidden", args),
|
"n_gnn_layers": extract_param("n_gnn_layers", args),
|
"loss": "ce",
|
"w_ce1": extract_param("w_ce1", args),
|
"w_ce2": extract_param("w_ce2", args),
|
"dropout": extract_param("dropout", args),
|
"final_dropout": extract_param("final_dropout", args),
|
"n_heads": extract_param("n_heads", args) if args.model == 'gat' else None
|
}
|
)
|
config = wandb.config
|
#set the transform if ego ids should be used
|
if args.ego:
|
transform = AddEgoIds()
|
else:
|
transform = None
|
#add the unique ids to later find the seed edges
|
add_arange_ids([tr_data, val_data, te_data])
|
tr_loader, val_loader, te_loader = get_loaders(tr_data, val_data, te_data, tr_inds, val_inds, te_inds, transform, args)
|
#get the model
|
sample_batch = next(iter(tr_loader))
|
model = get_model(sample_batch, config, args)
|
if args.reverse_mp:
|
model = to_hetero(model, te_data.metadata(), aggr='mean')
|
if not (args.avg_tps or args.finetune):
|
command = " ".join(sys.argv)
|
name = ""
|
name = '-'.join(name.split('-')[3:])
|
args.unique_name = name
|
logging.info("=> loading model checkpoint")
|
checkpoint = torch.load(f'{data_config["paths"]["model_to_load"]}/checkpoint_{args.unique_name}.tar')
|
start_epoch = checkpoint['epoch']
|
model.load_state_dict(checkpoint['model_state_dict'])
|
model.to(device)
|
logging.info("=> loaded checkpoint (epoch {})".format(start_epoch))
|
if not args.reverse_mp:
|
te_f1, te_prec, te_rec = evaluate_homo(te_loader, te_inds, model, te_data, device, args, precrec=True)
|
else:
|
te_f1, te_prec, te_rec = evaluate_hetero(te_loader, te_inds, model, te_data, device, args, precrec=True)
|
wandb.finish()
|
# <FILESEP>
|
import torch
|
import torch.nn as nn
|
import torch.nn.functional as F
|
from torch.optim import SGD
|
from torch.autograd import Variable
|
from torch.nn.parameter import Parameter
|
from sklearn.metrics.cluster import normalized_mutual_info_score as nmi_score
|
from sklearn.metrics import adjusted_rand_score as ari_score
|
from sklearn.cluster import KMeans
|
from sklearn.decomposition import PCA
|
from utils.util import cluster_acc, Identity, AverageMeter, seed_torch, str2bool
|
from utils import ramps
|
from data.imagenetloader import ImageNetLoader30
|
from models.resnet import resnet18
|
from modules.module import feat2prob, target_distribution
|
import torchvision.models as models
|
from tqdm import tqdm
|
import numpy as np
|
import warnings
|
import os
|
warnings.filterwarnings("ignore", category=UserWarning)
|
def init_prob_kmeans(model, eval_loader, args):
|
torch.manual_seed(1)
|
model = model.to(device)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.