repo stringlengths 1 99 | file stringlengths 13 215 | code stringlengths 12 59.2M | file_length int64 12 59.2M | avg_line_length float64 3.82 1.48M | max_line_length int64 12 2.51M | extension_type stringclasses 1
value |
|---|---|---|---|---|---|---|
pytorch-boat | pytorch-boat-main/BOAT-Swin/lr_scheduler.py | # --------------------------------------------------------
# Swin Transformer
# Copyright (c) 2021 Microsoft
# Licensed under The MIT License [see LICENSE for details]
# Written by Ze Liu
# --------------------------------------------------------
import torch
from timm.scheduler.cosine_lr import CosineLRScheduler
from... | 3,547 | 33.446602 | 105 | py |
pytorch-boat | pytorch-boat-main/BOAT-Swin/utils.py | # --------------------------------------------------------
# Swin Transformer
# Copyright (c) 2021 Microsoft
# Licensed under The MIT License [see LICENSE for details]
# Written by Ze Liu
# --------------------------------------------------------
import os
import torch
import torch.distributed as dist
try:
# noin... | 8,012 | 42.786885 | 117 | py |
pytorch-boat | pytorch-boat-main/BOAT-Swin/optimizer.py | # --------------------------------------------------------
# Swin Transformer
# Copyright (c) 2021 Microsoft
# Licensed under The MIT License [see LICENSE for details]
# Written by Ze Liu
# --------------------------------------------------------
from torch import optim as optim
def build_optimizer(config, model):
... | 2,013 | 33.724138 | 111 | py |
pytorch-boat | pytorch-boat-main/BOAT-Swin/models/boat_swin_transformer.py | # --------------------------------------------------------
# Swin Transformer
# Copyright (c) 2021 Microsoft
# Licensed under The MIT License [see LICENSE for details]
# Written by Ze Liu
# --------------------------------------------------------
import torch
import torch.nn as nn
import torch.utils.checkpoint as chec... | 30,671 | 41.074074 | 161 | py |
pytorch-boat | pytorch-boat-main/BOAT-Swin/models/swin_mlp.py | # --------------------------------------------------------
# Swin Transformer
# Copyright (c) 2021 Microsoft
# Licensed under The MIT License [see LICENSE for details]
# Written by Ze Liu
# --------------------------------------------------------
import torch
import torch.nn as nn
import torch.nn.functional as F
impor... | 18,508 | 38.464819 | 118 | py |
pytorch-boat | pytorch-boat-main/BOAT-Swin/models/swin_transformer.py | # --------------------------------------------------------
# Swin Transformer
# Copyright (c) 2021 Microsoft
# Licensed under The MIT License [see LICENSE for details]
# Written by Ze Liu
# --------------------------------------------------------
import torch
import torch.nn as nn
import torch.utils.checkpoint as chec... | 24,234 | 40.356655 | 119 | py |
pytorch-boat | pytorch-boat-main/BOAT-Swin/data/samplers.py | # --------------------------------------------------------
# Swin Transformer
# Copyright (c) 2021 Microsoft
# Licensed under The MIT License [see LICENSE for details]
# Written by Ze Liu
# --------------------------------------------------------
import torch
class SubsetRandomSampler(torch.utils.data.Sampler):
... | 781 | 25.066667 | 84 | py |
pytorch-boat | pytorch-boat-main/BOAT-Swin/data/build.py | # --------------------------------------------------------
# Swin Transformer
# Copyright (c) 2021 Microsoft
# Licensed under The MIT License [see LICENSE for details]
# Written by Ze Liu
# --------------------------------------------------------
import os
import torch
import numpy as np
import torch.distributed as di... | 5,877 | 37.927152 | 113 | py |
pytorch-boat | pytorch-boat-main/BOAT-Swin/data/cached_image_folder.py | # --------------------------------------------------------
# Swin Transformer
# Copyright (c) 2021 Microsoft
# Licensed under The MIT License [see LICENSE for details]
# Written by Ze Liu
# --------------------------------------------------------
import io
import os
import time
import torch.distributed as dist
import ... | 9,026 | 34.679842 | 115 | py |
ehrdiff | ehrdiff-main/diffusion_util.py | # -----------------------------------
# Code adapted from:
# https://github.com/lucidrains/denoising-diffusion-pytorch
# -----------------------------------
import math
import torch
import torch.nn as nn
import torch.nn.functional as F
from einops import rearrange, reduce
def exists(val):
return val is not None... | 6,942 | 27.809129 | 132 | py |
ehrdiff | ehrdiff-main/train_util.py | import os
import time
import random
import logging
import numpy as np
from scipy.stats import pearsonr
import matplotlib.pyplot as plt
import torch
from torch.utils.data import DataLoader
from transformers import get_cosine_schedule_with_warmup
from diffusion_util import LinearModel, Diffusion
def set_seed(seed=34... | 6,141 | 36.680982 | 119 | py |
ehrdiff | ehrdiff-main/gen_dat.py | from tqdm import tqdm
import torch
import numpy as np
from diffusion_util import LinearModel, Diffusion
device = torch.device('cuda:0')
dm = LinearModel(z_dim=1782, time_dim=384, unit_dims=[1024, 384, 384, 384, 1024])
dm.load_state_dict(torch.load("weight/model.pt"))
dm.to(device)
diffusion = Diffusion(
... | 1,016 | 26.486486 | 81 | py |
Text-Classification-Models-Pytorch | Text-Classification-Models-Pytorch-master/Model_TextCNN/utils.py | # utils.py
import torch
from torchtext import data
from torchtext.vocab import Vectors
import spacy
import pandas as pd
import numpy as np
from sklearn.metrics import accuracy_score
class Dataset(object):
def __init__(self, config):
self.config = config
self.train_iterator = None
self.test... | 4,498 | 37.452991 | 110 | py |
Text-Classification-Models-Pytorch | Text-Classification-Models-Pytorch-master/Model_TextCNN/model.py | # model.py
import torch
from torch import nn
import numpy as np
from utils import *
class TextCNN(nn.Module):
def __init__(self, config, vocab_size, word_embeddings):
super(TextCNN, self).__init__()
self.config = config
# Embedding Layer
self.embeddings = nn.Embedding(voca... | 4,215 | 39.932039 | 137 | py |
Text-Classification-Models-Pytorch | Text-Classification-Models-Pytorch-master/Model_TextCNN/train.py | # train.py
from utils import *
from model import *
from config import Config
import sys
import torch.optim as optim
from torch import nn
import torch
if __name__=='__main__':
config = Config()
train_file = '../data/ag_news.train'
if len(sys.argv) > 2:
train_file = sys.argv[1]
test_file = '../d... | 1,720 | 32.096154 | 98 | py |
Text-Classification-Models-Pytorch | Text-Classification-Models-Pytorch-master/Model_TextCNN/old_code/model.py | # model.py
import torch
from torch import nn
from torch import Tensor
from torch.autograd import Variable
import numpy as np
from sklearn.metrics import accuracy_score
class CNNText(nn.Module):
def __init__(self, config):
super(CNNText, self).__init__()
self.config = config
# Conv... | 4,642 | 40.088496 | 107 | py |
Text-Classification-Models-Pytorch | Text-Classification-Models-Pytorch-master/Model_TextCNN/old_code/train.py | # train.py
from utils import *
from config import Config
from sklearn.model_selection import train_test_split
import numpy as np
from tqdm import tqdm
import sys
import torch.optim as optim
from torch import nn, Tensor
from torch.autograd import Variable
import torch
from sklearn.metrics import accuracy_score
def get... | 3,445 | 36.868132 | 150 | py |
Text-Classification-Models-Pytorch | Text-Classification-Models-Pytorch-master/Model_Seq2Seq_Attention/utils.py | # utils.py
import torch
from torchtext import data
from torchtext.vocab import Vectors
import spacy
import pandas as pd
import numpy as np
from sklearn.metrics import accuracy_score
class Dataset(object):
def __init__(self, config):
self.config = config
self.train_iterator = None
self.test... | 4,492 | 37.076271 | 110 | py |
Text-Classification-Models-Pytorch | Text-Classification-Models-Pytorch-master/Model_Seq2Seq_Attention/model.py | # model.py
import torch
from torch import nn
import numpy as np
from torch.nn import functional as F
from utils import *
class Seq2SeqAttention(nn.Module):
def __init__(self, config, vocab_size, word_embeddings):
super(Seq2SeqAttention, self).__init__()
self.config = config
# Embe... | 5,529 | 42.203125 | 139 | py |
Text-Classification-Models-Pytorch | Text-Classification-Models-Pytorch-master/Model_Seq2Seq_Attention/train.py | # train.py
from utils import *
from model import *
from config import Config
import sys
import torch.optim as optim
from torch import nn
import torch
if __name__=='__main__':
config = Config()
train_file = '../data/ag_news.train'
if len(sys.argv) > 2:
train_file = sys.argv[1]
test_file = '../d... | 1,729 | 32.269231 | 98 | py |
Text-Classification-Models-Pytorch | Text-Classification-Models-Pytorch-master/Model_CharCNN/utils.py | # utils.py
import torch
from torchtext import data
import pandas as pd
import numpy as np
from sklearn.metrics import accuracy_score
def get_embedding_matrix(vocab_chars):
# one hot embedding plus all-zero vector
vocabulary_size = len(vocab_chars)
onehot_matrix = np.eye(vocabulary_size, vocabulary_size)
... | 4,545 | 37.525424 | 103 | py |
Text-Classification-Models-Pytorch | Text-Classification-Models-Pytorch-master/Model_CharCNN/model.py | # model.py
import torch
from torch import nn
import numpy as np
from utils import *
class CharCNN(nn.Module):
def __init__(self, config, vocab_size, embeddings):
super(CharCNN, self).__init__()
self.config = config
embed_size = vocab_size
# Embedding Layer
self.emb... | 5,019 | 40.147541 | 117 | py |
Text-Classification-Models-Pytorch | Text-Classification-Models-Pytorch-master/Model_CharCNN/train.py | # train.py
from utils import *
from model import *
from config import Config
import sys
import torch
import torch.optim as optim
from torch import nn
if __name__=='__main__':
config = Config()
train_file = '../data/ag_news.train'
if len(sys.argv) > 2:
train_file = sys.argv[1]
test_file = '../d... | 1,665 | 32.32 | 98 | py |
Text-Classification-Models-Pytorch | Text-Classification-Models-Pytorch-master/Model_CharCNN/without_torchtext/utils.py | # utils.py
import pandas as pd
import numpy as np
import torch
from torch.utils.data import Dataset
from torch.utils import data
from torch.utils.data import DataLoader
from torch.autograd import Variable
from sklearn.metrics import accuracy_score
# Used part of code to read the dataset from: https://github.com/1991v... | 3,657 | 37.505263 | 128 | py |
Text-Classification-Models-Pytorch | Text-Classification-Models-Pytorch-master/Model_CharCNN/without_torchtext/model.py | # model.py
import torch
from torch import nn
import numpy as np
from torch.autograd import Variable
from utils import *
class CharCNN(nn.Module):
def __init__(self, config):
super(CharCNN, self).__init__()
self.config = config
# This stackoverflow thread explains how conv1d works
... | 5,218 | 39.773438 | 117 | py |
Text-Classification-Models-Pytorch | Text-Classification-Models-Pytorch-master/Model_CharCNN/without_torchtext/train.py | # train.py
from utils import *
from model import *
from config import Config
import sys
import torch
import torch.optim as optim
from torch import nn
if __name__=='__main__':
config = Config()
train_file = '../data/ag_news.train'
if len(sys.argv) > 2:
train_file = sys.argv[1]
test_file = '../d... | 1,605 | 31.77551 | 94 | py |
Text-Classification-Models-Pytorch | Text-Classification-Models-Pytorch-master/Model_fastText/utils.py | # utils.py
import torch
from torchtext import data
from torchtext.vocab import Vectors
import spacy
import pandas as pd
import numpy as np
from sklearn.metrics import accuracy_score
class Dataset(object):
def __init__(self, config):
self.config = config
self.train_iterator = None
self.test... | 4,462 | 37.145299 | 97 | py |
Text-Classification-Models-Pytorch | Text-Classification-Models-Pytorch-master/Model_fastText/model.py | # model.py
import torch
from torch import nn
import numpy as np
from utils import *
class fastText(nn.Module):
def __init__(self, config, vocab_size, word_embeddings):
super(fastText, self).__init__()
self.config = config
# Embedding Layer
self.embeddings = nn.Embedding(vo... | 2,709 | 33.74359 | 98 | py |
Text-Classification-Models-Pytorch | Text-Classification-Models-Pytorch-master/Model_fastText/train.py | # train.py
from utils import *
from model import *
from config import Config
import numpy as np
import sys
import torch.optim as optim
from torch import nn
import torch
if __name__=='__main__':
config = Config()
train_file = '../data/ag_news.train'
if len(sys.argv) > 2:
train_file = sys.argv[1]
... | 1,740 | 31.849057 | 98 | py |
Text-Classification-Models-Pytorch | Text-Classification-Models-Pytorch-master/Model_fastText/old_code/model.py | # model.py
import torch
from torch import nn
from torch import Tensor
from torch.autograd import Variable
import numpy as np
from sklearn.metrics import accuracy_score
class fastText(nn.Module):
def __init__(self, config):
super(fastText, self).__init__()
self.config = config
# Hi... | 2,569 | 32.815789 | 82 | py |
Text-Classification-Models-Pytorch | Text-Classification-Models-Pytorch-master/Model_fastText/old_code/train.py | # train.py
from utils import *
from config import Config
from sklearn.model_selection import train_test_split
import numpy as np
from tqdm import tqdm
import sys
import torch.optim as optim
from torch import nn, Tensor
from torch.autograd import Variable
import torch
from sklearn.metrics import accuracy_score
def get... | 3,314 | 36.247191 | 108 | py |
Text-Classification-Models-Pytorch | Text-Classification-Models-Pytorch-master/Model_RCNN/utils.py | # utils.py
import torch
from torchtext import data
from torchtext.vocab import Vectors
import spacy
import pandas as pd
import numpy as np
from sklearn.metrics import accuracy_score
class Dataset(object):
def __init__(self, config):
self.config = config
self.train_iterator = None
self.test... | 4,498 | 37.452991 | 110 | py |
Text-Classification-Models-Pytorch | Text-Classification-Models-Pytorch-master/Model_RCNN/model.py | # model.py
import torch
from torch import nn
import numpy as np
from torch.nn import functional as F
from utils import *
class RCNN(nn.Module):
def __init__(self, config, vocab_size, word_embeddings):
super(RCNN, self).__init__()
self.config = config
# Embedding Layer
self... | 4,267 | 35.793103 | 98 | py |
Text-Classification-Models-Pytorch | Text-Classification-Models-Pytorch-master/Model_RCNN/train.py | # train.py
from utils import *
from model import *
from config import Config
import sys
import torch.optim as optim
from torch import nn
import torch
if __name__=='__main__':
config = Config()
train_file = '../data/ag_news.train'
if len(sys.argv) > 2:
train_file = sys.argv[1]
test_file = '../d... | 1,717 | 32.038462 | 98 | py |
Text-Classification-Models-Pytorch | Text-Classification-Models-Pytorch-master/Model_Transformer/utils.py | # utils.py
import torch
from torchtext import data
import spacy
import pandas as pd
import numpy as np
from sklearn.metrics import accuracy_score
class Dataset(object):
def __init__(self, config):
self.config = config
self.train_iterator = None
self.test_iterator = None
self.val_it... | 4,255 | 36.663717 | 110 | py |
Text-Classification-Models-Pytorch | Text-Classification-Models-Pytorch-master/Model_Transformer/model.py | # Model.py
import torch
import torch.nn as nn
from copy import deepcopy
from train_utils import Embeddings,PositionalEncoding
from attention import MultiHeadedAttention
from encoder import EncoderLayer, Encoder
from feed_forward import PositionwiseFeedForward
import numpy as np
from utils import *
class Transformer(n... | 3,390 | 35.858696 | 124 | py |
Text-Classification-Models-Pytorch | Text-Classification-Models-Pytorch-master/Model_Transformer/encoder.py | # encoder.py
from torch import nn
from train_utils import clones
from sublayer import LayerNorm, SublayerOutput
class Encoder(nn.Module):
'''
Transformer Encoder
It is a stack of N layers.
'''
def __init__(self, layer, N):
super(Encoder, self).__init__()
self.layers = clones(l... | 1,248 | 30.225 | 104 | py |
Text-Classification-Models-Pytorch | Text-Classification-Models-Pytorch-master/Model_Transformer/feed_forward.py | # feed_forward.py
from torch import nn
import torch.nn.functional as F
class PositionwiseFeedForward(nn.Module):
"Positionwise feed-forward network."
def __init__(self, d_model, d_ff, dropout=0.1):
super(PositionwiseFeedForward, self).__init__()
self.w_1 = nn.Linear(d_model, d_ff)
self... | 515 | 31.25 | 58 | py |
Text-Classification-Models-Pytorch | Text-Classification-Models-Pytorch-master/Model_Transformer/sublayer.py | # sublayer.py
import torch
from torch import nn
class LayerNorm(nn.Module):
"Construct a layer normalization module."
def __init__(self, features, eps=1e-6):
super(LayerNorm, self).__init__()
self.a_2 = nn.Parameter(torch.ones(features))
self.b_2 = nn.Parameter(torch.zeros(features))
... | 950 | 29.677419 | 71 | py |
Text-Classification-Models-Pytorch | Text-Classification-Models-Pytorch-master/Model_Transformer/train_utils.py | # train_utils.py
import torch
from torch import nn
from torch.autograd import Variable
import copy
import math
def clones(module, N):
"Produce N identical layers."
return nn.ModuleList([copy.deepcopy(module) for _ in range(N)])
class Embeddings(nn.Module):
'''
Usual Embedding layer with weights multi... | 1,577 | 34.863636 | 129 | py |
Text-Classification-Models-Pytorch | Text-Classification-Models-Pytorch-master/Model_Transformer/attention.py | # attention.py
import torch
from torch import nn
import math
import torch.nn.functional as F
from train_utils import clones
def attention(query, key, value, mask=None, dropout=None):
"Implementation of Scaled dot product attention"
d_k = query.size(-1)
scores = torch.matmul(query, key.transpose(-2, -1)) /... | 1,915 | 35.846154 | 76 | py |
Text-Classification-Models-Pytorch | Text-Classification-Models-Pytorch-master/Model_Transformer/train.py | # train.py
from utils import *
from model import *
from config import Config
import sys
import torch.optim as optim
from torch import nn
import torch
if __name__=='__main__':
config = Config()
train_file = '../data/ag_news.train'
if len(sys.argv) > 2:
train_file = sys.argv[1]
test_file = '../d... | 1,640 | 31.82 | 98 | py |
Text-Classification-Models-Pytorch | Text-Classification-Models-Pytorch-master/Model_TextRNN/utils.py | # utils.py
import torch
from torchtext import data
from torchtext.vocab import Vectors
import spacy
import pandas as pd
import numpy as np
from sklearn.metrics import accuracy_score
class Dataset(object):
def __init__(self, config):
self.config = config
self.train_iterator = None
self.test... | 4,498 | 37.452991 | 110 | py |
Text-Classification-Models-Pytorch | Text-Classification-Models-Pytorch-master/Model_TextRNN/model.py | # model.py
import torch
from torch import nn
import numpy as np
from utils import *
class TextRNN(nn.Module):
def __init__(self, config, vocab_size, word_embeddings):
super(TextRNN, self).__init__()
self.config = config
# Embedding Layer
self.embeddings = nn.Embedding(voca... | 3,586 | 37.569892 | 115 | py |
Text-Classification-Models-Pytorch | Text-Classification-Models-Pytorch-master/Model_TextRNN/train.py | # train.py
from utils import *
from model import *
from config import Config
import sys
import torch.optim as optim
from torch import nn
import torch
if __name__=='__main__':
config = Config()
train_file = '../data/ag_news.train'
if len(sys.argv) > 2:
train_file = sys.argv[1]
test_file = '../d... | 1,720 | 32.096154 | 98 | py |
CppDNN-develop | CppDNN-develop/example/keras_simple/simple.py | from keras import models
from keras import layers
from numpy import array
mnistfile = open('mnist_example', 'r')
mnistdata = mnistfile.read()
mnistdata = mnistdata.splitlines()[0].split(' ')
mnistdataf = []
for m in mnistdata:
mnistdataf.append(float(m))
mnistdata = array(mnistdataf)
mnistdata = mnistdata.reshape(... | 788 | 27.178571 | 50 | py |
CppDNN-develop | CppDNN-develop/script/DecodeKerasModel.py | import sys
from keras import models
if len(sys.argv) < 3:
print('usage: python DecodeKerasModel.py input output')
exit(1)
input = sys.argv[1]
output = sys.argv[2]
print(input)
outputFile = open(output, 'w')
model = models.load_model(input)
weights_list = model.get_weights()
print("############################... | 1,171 | 30.675676 | 79 | py |
benchmarking-gnns-pyg | benchmarking-gnns-pyg-master/main_arxiv_node_classification.py |
"""
IMPORTING LIBS
"""
import dgl
import numpy as np
import os
import socket
import time
import random
import glob
import argparse, json
import pickle
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
from torch.utils.data import DataLoader
from torch_geometric.d... | 19,431 | 41.060606 | 202 | py |
benchmarking-gnns-pyg | benchmarking-gnns-pyg-master/test.py | # -*- coding:utf-8 -*-
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch
import pickle
import torch.utils.data
import time
import os
import numpy as np
import csv
import dgl
from scipy import sparse as sp
import numpy as np
# # coding=gbk
# from tqdm import trange
# from random import... | 5,463 | 34.712418 | 145 | py |
benchmarking-gnns-pyg | benchmarking-gnns-pyg-master/main_Planetoid_node_classification.py |
"""
IMPORTING LIBS
"""
import dgl
import numpy as np
import os
import socket
import time
import random
import glob
import argparse, json
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
from torch.utils.data import DataLoader
from tensorboardX import SummaryWri... | 21,251 | 43 | 188 | py |
benchmarking-gnns-pyg | benchmarking-gnns-pyg-master/main_ogb_node_classification.py |
"""
IMPORTING LIBS
"""
import dgl
import numpy as np
import os
import socket
import time
import random
import glob
import argparse, json
import pickle
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
from torch.utils.data import DataLoader
from torch_geometric.d... | 20,051 | 41.303797 | 202 | py |
benchmarking-gnns-pyg | benchmarking-gnns-pyg-master/main_SBMs_node_classification.py |
"""
IMPORTING LIBS
"""
import dgl
import numpy as np
import os
import socket
import time
import random
import glob
import argparse, json
import pickle
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
from torch.utils.data import DataLoader
from torch_geometric.d... | 19,999 | 41.643923 | 226 | py |
benchmarking-gnns-pyg | benchmarking-gnns-pyg-master/nets/ogb_node_classification/gat_net.py | import torch
import torch.nn as nn
import torch.nn.functional as F
import dgl
from torch_geometric.typing import OptPairTensor
"""
GAT: Graph Attention Network
Graph Attention Networks (Veličković et al., ICLR 2018)
https://arxiv.org/abs/1710.10903
"""
from layers.gat_layer import GATLayer
from layers.mlp... | 3,492 | 38.247191 | 120 | py |
benchmarking-gnns-pyg | benchmarking-gnns-pyg-master/nets/ogb_node_classification/graphsage_net.py | import torch
import torch.nn as nn
import torch.nn.functional as F
import dgl
"""
GraphSAGE:
William L. Hamilton, Rex Ying, Jure Leskovec, Inductive Representation Learning on Large Graphs (NeurIPS 2017)
https://cs.stanford.edu/people/jure/pubs/graphsage-nips17.pdf
"""
from layers.graphsage_layer import... | 5,368 | 35.52381 | 122 | py |
benchmarking-gnns-pyg | benchmarking-gnns-pyg-master/nets/ogb_node_classification/gin_net.py | import torch
import torch.nn as nn
import torch.nn.functional as F
import dgl
from dgl.nn.pytorch.glob import SumPooling, AvgPooling, MaxPooling
"""
GIN: Graph Isomorphism Networks
HOW POWERFUL ARE GRAPH NEURAL NETWORKS? (Keyulu Xu, Weihua Hu, Jure Leskovec and Stefanie Jegelka, ICLR 2019)
https://arxiv.o... | 5,771 | 35.531646 | 113 | py |
benchmarking-gnns-pyg | benchmarking-gnns-pyg-master/nets/ogb_node_classification/gcn_net.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from torch_geometric.nn import GCNConv
import dgl
import numpy as np
"""
GCN: Graph Convolutional Networks
Thomas N. Kipf, Max Welling, Semi-Supervised Classification with Graph Convolutional Networks (ICLR 2017)
http://arxiv.org/abs/1609.0... | 3,608 | 33.701923 | 110 | py |
benchmarking-gnns-pyg | benchmarking-gnns-pyg-master/nets/ogb_node_classification/gated_gcn_net.py | import torch
import torch.nn as nn
import torch.nn.functional as F
import dgl
import numpy as np
"""
ResGatedGCN: Residual Gated Graph ConvNets
An Experimental Study of Neural Networks for Variable Graphs (Xavier Bresson and Thomas Laurent, ICLR 2018)
https://arxiv.org/pdf/1711.07553v2.pdf
"""
from layers... | 8,653 | 37.807175 | 122 | py |
benchmarking-gnns-pyg | benchmarking-gnns-pyg-master/nets/ogb_node_classification/mlp_net.py | import torch
import torch.nn as nn
import torch.nn.functional as F
import dgl
from layers.mlp_readout_layer import MLPReadout
class MLPNet(nn.Module):
def __init__(self, net_params):
super().__init__()
in_dim_node = net_params['in_dim'] # node_dim (feat is an integer)
hidden_dim = net_... | 4,176 | 29.268116 | 93 | py |
benchmarking-gnns-pyg | benchmarking-gnns-pyg-master/nets/ogb_node_classification/mo_net.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from torch_scatter import scatter_add
import dgl
import numpy as np
"""
GMM: Gaussian Mixture Model Convolution layer
Geometric Deep Learning on Graphs and Manifolds using Mixture Model CNNs (Federico Monti et al., CVPR 2017)
https://arxiv... | 6,647 | 39.785276 | 121 | py |
benchmarking-gnns-pyg | benchmarking-gnns-pyg-master/nets/SBMs_node_classification/gat_net.py | import torch
import torch.nn as nn
import torch.nn.functional as F
import dgl
from torch_geometric.typing import OptPairTensor
"""
GAT: Graph Attention Network
Graph Attention Networks (Veličković et al., ICLR 2018)
https://arxiv.org/abs/1710.10903
"""
from layers.gat_layer import GATLayer
from layers.mlp... | 5,639 | 35.862745 | 120 | py |
benchmarking-gnns-pyg | benchmarking-gnns-pyg-master/nets/SBMs_node_classification/ring_gnn_net.py | import torch
import torch.nn as nn
import torch.nn.functional as F
import dgl
import time
"""
Ring-GNN
On the equivalence between graph isomorphism testing and function approximation with GNNs (Chen et al, 2019)
https://arxiv.org/pdf/1905.12560v1.pdf
"""
from layers.ring_gnn_equiv_layer import RingGNNEqui... | 3,202 | 38.060976 | 141 | py |
benchmarking-gnns-pyg | benchmarking-gnns-pyg-master/nets/SBMs_node_classification/three_wl_gnn_net.py | import torch
import torch.nn as nn
import torch.nn.functional as F
import dgl
import time
"""
3WLGNN / ThreeWLGNN
Provably Powerful Graph Networks (Maron et al., 2019)
https://papers.nips.cc/paper/8488-provably-powerful-graph-networks.pdf
CODE adapted from https://github.com/hadarser/ProvablyPowe... | 4,050 | 36.859813 | 118 | py |
benchmarking-gnns-pyg | benchmarking-gnns-pyg-master/nets/SBMs_node_classification/graphsage_net.py | import torch
import torch.nn as nn
import torch.nn.functional as F
import dgl
"""
GraphSAGE:
William L. Hamilton, Rex Ying, Jure Leskovec, Inductive Representation Learning on Large Graphs (NeurIPS 2017)
https://cs.stanford.edu/people/jure/pubs/graphsage-nips17.pdf
"""
from layers.graphsage_layer import... | 6,149 | 36.048193 | 122 | py |
benchmarking-gnns-pyg | benchmarking-gnns-pyg-master/nets/SBMs_node_classification/gin_net.py | import torch
import torch.nn as nn
import torch.nn.functional as F
import dgl
from dgl.nn.pytorch.glob import SumPooling, AvgPooling, MaxPooling
"""
GIN: Graph Isomorphism Networks
HOW POWERFUL ARE GRAPH NEURAL NETWORKS? (Keyulu Xu, Weihua Hu, Jure Leskovec and Stefanie Jegelka, ICLR 2019)
https://arxiv.o... | 6,582 | 36.19209 | 113 | py |
benchmarking-gnns-pyg | benchmarking-gnns-pyg-master/nets/SBMs_node_classification/gcn_net.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from torch_geometric.nn import GCNConv
import dgl
import numpy as np
"""
GCN: Graph Convolutional Networks
Thomas N. Kipf, Max Welling, Semi-Supervised Classification with Graph Convolutional Networks (ICLR 2017)
http://arxiv.org/abs/1609.0... | 5,901 | 34.769697 | 110 | py |
benchmarking-gnns-pyg | benchmarking-gnns-pyg-master/nets/SBMs_node_classification/gated_gcn_net.py | import torch
import torch.nn as nn
import torch.nn.functional as F
import dgl
import numpy as np
"""
ResGatedGCN: Residual Gated Graph ConvNets
An Experimental Study of Neural Networks for Variable Graphs (Xavier Bresson and Thomas Laurent, ICLR 2018)
https://arxiv.org/pdf/1711.07553v2.pdf
"""
from layers... | 9,626 | 37.818548 | 122 | py |
benchmarking-gnns-pyg | benchmarking-gnns-pyg-master/nets/SBMs_node_classification/mlp_net.py | import torch
import torch.nn as nn
import torch.nn.functional as F
import dgl
from layers.mlp_readout_layer import MLPReadout
class MLPNet(nn.Module):
def __init__(self, net_params):
super().__init__()
in_dim_node = net_params['in_dim'] # node_dim (feat is an integer)
hidden_dim = net_... | 4,619 | 29.8 | 91 | py |
benchmarking-gnns-pyg | benchmarking-gnns-pyg-master/nets/SBMs_node_classification/mo_net.py | import torch
import torch.nn as nn
import torch.nn.functional as F
# from torch_scatter import scatter_add
# from num_nodes import maybe_num_nodes
import dgl
from torch_geometric.nn.conv import MessagePassing
import numpy as np
import torch.nn as nn
from torch import Tensor
# from torch_geometric.utils import degree
fr... | 7,669 | 40.236559 | 121 | py |
benchmarking-gnns-pyg | benchmarking-gnns-pyg-master/nets/Planetoid_node_classification/gat_net.py | import torch
import torch.nn as nn
import torch.nn.functional as F
import dgl
from torch_geometric.typing import OptPairTensor
"""
GAT: Graph Attention Network
Graph Attention Networks (Veličković et al., ICLR 2018)
https://arxiv.org/abs/1710.10903
"""
from layers.gat_layer import GATLayer
from layers.mlp... | 4,653 | 34.257576 | 120 | py |
benchmarking-gnns-pyg | benchmarking-gnns-pyg-master/nets/Planetoid_node_classification/graphsage_net.py | import torch
import torch.nn as nn
import torch.nn.functional as F
import dgl
"""
GraphSAGE:
William L. Hamilton, Rex Ying, Jure Leskovec, Inductive Representation Learning on Large Graphs (NeurIPS 2017)
https://cs.stanford.edu/people/jure/pubs/graphsage-nips17.pdf
"""
from layers.graphsage_layer import... | 5,141 | 35.211268 | 122 | py |
benchmarking-gnns-pyg | benchmarking-gnns-pyg-master/nets/Planetoid_node_classification/gin_net.py | import torch
import torch.nn as nn
import torch.nn.functional as F
import dgl
from dgl.nn.pytorch.glob import SumPooling, AvgPooling, MaxPooling
"""
GIN: Graph Isomorphism Networks
HOW POWERFUL ARE GRAPH NEURAL NETWORKS? (Keyulu Xu, Weihua Hu, Jure Leskovec and Stefanie Jegelka, ICLR 2019)
https://arxiv.o... | 5,612 | 35.448052 | 113 | py |
benchmarking-gnns-pyg | benchmarking-gnns-pyg-master/nets/Planetoid_node_classification/gcn_net.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from torch_geometric.nn import GCNConv
import dgl
import numpy as np
"""
GCN: Graph Convolutional Networks
Thomas N. Kipf, Max Welling, Semi-Supervised Classification with Graph Convolutional Networks (ICLR 2017)
http://arxiv.org/abs/1609.0... | 5,125 | 33.635135 | 110 | py |
benchmarking-gnns-pyg | benchmarking-gnns-pyg-master/nets/Planetoid_node_classification/gated_gcn_net.py | import torch
import torch.nn as nn
import torch.nn.functional as F
import dgl
import numpy as np
"""
ResGatedGCN: Residual Gated Graph ConvNets
An Experimental Study of Neural Networks for Variable Graphs (Xavier Bresson and Thomas Laurent, ICLR 2018)
https://arxiv.org/pdf/1711.07553v2.pdf
"""
from layers... | 8,352 | 37.493088 | 122 | py |
benchmarking-gnns-pyg | benchmarking-gnns-pyg-master/nets/Planetoid_node_classification/mlp_net.py | import torch
import torch.nn as nn
import torch.nn.functional as F
import dgl
from layers.mlp_readout_layer import MLPReadout
class MLPNet(nn.Module):
def __init__(self, net_params):
super().__init__()
in_dim_node = net_params['in_dim'] # node_dim (feat is an integer)
hidden_dim = net_... | 3,772 | 27.583333 | 93 | py |
benchmarking-gnns-pyg | benchmarking-gnns-pyg-master/nets/Planetoid_node_classification/mo_net.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from torch_scatter import scatter_add
import dgl
import numpy as np
"""
GMM: Gaussian Mixture Model Convolution layer
Geometric Deep Learning on Graphs and Manifolds using Mixture Model CNNs (Federico Monti et al., CVPR 2017)
https://arxiv... | 6,420 | 39.639241 | 121 | py |
benchmarking-gnns-pyg | benchmarking-gnns-pyg-master/layers/graphsage_layer.py | import torch
import torch.nn as nn
import torch.nn.functional as F
import dgl.function as fn
from dgl.nn.pytorch import SAGEConv
"""
GraphSAGE:
William L. Hamilton, Rex Ying, Jure Leskovec, Inductive Representation Learning on Large Graphs (NeurIPS 2017)
https://cs.stanford.edu/people/jure/pubs/graphsage... | 10,938 | 29.386111 | 114 | py |
benchmarking-gnns-pyg | benchmarking-gnns-pyg-master/layers/mlp_readout_layer.py | import torch
import torch.nn as nn
import torch.nn.functional as F
"""
MLP Layer used after graph vector representation
"""
class MLPReadout(nn.Module):
def __init__(self, input_dim, output_dim, L=2): #L=nb_hidden_layers
super().__init__()
list_FC_layers = [ nn.Linear( input_dim//2**l , input... | 1,026 | 26.756757 | 109 | py |
benchmarking-gnns-pyg | benchmarking-gnns-pyg-master/layers/gated_gcn_layer.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from torch import Tensor
from torch_geometric.typing import OptTensor
from torch_scatter import scatter
from torch_geometric.nn.conv import MessagePassing
"""
ResGatedGCN: Residual Gated Graph ConvNets
An Experimental Study of Neural Networks f... | 10,484 | 35.40625 | 170 | py |
benchmarking-gnns-pyg | benchmarking-gnns-pyg-master/layers/gat_layer.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from dgl.nn.pytorch import GATConv
"""
GAT: Graph Attention Network
Graph Attention Networks (Veličković et al., ICLR 2018)
https://arxiv.org/abs/1710.10903
"""
class GATLayer(nn.Module):
"""
Parameters
----------
in_dim :... | 10,303 | 29.850299 | 107 | py |
benchmarking-gnns-pyg | benchmarking-gnns-pyg-master/layers/gin_layer.py | import torch
import torch.nn as nn
import torch.nn.functional as F
import dgl.function as fn
"""
GIN: Graph Isomorphism Networks
HOW POWERFUL ARE GRAPH NEURAL NETWORKS? (Keyulu Xu, Weihua Hu, Jure Leskovec and Stefanie Jegelka, ICLR 2019)
https://arxiv.org/pdf/1810.00826.pdf
"""
class GINLayer(nn.Module):... | 4,598 | 30.9375 | 113 | py |
benchmarking-gnns-pyg | benchmarking-gnns-pyg-master/layers/gmm_layer.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.nn import init
import dgl.function as fn
"""
GMM: Gaussian Mixture Model Convolution layer
Geometric Deep Learning on Graphs and Manifolds using Mixture Model CNNs (Federico Monti et al., CVPR 2017)
https://arxiv.org/pdf/1611.084... | 3,680 | 31.289474 | 111 | py |
benchmarking-gnns-pyg | benchmarking-gnns-pyg-master/layers/gcn_layer.py | import torch
import torch.nn as nn
import torch.nn.functional as F
import dgl.function as fn
from dgl.nn.pytorch import GraphConv
"""
GCN: Graph Convolutional Networks
Thomas N. Kipf, Max Welling, Semi-Supervised Classification with Graph Convolutional Networks (ICLR 2017)
http://arxiv.org/abs/1609.02907
... | 2,561 | 29.86747 | 109 | py |
benchmarking-gnns-pyg | benchmarking-gnns-pyg-master/layers/ring_gnn_equiv_layer.py | import torch
import torch.nn as nn
import torch.nn.functional as F
"""
Ring-GNN equi 2 to 2 layer file
On the equivalence between graph isomorphism testing and function approximation with GNNs (Chen et al, 2019)
https://arxiv.org/pdf/1905.12560v1.pdf
CODE ADPATED FROM https://github.com/leichen2018/Ri... | 8,076 | 39.385 | 139 | py |
benchmarking-gnns-pyg | benchmarking-gnns-pyg-master/layers/three_wl_gnn_layers.py | import torch
import torch.nn as nn
import torch.nn.functional as F
"""
Layers used for
3WLGNN
Provably Powerful Graph Networks (Maron et al., 2019)
https://papers.nips.cc/paper/8488-provably-powerful-graph-networks.pdf
CODE adapted from https://github.com/hadarser/ProvablyPowerfulGraphNetwork... | 4,983 | 31.154839 | 108 | py |
benchmarking-gnns-pyg | benchmarking-gnns-pyg-master/train/train_Planetoid_node_classification.py | """
Utility functions for training one epoch
and evaluating one epoch
"""
import torch
import torch.nn as nn
import math
from train.metrics import accuracy_TU as accuracy
"""
For GCNs
"""
def train_epoch_sparse(model, optimizer, device, dataset, train_idx):
model.train()
epoch_loss = 0
epoch_... | 3,774 | 30.991525 | 89 | py |
benchmarking-gnns-pyg | benchmarking-gnns-pyg-master/train/metrics.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from sklearn.metrics import confusion_matrix
from sklearn.metrics import f1_score
import numpy as np
def MAE(scores, targets):
MAE = F.l1_loss(scores, targets)
MAE = MAE.detach().item()
return MAE
# it is the original one to calculate th... | 2,754 | 31.797619 | 135 | py |
benchmarking-gnns-pyg | benchmarking-gnns-pyg-master/train/train_ogb_node_classification.py | """
Utility functions for training one epoch
and evaluating one epoch
"""
import torch
import torch.nn as nn
import math
import dgl
from tqdm import tqdm
from train.metrics import accuracy_SBM as accuracy
from train.metrics import accuracy_ogb
from ogb.nodeproppred import Evaluator
"""
For GCNs
"""
def tr... | 11,004 | 35.440397 | 110 | py |
benchmarking-gnns-pyg | benchmarking-gnns-pyg-master/train/train_SBMs_node_classification.py | """
Utility functions for training one epoch
and evaluating one epoch
"""
import torch
import torch.nn as nn
import math
import dgl
from train.metrics import accuracy_SBM as accuracy
from train.metrics import accuracy_ogb
"""
For GCNs
"""
def train_epoch_sparse(model, optimizer, device, data_loader, epoc... | 7,186 | 38.489011 | 113 | py |
benchmarking-gnns-pyg | benchmarking-gnns-pyg-master/data/ogbn.py |
import time
import os
import pickle
import numpy as np
import os.path as osp
import dgl
import torch
from torch_scatter import scatter
from scipy import sparse as sp
import numpy as np
from tqdm import tqdm
from torch_geometric.data import InMemoryDataset
from torch_geometric.data import Data
from scipy.sparse import ... | 22,737 | 38.407279 | 140 | py |
benchmarking-gnns-pyg | benchmarking-gnns-pyg-master/data/molecules.py | import torch
import pickle
import torch.utils.data
import time
import os
import numpy as np
import csv
import dgl
from scipy import sparse as sp
import numpy as np
from torch_geometric.data import Data
from torch_geometric.data import InMemoryDataset
from tqdm import tqdm
# *NOTE
# The dataset pickle and index file... | 14,989 | 39.404313 | 130 | py |
benchmarking-gnns-pyg | benchmarking-gnns-pyg-master/data/node2vec_citeseer.py | import argparse
import torch
from torch_geometric.nn import Node2Vec
from torch_geometric.utils import to_undirected
import torch_geometric as pyg
from ogb.nodeproppred import PygNodePropPredDataset
import os.path as osp
def save_embedding(model):
torch.save(model.embedding.weight.data.cpu(), 'data/planetoid/embe... | 2,380 | 36.793651 | 89 | py |
benchmarking-gnns-pyg | benchmarking-gnns-pyg-master/data/SBMs.py |
import time
import os
import pickle
import numpy as np
import os.path as osp
import dgl
import torch
from ogb.utils.url import decide_download, download_url, extract_zip
from scipy import sparse as sp
import numpy as np
from tqdm import tqdm
from torch_geometric.data import InMemoryDataset
from torch_geometric.data im... | 14,591 | 37.70557 | 127 | py |
benchmarking-gnns-pyg | benchmarking-gnns-pyg-master/data/node2vec_proteins.py | import argparse
import torch
from torch_geometric.nn import Node2Vec
from ogb.nodeproppred import PygNodePropPredDataset
def save_embedding(model):
torch.save(model.embedding.weight.data.cpu(), 'ogbn/embedding_proteins.pt')
def main():
parser = argparse.ArgumentParser(description='OGBN-Proteins (Node2Vec)... | 2,096 | 34.542373 | 79 | py |
benchmarking-gnns-pyg | benchmarking-gnns-pyg-master/data/CSL.py | import numpy as np, time, pickle, random, csv
import torch
from torch.utils.data import DataLoader, Dataset
import os
import pickle
import numpy as np
import dgl
from sklearn.model_selection import StratifiedKFold, train_test_split
random.seed(42)
from scipy import sparse as sp
class DGLFormDataset(torch.utils.d... | 13,727 | 40.101796 | 128 | py |
benchmarking-gnns-pyg | benchmarking-gnns-pyg-master/data/node2vec-products.py | import argparse
import torch
from torch_geometric.nn import Node2Vec
from ogb.nodeproppred import PygNodePropPredDataset
def save_embedding(model):
torch.save(model.embedding.weight.data.cpu(), 'ogbn/embedding_products.pt')
def main():
parser = argparse.ArgumentParser(description='OGBN-Products (Node2Vec)... | 2,133 | 35.169492 | 79 | py |
benchmarking-gnns-pyg | benchmarking-gnns-pyg-master/data/planetoids.py | import torch
import pickle
import torch.utils.data
import time
import os
import numpy as np
from torch_geometric.utils import get_laplacian
import csv
from scipy import sparse as sp
import dgl
from dgl.data import TUDataset
from dgl.data import LegacyTUDataset
import torch_geometric as pyg
from scipy.sparse import csr_... | 13,158 | 43.60678 | 131 | py |
benchmarking-gnns-pyg | benchmarking-gnns-pyg-master/data/node2vec_arxiv.py | import argparse
import torch
from torch_geometric.nn import Node2Vec
from torch_geometric.utils import to_undirected
from ogb.nodeproppred import PygNodePropPredDataset
import os.path as osp
def save_embedding(model):
torch.save(model.embedding.weight.data.cpu(), 'ogbn/embedding_arxiv.pt')
def main():
pars... | 2,306 | 36.819672 | 81 | py |
benchmarking-gnns-pyg | benchmarking-gnns-pyg-master/data/molecules/prepare_molecules.py | #!/usr/bin/env python
# coding: utf-8
# # Notebook for preparing and saving MOLECULAR graphs
# In[1]:
import numpy as np
import torch
import pickle
import time
import os
from IPython import get_ipython
#get_ipython().run_line_magic('matplotlib', 'inline')
import matplotlib.pyplot as plt
# In[2]:
print(torch.__v... | 2,951 | 17.110429 | 116 | py |
SleePyCo | SleePyCo-main/train_mtcl.py | import os
import json
import argparse
import warnings
import torch
import torch.nn as nn
import torch.optim as optim
from torch.utils.data import DataLoader
from utils import *
from loader import EEGDataLoader
from models.main_model import MainModel
class OneFoldTrainer:
def __init__(self, args, fold, config):
... | 8,872 | 40.853774 | 170 | py |
SleePyCo | SleePyCo-main/test.py | import os
import json
import argparse
import warnings
import torch
import torch.nn as nn
from torch.utils.data import DataLoader
from utils import *
from loader import EEGDataLoader
from train_mtcl import OneFoldTrainer
from models.main_model import MainModel
class OneFoldEvaluator(OneFoldTrainer):
def __init__... | 3,233 | 34.933333 | 169 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.