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 |
|---|---|---|---|---|---|---|
3D_STEP_Classification | 3D_STEP_Classification-main/MultiView_Classification/models/MVCNN.py | import numpy as np
import os
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.autograd import Variable
import torchvision.models as models
from .Model import Model
mean = Variable(torch.FloatTensor([0.485, 0.456, 0.406]), requires_grad=False).cuda()
std = Variable(torch.FloatTensor([0.229,... | 4,572 | 43.833333 | 118 | py |
3D_STEP_Classification | 3D_STEP_Classification-main/MultiView_Classification/models/Model.py | import torch
import torch.nn as nn
import os
import glob
class Model(nn.Module):
def __init__(self, name):
super(Model, self).__init__()
self.name = name
def save(self, path, epoch=0):
complete_path = os.path.join(path, self.name)
if not os.path.exists(complete_path):
... | 1,102 | 25.902439 | 86 | py |
3D_STEP_Classification | 3D_STEP_Classification-main/Graph_classification/GCN.py | import numpy as np
import torch.nn as nn
import torch.nn.functional as F
from torch_geometric.nn import GCNConv
import torch
class AttentionModule(torch.nn.Module):
"""
Attention Module to make a pass on graph.
"""
def __init__(self, dim):
super(AttentionModule, self).__init__()
self.se... | 24,497 | 44.450835 | 119 | py |
3D_STEP_Classification | 3D_STEP_Classification-main/Graph_classification/train_GCN.py | #! /usr/bin/env python
from GCN import *
from datetime import datetime
from utils.my_utils import *
from utils.util import *
import time
from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter
import os
import math
from train_utils import *
torch.manual_seed(124)
np.random.seed(124)
# Parameters
# =======... | 5,816 | 45.166667 | 195 | py |
3D_STEP_Classification | 3D_STEP_Classification-main/Graph_classification/train_utils.py | from sklearn import metrics
from sklearn.metrics import confusion_matrix
import numpy as np
import torch
import seaborn as sns
import matplotlib.pyplot as plt
def label_smoothing(true_labels: torch.Tensor, classes: int, smoothing=0.1):
"""
if smoothing == 0, it's one-hot method
if 0 < smoothing < 1, it's ... | 5,946 | 37.869281 | 131 | py |
3D_STEP_Classification | 3D_STEP_Classification-main/Graph_classification/utils/util.py | import os
import networkx as nx
import numpy as np
import random
import scipy.sparse as sp
from sklearn.model_selection import StratifiedKFold
"""Adapted from https://github.com/weihua916/powerful-gnns/blob/master/util.py"""
class S2VGraph(object):
def __init__(self, g, label, node_tags=None, node_features=None, ... | 8,984 | 32.778195 | 119 | py |
3D_STEP_Classification | 3D_STEP_Classification-main/PointNet_Classifiication/pointnet2_cls_ssg.py | import torch.nn as nn
import torch.nn.functional as F
from pointnet2_utils import PointNetSetAbstraction
class get_model(nn.Module):
def __init__(self,num_class,normal_channel=True):
super(get_model, self).__init__()
in_channel = 6 if normal_channel else 3
self.normal_channel = normal_chan... | 1,814 | 34.588235 | 139 | py |
3D_STEP_Classification | 3D_STEP_Classification-main/PointNet_Classifiication/pointnet2_utils.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from time import time
import numpy as np
def timeit(tag, t):
print("{}: {}s".format(tag, time() - t))
return time()
def pc_normalize(pc):
l = pc.shape[0]
centroid = np.mean(pc, axis=0)
pc = pc - centroid
m = np.max(np.sqrt(np.s... | 11,168 | 34.233438 | 104 | py |
3D_STEP_Classification | 3D_STEP_Classification-main/PointNet_Classifiication/pointnet2_cls_msg.py | import torch.nn as nn
import torch.nn.functional as F
from pointnet2_utils import PointNetSetAbstractionMsg, PointNetSetAbstraction
class get_model(nn.Module):
def __init__(self,num_class,normal_channel=True):
super(get_model, self).__init__()
in_channel = 3 if normal_channel else 0
self.n... | 1,797 | 33.576923 | 138 | py |
3D_STEP_Classification | 3D_STEP_Classification-main/PointNet_Classifiication/train_pointNet.py | import os
import sys
import torch
import numpy as np
import datetime
import logging
import provider
import importlib
import shutil
import argparse
from pathlib import Path
from tqdm import tqdm
from ModelNetDataLoader import ModelNetDataLoader
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
ROOT_DIR = BASE_DIR
s... | 8,887 | 37.812227 | 138 | py |
3D_STEP_Classification | 3D_STEP_Classification-main/PointNet_Classifiication/pointnet_cls.py | import torch.nn as nn
import torch.utils.data
import torch.nn.functional as F
from pointnet_utils import PointNetEncoder, feature_transform_reguliarzer
class get_model(nn.Module):
def __init__(self, k=40, normal_channel=True):
super(get_model, self).__init__()
if normal_channel:
channel... | 1,414 | 33.512195 | 94 | py |
3D_STEP_Classification | 3D_STEP_Classification-main/PointNet_Classifiication/ModelNetDataLoader.py | '''
@author: Xu Yan
@file: ModelNet.py
@time: 2021/3/19 15:51
'''
import os
import numpy as np
import warnings
import pickle
from tqdm import tqdm
from torch.utils.data import Dataset
warnings.filterwarnings('ignore')
def pc_normalize(pc):
centroid = np.mean(pc, axis=0)
pc = pc - centroid
m = np.max(np.... | 5,470 | 36.217687 | 121 | py |
How-to-0wn-NAS-in-Your-Spare-Time | How-to-0wn-NAS-in-Your-Spare-Time-master/reconstruct_malconv.py | """
Reconstruct the MalConv architecture from the Flush+Reload results
"""
# basic
import os
import json
import argparse
from math import ceil
from copy import deepcopy
from itertools import product
# externals (numpy, networkx, matplotlib)
import numpy as np
import networkx as nx
import matplotlib.pyplot as plt
... | 29,075 | 38.028188 | 100 | py |
chronological_probing | chronological_probing-main/code/prober.py | import os
from transformers import AutoTokenizer, AutoModel, pipeline
import torch
from tqdm import tqdm
import pickle
import numpy as np
from nltk.tokenize import WordPunctTokenizer
import pandas as pd
import json
import re
class Embeddings(object):
def __init__(self, device, tokenizer_path,
out... | 12,980 | 41.560656 | 139 | py |
secure-muda | secure-muda-master/feature-gen-code/main.py | """
Extract features from pre-trained networks.
The main procedures are finetune and extract features.
Finetune: Given an Imagenet pretrained model (such as ResNet50), finetune it on a dataset (we call it source)
Extractor: After fine-tune, extract features on the target domain using finetuned models on source
This cl... | 12,648 | 42.920139 | 143 | py |
secure-muda | secure-muda-master/feature-gen-code/backbone.py | import numpy as np
import torch
import torch.nn as nn
import torchvision
from torchvision import models
# convnet without the last layer
class AlexNetFc(nn.Module):
def __init__(self):
super(AlexNetFc, self).__init__()
model_alexnet = models.alexnet(pretrained=True)
self.features = model_a... | 5,961 | 29.418367 | 68 | py |
secure-muda | secure-muda-master/feature-gen-code/models.py | import torch
import torch.nn as nn
import backbone
class Network(nn.Module):
def __init__(self, base_net='alexnet', n_class=31):
super(Network, self).__init__()
self.n_class = n_class
self.base_network = backbone.network_dict[base_net]()
self.classifier_layer = nn.Linear(
... | 703 | 28.333333 | 61 | py |
secure-muda | secure-muda-master/feature-gen-code/data_load.py | from torchvision import datasets, transforms
from torch.utils.data import DataLoader, Subset
import torch
from PIL import Image
# This file works for RGB images.
def load_data(data_folder, domain_name, batch_size, phase='train', train_val_split=True, train_ratio=.8):
transform_dict = {
'train': transforms... | 6,811 | 45.027027 | 135 | py |
secure-muda | secure-muda-master/train_code/customlayers.py | import torch
import torch.nn as nn
import torch.nn.utils.weight_norm as weightNorm
from torchvision import models
# single domain classifier layer
class ClassifierLayer(nn.Module):
def __init__(self, input_dim, classes, dropout):
super(ClassifierLayer, self).__init__()
self.classes = classes
... | 2,318 | 30.337838 | 90 | py |
secure-muda | secure-muda-master/train_code/dataset.py | import os
import cv2
import torch
import random
import numpy as np
from tqdm import tqdm
from PIL import Image
import config as config
import matplotlib.pyplot as plt
from torchvision import transforms, utils
from torch.utils.data import Dataset, DataLoader
import pandas as pd
class FrozenDataset():
def __init__(... | 2,123 | 29.342857 | 100 | py |
secure-muda | secure-muda-master/train_code/config.py | import os
import shutil
import torch
import glob
import pdb
import numpy as np
from config_populate import data_settings
# While config is mostly unchanged throughout different runs, to avoid creating multiple config files for
# each problem, we select experiments using this auxiliary file
import exp_select as exp_sel... | 10,847 | 57.322581 | 194 | py |
secure-muda | secure-muda-master/train_code/net.py |
import torch.nn as nn
import torch
from customlayers import ClassifierLayer as C
from customlayers import BackBoneLayer as G
from customlayers import ForwardLayer as F
import config as config
class SingleSourceNet(nn.Module):
def __init__(self, settings):
super(SingleSourceNet, self).__init... | 1,464 | 34.731707 | 171 | py |
secure-muda | secure-muda-master/train_code/metrics.py | import torch
import torch.nn as nn
import matplotlib.pyplot as plt
import numpy as np
###########################################################------------------_SECTION LOSS--------------------###########################################################################
def Entropy(input_):
bs = input_.size(0)
... | 7,769 | 44.174419 | 188 | py |
secure-muda | secure-muda-master/train_code/gaussian_utils.py | import numpy as np
import metrics as metrics
from tqdm import tqdm
import torch
import time
from sklearn.mixture import GaussianMixture
def sample_from_gaussians(means, covs, n_samples, perm_res=True):
# Return samples from the num_classes gaussians trained on the source
N_CLASSES = len(n_samples)
Xs... | 4,208 | 38.336449 | 128 | py |
secure-muda | secure-muda-master/train_code/evaluate_model.py | import numpy as np
import config as config
import metrics as metrics
import gaussian_utils
from trainer import MultiSourceTrainer
from tqdm import tqdm
import torch
from torch.autograd import Variable
def get_individual_performance():
# Computes the target performance for source-only and post-adaptation models... | 18,668 | 44.645477 | 216 | py |
secure-muda | secure-muda-master/train_code/trainer.py | import numpy as np
import copy
import shutil
import os
import config as config
import metrics as metrics
from net import SingleSourceNet as smodel
from dataset import FeatureDataset, FrozenDataset
import gaussian_utils
from tqdm import tqdm
import torch
import torch.nn as nn
import torch.optim as optim
from torch.au... | 27,051 | 47.480287 | 187 | py |
sar_transformer | sar_transformer-main/test.py | # Code for testing on real SAR images
# Author: Malsha Perera
import argparse
import torch
import torchvision
from torch import nn
from torchvision.transforms import functional as F
import os
import numpy as np
import torch
from transform_main import TransSAR, TransSARV2, TransSARV3
import cv2
parser = argparse.Arg... | 1,872 | 18.925532 | 71 | py |
sar_transformer | sar_transformer-main/transform_main.py | import torch
import torch.nn as nn
import torch.nn.functional
import torch.nn.functional as F
from functools import partial
from arch.trans_basenetworks import *
import timm
from timm.models.layers import DropPath, to_2tuple, trunc_normal_
import types
import math
from abc import ABCMeta, abstractmethod
from mmcv.cnn ... | 55,366 | 39.50256 | 175 | py |
sar_transformer | sar_transformer-main/utils.py | import os
import numpy as np
import torch
from skimage import io,color
from PIL import Image
from torch.utils.data import Dataset
from torchvision import transforms as T
from torchvision.transforms import functional as F
from typing import Callable
import os
import cv2
import pandas as pd
from numbers import Number
... | 3,403 | 28.6 | 111 | py |
sar_transformer | sar_transformer-main/train.py | # Code for training TransSAR on synthetic images
# Author: Malsha Perera
import torch
import torch.nn as nn
import torch.optim as optim
from torch.optim import lr_scheduler
import numpy as np
import torchvision
from torchvision import datasets, models, transforms
import matplotlib.pyplot as plt
import time
import os
i... | 8,498 | 32.199219 | 93 | py |
sar_transformer | sar_transformer-main/arch/trans_basenetworks.py | import torch
import torch.nn as nn
import torch.nn.functional as F
import math
import torch
from torch import nn
from torch.nn import init
from torch.nn import functional as F
from torch.autograd import Function
from math import sqrt
import random
class ConvBlock(torch.nn.Module):
def __init__(self, input_size,... | 5,081 | 29.614458 | 126 | py |
PPOGAN | PPOGAN-master/unsupervised_text_generation/config.py | # -*- coding: utf-8 -*-
# @Author : William
# @Project : TextGAN-william
# @FileName : config.py
# @Time : Created at 2019-03-18
# @Blog : http://zhiweil.ml/
# @Description :
# Copyrights (C) 2018. All Rights Reserved.
import os
import re
import time
import torch
from torch.nn import fun... | 11,232 | 38.139373 | 138 | py |
PPOGAN | PPOGAN-master/unsupervised_text_generation/models/SentiGAN_D.py | # -*- coding: utf-8 -*-
# @Author : William
# @Project : TextGAN-william
# @FileName : SentiGAN_D.py
# @Time : Created at 2019-07-26
# @Blog : http://zhiweil.ml/
# @Description :
# Copyrights (C) 2018. All Rights Reserved.
import torch.nn as nn
from models.discriminator import CNNDisc... | 1,335 | 33.25641 | 116 | py |
PPOGAN | PPOGAN-master/unsupervised_text_generation/models/JSDGAN_G.py | # -*- coding: utf-8 -*-
# @Author : William
# @Project : TextGAN-william
# @FileName : JSDGAN_G.py
# @Time : Created at 2019/11/17
# @Blog : http://zhiweil.ml/
# @Description :
# Copyrights (C) 2018. All Rights Reserved.
import torch
import torch.nn.functional as F
from models.genera... | 2,889 | 37.533333 | 120 | py |
PPOGAN | PPOGAN-master/unsupervised_text_generation/models/SentiGAN_G.py | # -*- coding: utf-8 -*-
# @Author : William
# @Project : TextGAN-william
# @FileName : SentiGAN_G.py
# @Time : Created at 2019-07-26
# @Blog : http://zhiweil.ml/
# @Description :
# Copyrights (C) 2018. All Rights Reserved.
import torch
import torch.nn.functional as F
from models.gene... | 2,451 | 36.151515 | 127 | py |
PPOGAN | PPOGAN-master/unsupervised_text_generation/models/discriminator.py | # -*- coding: utf-8 -*-
# @Author : William
# @Project : TextGAN-william
# @FileName : config.py
# @Time : Created at 2019-03-18
# @Blog : http://zhiweil.ml/
# @Description :
# Copyrights (C) 2018. All Rights Reserved.
import math
import torch
import torch.autograd as autograd
import to... | 8,100 | 39.303483 | 121 | py |
PPOGAN | PPOGAN-master/unsupervised_text_generation/models/relational_rnn_general.py | import torch
import torch.nn.functional as F
from torch import nn
# this class largely follows the official sonnet implementation
# https://github.com/deepmind/sonnet/blob/master/sonnet/python/modules/relational_memory.py
class RelationalMemory(nn.Module):
"""
Constructs a `RelationalMemory` object.
Thi... | 15,604 | 41.753425 | 142 | py |
PPOGAN | PPOGAN-master/unsupervised_text_generation/models/LeakGAN_G.py | # -*- coding: utf-8 -*-
# @Author : William
# @Project : TextGAN-william
# @FileName : LeakGAN_G.py
# @Time : Created at 2019-04-25
# @Blog : http://zhiweil.ml/
# @Description :
# Copyrights (C) 2018. All Rights Reserved.
import math
import time
import torch
import torch.nn as nn
impor... | 16,609 | 41.372449 | 120 | py |
PPOGAN | PPOGAN-master/unsupervised_text_generation/models/RelGAN_G.py | # -*- coding: utf-8 -*-
# @Author : William
# @Project : TextGAN-william
# @FileName : RelGAN_G.py
# @Time : Created at 2019-04-25
# @Blog : http://zhiweil.ml/
# @Description :
# Copyrights (C) 2018. All Rights Reserved.
import torch
import torch.nn as nn
import torch.nn.functional as F... | 5,316 | 37.528986 | 120 | py |
PPOGAN | PPOGAN-master/unsupervised_text_generation/models/MaliGAN_G.py | # -*- coding: utf-8 -*-
# @Author : William
# @Project : TextGAN-william
# @FileName : MaliGAN_G.py
# @Time : Created at 2019/10/17
# @Blog : http://zhiweil.ml/
# @Description :
# Copyrights (C) 2018. All Rights Reserved.
import torch
import torch.nn.functional as F
from models.genera... | 1,450 | 34.390244 | 127 | py |
PPOGAN | PPOGAN-master/unsupervised_text_generation/models/generator.py | # -*- coding: utf-8 -*-
# @Author : William
# @Project : TextGAN-william
# @FileName : config.py
# @Time : Created at 2019-03-18
# @Blog : http://zhiweil.ml/
# @Description :
# Copyrights (C) 2018. All Rights Reserved.
import math
import torch
import torch.nn as nn
import config as cfg
... | 4,098 | 36.605505 | 108 | py |
PPOGAN | PPOGAN-master/unsupervised_text_generation/models/RelGAN_D.py | # -*- coding: utf-8 -*-
# @Author : William
# @Project : TextGAN-william
# @FileName : RelGAN_D.py
# @Time : Created at 2019-04-25
# @Blog : http://zhiweil.ml/
# @Description :
# Copyrights (C) 2018. All Rights Reserved.
import torch
import torch.nn as nn
import torch.nn.functional as ... | 2,425 | 37.507937 | 119 | py |
PPOGAN | PPOGAN-master/unsupervised_text_generation/models/SeqGAN_G.py | # -*- coding: utf-8 -*-
# @Author : William
# @Project : TextGAN-william
# @FileName : SeqGAN_G.py
# @Time : Created at 2019-04-25
# @Blog : http://zhiweil.ml/
# @Description :
# Copyrights (C) 2018. All Rights Reserved.
import torch
import torch.nn.functional as F
from models.generat... | 1,456 | 35.425 | 127 | py |
PPOGAN | PPOGAN-master/unsupervised_text_generation/metrics/clas_acc.py | # -*- coding: utf-8 -*-
# @Author : William
# @Project : TextGAN-william
# @FileName : clas_acc.py
# @Time : Created at 2019/12/4
# @Blog : http://zhiweil.ml/
# @Description :
# Copyrights (C) 2018. All Rights Reserved.
import torch
from metrics.basic import Metrics
class ACC(Metric... | 1,394 | 28.0625 | 85 | py |
PPOGAN | PPOGAN-master/unsupervised_text_generation/metrics/nll.py | # -*- coding: utf-8 -*-
# @Author : William
# @Project : TextGAN-william
# @FileName : nll.py
# @Time : Created at 2019-05-31
# @Blog : http://zhiweil.ml/
# @Description :
# Copyrights (C) 2018. All Rights Reserved.
import torch
import torch.nn as nn
import config as cfg
from metrics.... | 3,792 | 37.313131 | 114 | py |
PPOGAN | PPOGAN-master/unsupervised_text_generation/instructor/real_data/leakgan_instructor.py | # -*- coding: utf-8 -*-
# @Author : William
# @Project : TextGAN-william
# @FileName : leakgan_instructor.py
# @Time : Created at 2019-06-05
# @Blog : http://zhiweil.ml/
# @Description :
# Copyrights (C) 2018. All Rights Reserved.
import torch
import torch.optim as optim
import config... | 8,968 | 44.527919 | 114 | py |
PPOGAN | PPOGAN-master/unsupervised_text_generation/instructor/real_data/instructor.py | # -*- coding: utf-8 -*-
# @Author : William
# @Project : TextGAN-william
# @FileName : instructor.py
# @Time : Created at 2019-04-25
# @Blog : http://zhiweil.ml/
# @Description :
# Copyrights (C) 2018. All Rights Reserved.
import numpy as np
import torch
import torch.nn as nn
import c... | 11,155 | 40.626866 | 115 | py |
PPOGAN | PPOGAN-master/unsupervised_text_generation/instructor/real_data/relgan_instructor.py | # -*- coding: utf-8 -*-
# @Author : William
# @Project : TextGAN-william
# @FileName : relgan_instructor.py
# @Time : Created at 2019-04-25
# @Blog : http://zhiweil.ml/
# @Description :
# Copyrights (C) 2018. All Rights Reserved.
import torch
import torch.nn.functional as F
import torc... | 7,150 | 40.33526 | 115 | py |
PPOGAN | PPOGAN-master/unsupervised_text_generation/instructor/real_data/jsdgan_instructor.py | # -*- coding: utf-8 -*-
# @Author : William
# @Project : TextGAN-william
# @FileName : JSDGAN_instructor.py
# @Time : Created at 2019/11/25
# @Blog : http://zhiweil.ml/
# @Description :
# Copyrights (C) 2018. All Rights Reserved.
import torch
import torch.optim as optim
import config ... | 3,564 | 34.65 | 120 | py |
PPOGAN | PPOGAN-master/unsupervised_text_generation/instructor/real_data/maligan_instructor.py | # -*- coding: utf-8 -*-
# @Author : William
# @Project : TextGAN-william
# @FileName : maligan_instructor.py
# @Time : Created at 2019/11/29
# @Blog : http://zhiweil.ml/
# @Description :
# Copyrights (C) 2018. All Rights Reserved.
import torch
import torch.optim as optim
import confi... | 6,211 | 39.337662 | 119 | py |
PPOGAN | PPOGAN-master/unsupervised_text_generation/instructor/real_data/seqgan_instructor.py | # -*- coding: utf-8 -*-
# @Author : William
# @Project : TextGAN-william
# @FileName : seqgan_instructor.py
# @Time : Created at 2019-06-05
# @Blog : http://zhiweil.ml/
# @Description :
# Copyrights (C) 2018. All Rights Reserved.
import torch
import torch.optim as optim
import config ... | 5,817 | 40.557143 | 119 | py |
PPOGAN | PPOGAN-master/unsupervised_text_generation/instructor/real_data/trgan_instructor.py | # -*- coding: utf-8 -*-
# @Author : William
# @Project : TextGAN-william
# @FileName : relgan_instructor.py
# @Time : Created at 2019-04-25
# @Blog : http://zhiweil.ml/
# @Description :
# Copyrights (C) 2018. All Rights Reserved.
import torch
import torch.nn as nn
import torch.nn.functi... | 9,711 | 42.747748 | 145 | py |
PPOGAN | PPOGAN-master/unsupervised_text_generation/instructor/real_data/sentigan_instructor.py | # -*- coding: utf-8 -*-
# @Author : William
# @Project : TextGAN-william
# @FileName : sentigan_instructor.py
# @Time : Created at 2019-07-09
# @Blog : http://zhiweil.ml/
# @Description :
# Copyrights (C) 2018. All Rights Reserved.
import torch
import torch.optim as optim
import config... | 9,725 | 44.877358 | 120 | py |
PPOGAN | PPOGAN-master/unsupervised_text_generation/instructor/oracle_data/leakgan_instructor.py | # -*- coding: utf-8 -*-
# @Author : William
# @Project : TextGAN-william
# @FileName : leakgan_instructor.py
# @Time : Created at 2019-04-25
# @Blog : http://zhiweil.ml/
# @Description :
# Copyrights (C) 2018. All Rights Reserved.
import torch
import torch.optim as optim
import config... | 8,922 | 44.294416 | 114 | py |
PPOGAN | PPOGAN-master/unsupervised_text_generation/instructor/oracle_data/instructor.py | # -*- coding: utf-8 -*-
# @Author : William
# @Project : TextGAN-william
# @FileName : instructor.py
# @Time : Created at 2019-04-25
# @Blog : http://zhiweil.ml/
# @Description :
# Copyrights (C) 2018. All Rights Reserved.
import numpy as np
import os
import torch
import torch.nn as nn... | 9,609 | 39.041667 | 116 | py |
PPOGAN | PPOGAN-master/unsupervised_text_generation/instructor/oracle_data/relgan_instructor.py | # -*- coding: utf-8 -*-
# @Author : William
# @Project : TextGAN-william
# @FileName : relgan_instructor.py
# @Time : Created at 2019-04-25
# @Blog : http://zhiweil.ml/
# @Description :
# Copyrights (C) 2018. All Rights Reserved.
import torch
import torch.nn as nn
import torch.nn.functi... | 7,248 | 40.1875 | 119 | py |
PPOGAN | PPOGAN-master/unsupervised_text_generation/instructor/oracle_data/jsdgan_instructor.py | # -*- coding: utf-8 -*-
# @Author : William
# @Project : TextGAN-william
# @FileName : JSDGAN_instructor.py
# @Time : Created at 2019/11/16
# @Blog : http://zhiweil.ml/
# @Description :
# Copyrights (C) 2018. All Rights Reserved.
import os
import torch
import torch.optim as optim
impor... | 3,844 | 35.273585 | 120 | py |
PPOGAN | PPOGAN-master/unsupervised_text_generation/instructor/oracle_data/maligan_instructor.py | # -*- coding: utf-8 -*-
# @Author : William
# @Project : TextGAN-william
# @FileName : maligan_instructor.py
# @Time : Created at 2019/10/17
# @Blog : http://zhiweil.ml/
# @Description :
# Copyrights (C) 2018. All Rights Reserved.
import torch
import torch.optim as optim
import confi... | 6,497 | 40.388535 | 119 | py |
PPOGAN | PPOGAN-master/unsupervised_text_generation/instructor/oracle_data/seqgan_instructor.py | # -*- coding: utf-8 -*-
# @Author : William
# @Project : TextGAN-william
# @FileName : seqgan_instructor.py
# @Time : Created at 2019-04-25
# @Blog : http://zhiweil.ml/
# @Description :
# Copyrights (C) 2018. All Rights Reserved.
import torch
import torch.optim as optim
import config ... | 6,175 | 41.593103 | 119 | py |
PPOGAN | PPOGAN-master/unsupervised_text_generation/instructor/oracle_data/trgan_instructor.py | # -*- coding: utf-8 -*-
# @Author : William
# @Project : TextGAN-william
# @FileName : relgan_instructor.py
# @Time : Created at 2019-04-25
# @Blog : http://zhiweil.ml/
# @Description :
# Copyrights (C) 2018. All Rights Reserved.
import torch
import torch.nn as nn
import torch.nn.functi... | 9,786 | 43.085586 | 145 | py |
PPOGAN | PPOGAN-master/unsupervised_text_generation/instructor/oracle_data/sentigan_instructor.py | # -*- coding: utf-8 -*-
# @Author : William
# @Project : TextGAN-william
# @FileName : sentigan_instructor.py
# @Time : Created at 2019-07-26
# @Blog : http://zhiweil.ml/
# @Description :
# Copyrights (C) 2018. All Rights Reserved.
import os
import torch
import torch.optim as optim
im... | 9,006 | 43.589109 | 120 | py |
PPOGAN | PPOGAN-master/unsupervised_text_generation/utils/data_loader.py | # -*- coding: utf-8 -*-
# @Author : William
# @Project : TextGAN-william
# @FileName : data_loader.py
# @Time : Created at 2019-05-31
# @Blog : http://zhiweil.ml/
# @Description :
# Copyrights (C) 2018. All Rights Reserved.
import random
from torch.utils.data import Dataset, DataLoader... | 4,339 | 32.90625 | 100 | py |
PPOGAN | PPOGAN-master/unsupervised_text_generation/utils/data_utils.py | # -*- coding: utf-8 -*-
# @Author : William
# @Project : TextGAN-william
# @FileName : data_utils.py
# @Time : Created at 2019-03-16
# @Blog : http://zhiweil.ml/
# @Description :
# Copyrights (C) 2018. All Rights Reserved.
from time import strftime, localtime
import torch.nn as nn
fro... | 6,818 | 39.589286 | 110 | py |
PPOGAN | PPOGAN-master/unsupervised_text_generation/utils/cat_data_loader.py | # -*- coding: utf-8 -*-
# @Author : William
# @Project : TextGAN-william
# @FileName : cat_data_loader.py
# @Time : Created at 2019-05-31
# @Blog : http://zhiweil.ml/
# @Description :
# Copyrights (C) 2018. All Rights Reserved.
import random
from torch.utils.data import Dataset, DataLo... | 5,925 | 35.134146 | 100 | py |
PPOGAN | PPOGAN-master/unsupervised_text_generation/utils/text_process.py | # -*- coding: utf-8 -*-
# @Author : William
# @Project : TextGAN-william
# @FileName : text_process.py
# @Time : Created at 2019-05-14
# @Blog : http://zhiweil.ml/
# @Description :
# Copyrights (C) 2018. All Rights Reserved.
import nltk
import numpy as np
import os
import torch
import... | 12,120 | 33.240113 | 113 | py |
PPOGAN | PPOGAN-master/unsupervised_text_generation/utils/helpers.py | import logging
import sys
from time import strftime, gmtime
import numpy as np
import torch
import torch.nn as nn
from metrics.nll import NLL
from utils.data_loader import GenDataIter
from torch.nn import functional as F
class Signal:
"""Running signal to control training process"""
def __init__(self, signa... | 6,456 | 34.872222 | 101 | py |
PPOGAN | PPOGAN-master/unsupervised_text_generation/utils/rollout.py | # -*- coding: utf-8 -*-
# @Author : William
# @Project : TextGAN-william
# @FileName : rollout.py
# @Time : Created at 2019-03-15
# @Blog : http://zhiweil.ml/
# @Description :
# Copyrights (C) 2018. All Rights Reserved.
import copy
import torch
import torch.nn.functional as F
class R... | 7,763 | 36.873171 | 107 | py |
PPOGAN | PPOGAN-master/cifar10/main.py | from printlib import print_normal as print
import argparse
import os, sys
parser = argparse.ArgumentParser()
parser.add_argument('--output_dir', type=str, default="./",
help='GPUs to use.')
parser.add_argument('--snapshot_dir', type=str, default="./",
help='snapshot')
parser.add_... | 17,320 | 37.749441 | 133 | py |
PPOGAN | PPOGAN-master/cifar10/fid-score.py | #!/usr/bin/env python3
"""Calculates the Frechet Inception Distance (FID) to evalulate GANs
The FID metric calculates the distance between two distributions of images.
Typically, we have summary statistics (mean & covariance matrix) of one
of these distributions, while the 2nd distribution is given by a GAN.
When run... | 9,861 | 36.785441 | 79 | py |
PPOGAN | PPOGAN-master/cifar10/inception.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from torchvision import models
try:
from torchvision.models.utils import load_state_dict_from_url
except ImportError:
from torch.utils.model_zoo import load_url as load_state_dict_from_url
# Inception weights ported to Pytorch from
# http://do... | 11,625 | 36.503226 | 126 | py |
PPOGAN | PPOGAN-master/cifar10/utils.py | import torch
import torch.nn as nn
from torch.nn import functional as F
import torch.nn.parallel
import torch.backends.cudnn as cudnn
import torch.optim as optim
import torch.utils.data
import torchvision
from torch.utils.tensorboard import SummaryWriter
import torchvision.datasets as dset
import torchvision.transforms... | 8,919 | 38.821429 | 131 | py |
lsa-zsl | lsa-zsl-main/src/test.py | import random
from datetime import datetime
import torch.backends.cudnn as cudnn
import classifiers.classifier_images as classifier
import datasets.image_util as util
import networks.models as model
from utils import *
log_name = (
"logs/"
+ datetime.now().strftime("%Y-%m-%d %H:%M:%S")
+ "_"
+ opt.da... | 3,058 | 27.324074 | 87 | py |
lsa-zsl | lsa-zsl-main/src/train_images_inductive.py | import os
import random
from datetime import datetime
import loguru
import torch.backends.cudnn as cudnn
import torch.nn as nn
import torch.optim as optim
import classifiers.classifier_images as classifier
import datasets.image_util as util
import networks.models as model
from utils import *
log_name = (
"logs/"... | 11,148 | 34.848875 | 88 | py |
lsa-zsl | lsa-zsl-main/src/utils.py | from __future__ import print_function
import torch
import torch.autograd as autograd
import torch.nn as nn
from torch.autograd import Variable
from config_images import opt
def loss_fn(recon_x, x, mean, log_var):
BCE = torch.nn.functional.binary_cross_entropy(
recon_x + 1e-12, x.detach(), size_average=F... | 3,946 | 31.352459 | 81 | py |
lsa-zsl | lsa-zsl-main/src/train_images_transductive.py | import os
import random
from datetime import datetime
import loguru
import torch.backends.cudnn as cudnn
import torch.nn as nn
import torch.optim as optim
import classifiers.classifier_images as classifier
import datasets.image_util as util
import networks.models as model
from utils import *
log_name = (
"logs/"... | 13,577 | 36.821727 | 88 | py |
lsa-zsl | lsa-zsl-main/src/networks/models.py | import torch
import torch.nn as nn
def weights_init(m):
classname = m.__class__.__name__
if classname.find("Linear") != -1:
m.weight.data.normal_(0.0, 0.02)
m.bias.data.fill_(0)
elif classname.find("BatchNorm") != -1:
m.weight.data.normal_(1.0, 0.02)
m.bias.data.fill_(0)
... | 3,431 | 29.371681 | 69 | py |
lsa-zsl | lsa-zsl-main/src/datasets/image_util.py | import numpy as np
import scipy.io as sio
import torch
from sklearn import preprocessing
class Logger(object):
def __init__(self, filename):
self.filename = filename
f = open(self.filename + ".log", "a")
f.close()
def write(self, message):
f = open(self.filename + ".log", "a")... | 5,813 | 39.943662 | 88 | py |
lsa-zsl | lsa-zsl-main/src/classifiers/classifier_images.py | import copy
import pdb
import sys
import numpy as np
import torch
import torch.nn as nn
import torch.optim as optim
from sklearn.preprocessing import MinMaxScaler
from torch.autograd import Variable
import datasets.image_util as util
class CLASSIFIER:
def __init__(
self,
_train_X,
_train... | 8,736 | 35.404167 | 86 | py |
SSTOD | SSTOD-main/train.py | import sys
from torch import nn
from transformers import AutoTokenizer
import ontology
from models.model import UBAR_plus
sys.path.append('..')
from evaluate import validate_metric, validation_metric_gpt
import argparse
import json
import logging
import os
import random
import time
from torch.utils.data import Ran... | 16,756 | 38.614657 | 132 | py |
SSTOD | SSTOD-main/models/TFIDF.py | import heapq
import json
import pickle
import re
import numpy as np
from pypinyin import lazy_pinyin
from sklearn.metrics.pairwise import cosine_similarity
import torch
from tqdm import tqdm
class TfIdf(object):
def __init__(self):
self.word_vectorizer, self.word_transformer, self.word_weight = pickle.lo... | 2,614 | 44.877193 | 121 | py |
SSTOD | SSTOD-main/models/model.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from transformers import AutoModelWithLMHead, AutoModel
from models.TFIDF import TfIdf
class UBAR_plus(nn.Module):
def __init__(self, args, tokenizer, device):
super(UBAR_plus, self).__init__()
self.args = args
self.tokeni... | 978 | 29.59375 | 77 | py |
SSTOD | SSTOD-main/reader/Dataset.py | import copy
import json
import logging
import os
import random
from collections import OrderedDict
from torch.utils.data import Dataset
import ontology
from reader.data_util import read_name_dialog_from_file
from utils import utils
class _BaseDataset(Dataset):
def __init__(self, args):
super(_BaseDatase... | 12,361 | 36.460606 | 146 | py |
SSTOD | SSTOD-main/reader/DataBase.py | import json
import logging
import os
import pickle
import random
import re
import pypinyin
from sklearn.feature_extraction.text import CountVectorizer, TfidfTransformer, TfidfVectorizer
from sklearn.metrics.pairwise import linear_kernel
from torch.utils.data import Dataset, DataLoader
from tqdm import tqdm
import ont... | 5,465 | 34.72549 | 103 | py |
SSTOD | SSTOD-main/utils/optim.py | import os
import torch
from torch import optim
from transformers.optimization import AdamW, get_linear_schedule_with_warmup
class Optim(object):
def __init__(self, **kwargs):
params = kwargs
self.lr = params.get('learning_rate', 1e-4)
self.method = params.get('method', 'adamw')
sel... | 1,719 | 43.102564 | 121 | py |
SSTOD | SSTOD-main/utils/utils.py | import logging
import numpy as np
import torch
from torch.autograd import Variable
from config import BIO_TAG
def log_first_inputs(log_dict):
logging.info("**** Input Examples ****")
for key, context in log_dict.items():
logging.info(key + ': ' + context)
def padSeqs_gpt(sequences, pad_id, maxlen=... | 4,035 | 32.081967 | 114 | py |
WWW2018_Camel | WWW2018_Camel-master/code/utility.py | import six.moves.cPickle as pickle
#import pandas as pd
import numpy as np
import string
import re
import random
from keras.preprocessing import sequence
from itertools import *
class input_data:
def __init__(self, args):
self.args = args
# direct paper-author relation
p_a_dir_list_train = [[] for k in range(... | 9,449 | 34.130112 | 135 | py |
WWW2018_Camel | WWW2018_Camel-master/code/Camel.py | import tensorflow as tf
import keras
from keras.preprocessing import sequence
import cPickle as pkl
import utility as U
from itertools import *
import argparse
import os
import random
import numpy as np
# input arguments
parser = argparse.ArgumentParser(description='demo code of Camel')
parser.add_argument('--author... | 9,396 | 35.996063 | 163 | py |
nn-template | nn-template-main/{{ cookiecutter.repository_name }}/src/{{ cookiecutter.package_name }}/run.py | import logging
from typing import List, Optional
import hydra
import omegaconf
import pytorch_lightning as pl
from omegaconf import DictConfig, ListConfig
from pytorch_lightning import Callback
from nn_core.callbacks import NNTemplateCore
from nn_core.common import PROJECT_ROOT
from nn_core.common.utils import enforc... | 3,995 | 32.579832 | 114 | py |
nn-template | nn-template-main/{{ cookiecutter.repository_name }}/src/{{ cookiecutter.package_name }}/__init__.py | import logging
from nn_core.console_logging import NNRichHandler
# Required workaround because PyTorch Lightning configures the logging on import,
# thus the logging configuration defined in the __init__.py must be called before
# the lightning import otherwise it has no effect.
# See https://github.com/PyTorchLightn... | 1,213 | 28.609756 | 117 | py |
nn-template | nn-template-main/{{ cookiecutter.repository_name }}/src/{{ cookiecutter.package_name }}/modules/module.py | from torch import nn
# https://medium.com/@nutanbhogendrasharma/pytorch-convolutional-neural-network-with-mnist-dataset-4e8a4265e118
class CNN(nn.Module):
def __init__(self, num_classes: int):
super(CNN, self).__init__()
self.model = nn.Sequential(
nn.Conv2d(
in_channel... | 887 | 27.645161 | 111 | py |
nn-template | nn-template-main/{{ cookiecutter.repository_name }}/src/{{ cookiecutter.package_name }}/pl_modules/pl_module.py | import logging
from typing import Any, Mapping, Optional, Sequence, Tuple, Union
import hydra
import omegaconf
import pytorch_lightning as pl
import torch
import torch.nn.functional as F
import torchmetrics
from torch.optim import Optimizer
from nn_core.common import PROJECT_ROOT
from nn_core.model_logging import NNL... | 5,083 | 30.190184 | 114 | py |
nn-template | nn-template-main/{{ cookiecutter.repository_name }}/src/{{ cookiecutter.package_name }}/data/dataset.py | import hydra
import omegaconf
from torch.utils.data import Dataset
from torchvision.datasets import FashionMNIST
from nn_core.common import PROJECT_ROOT
from nn_core.nn_types import Split
class MyDataset(Dataset):
def __init__(self, split: Split, **kwargs):
super().__init__()
self.split: Split = ... | 1,247 | 23.470588 | 102 | py |
nn-template | nn-template-main/{{ cookiecutter.repository_name }}/src/{{ cookiecutter.package_name }}/data/datamodule.py | import logging
from functools import cached_property, partial
from pathlib import Path
from typing import List, Mapping, Optional, Sequence, Union
import hydra
import omegaconf
import pytorch_lightning as pl
from omegaconf import DictConfig
from torch.utils.data import DataLoader, Dataset, random_split
from torch.util... | 8,091 | 35.45045 | 118 | py |
nn-template | nn-template-main/{{ cookiecutter.repository_name }}/tests/test_checkpoint.py | from importlib import import_module
from pathlib import Path
from typing import Any, Dict
from omegaconf import DictConfig, OmegaConf
from pytorch_lightning import LightningModule
from pytorch_lightning.core.saving import _load_state
from nn_core.serialization import NNCheckpointIO
from tests.conftest import load_che... | 2,420 | 34.086957 | 98 | py |
nn-template | nn-template-main/{{ cookiecutter.repository_name }}/tests/conftest.py | import logging
import os
import shutil
from pathlib import Path
from typing import Dict, Union
import pytest
from hydra import compose, initialize
from hydra.core.hydra_config import HydraConfig
from omegaconf import DictConfig, OmegaConf, open_dict
from pytest import FixtureRequest, TempPathFactory
from pytorch_light... | 3,621 | 23.308725 | 74 | py |
attention-is-all-you-need-pytorch | attention-is-all-you-need-pytorch-master/translate.py | ''' Translate input text with trained model. '''
import torch
import argparse
import dill as pickle
from tqdm import tqdm
import transformer.Constants as Constants
from torchtext.data import Dataset
from transformer.Models import Transformer
from transformer.Translator import Translator
def load_model(opt, device):... | 4,077 | 36.072727 | 97 | py |
attention-is-all-you-need-pytorch | attention-is-all-you-need-pytorch-master/train.py | '''
This script handles the training process.
'''
import argparse
import math
import time
import dill as pickle
from tqdm import tqdm
import numpy as np
import random
import os
import torch
import torch.nn.functional as F
import torch.optim as optim
from torchtext.data import Field, Dataset, BucketIterator
from torch... | 13,173 | 34.798913 | 162 | py |
attention-is-all-you-need-pytorch | attention-is-all-you-need-pytorch-master/preprocess.py | ''' Handling the data io '''
import os
import argparse
import logging
import dill as pickle
import urllib
from tqdm import tqdm
import sys
import codecs
import spacy
import torch
import tarfile
import torchtext.data
import torchtext.datasets
from torchtext.datasets import TranslationDataset
import transformer.Constants... | 12,646 | 36.52819 | 108 | py |
attention-is-all-you-need-pytorch | attention-is-all-you-need-pytorch-master/transformer/Layers.py | ''' Define the Layers '''
import torch.nn as nn
import torch
from transformer.SubLayers import MultiHeadAttention, PositionwiseFeedForward
__author__ = "Yu-Hsiang Huang"
class EncoderLayer(nn.Module):
''' Compose with two layers '''
def __init__(self, d_model, d_inner, n_head, d_k, d_v, dropout=0.1):
... | 1,684 | 38.186047 | 86 | py |
attention-is-all-you-need-pytorch | attention-is-all-you-need-pytorch-master/transformer/Translator.py | ''' This module will handle the text generation with beam search. '''
import torch
import torch.nn as nn
import torch.nn.functional as F
from transformer.Models import Transformer, get_pad_mask, get_subsequent_mask
class Translator(nn.Module):
''' Load a trained model and translate in beam search fashion. '''
... | 4,562 | 38.678261 | 101 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.