repo stringlengths 2 99 | file stringlengths 13 225 | code stringlengths 0 18.3M | file_length int64 0 18.3M | avg_line_length float64 0 1.36M | max_line_length int64 0 4.26M | extension_type stringclasses 1
value |
|---|---|---|---|---|---|---|
deepnl | deepnl-master/bin/dl-words.py | #!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Learn word embeddings from plain text.
Author: Giuseppe Attardi
"""
import logging
import numpy as np
import argparse
from ConfigParser import ConfigParser
# profiling
# import yappi
# allow executing from anywhere without installing the package
import sys
import o... | 6,996 | 33.46798 | 98 | py |
deepnl | deepnl-master/bin/dl-conv.py | #!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Train and use a convolutional neural network classifier.
Author: Giuseppe Attardi
"""
from __future__ import print_function
import logging
import numpy as np
import argparse
from ConfigParser import ConfigParser
# allow executing from anywhere without installing the... | 13,651 | 41.397516 | 132 | py |
deepnl | deepnl-master/bin/dl-ner.py | #!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Train and use a NE tagger.
Author: Giuseppe Attardi
"""
from __future__ import print_function
import logging
import numpy as np
import argparse
from ConfigParser import ConfigParser
# allow executing from anywhere without installing the package
import sys
import os
... | 15,687 | 42.699164 | 128 | py |
deepnl | deepnl-master/bin/mwe.py | #! /usr/bin/env python
"""
Check if phrase is a MWE.
Usage:
./mwe.py embeddings vocabulary
Options:
-h, --help : display this help and exit
"""
from __future__ import print_function
import sys
from optparse import OptionParser
import cPickle as pickle
from operator import itemgetter
import re
impo... | 5,132 | 28.164773 | 76 | py |
deepnl | deepnl-master/bin/dl-pos.py | #!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Train and use a POS tagger.
Author: Giuseppe Attardi
"""
import logging
import numpy as np
import argparse
from ConfigParser import ConfigParser
# allow executing from anywhere without installing the package
import sys
import os
import distutils.util
builddir = os.p... | 13,667 | 40.798165 | 132 | py |
deepnl | deepnl-master/bin/senna-tag.py | #!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
This script will run a POS or SRL tagger on the input data and print the results
to stdout.
"""
from __future__ import print_function
import argparse
import logging
import ipdb
# Attardi: allow executing from anywhere without installing package
import sys
import os
s... | 7,391 | 30.589744 | 88 | py |
deepnl | deepnl-master/bin/ssyevr.py | #!/usr/bin/python
from __future__ import print_function
import numpy as np
from scipy.linalg.lapack import ssyevr
A = np.array([[ 0.67, -0.20, 0.19, -1.06, 0.46],
[-0.20, 3.82, -0.13, 1.06, -0.48],
[ 0.19, -0.13, 3.27, 0.11, 1.10],
[-1.06, 1.06, 0.11, 5.86, -0.98],
... | 519 | 19 | 52 | py |
deepnl | deepnl-master/bin/dl-sentiwords.py | #!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Learn sentiment-specific word embeddings from tweets.
Author: Giuseppe Attardi
"""
import logging
import numpy as np
import argparse
from ConfigParser import ConfigParser
from itertools import chain
# allow executing from anywhere without installing the package
impo... | 9,109 | 39.488889 | 100 | py |
deepnl | deepnl-master/bin/tweet-tokenize.py | #!/usr/bin/python
"""
Tokenize a Twitter corpus in CoNLL 2013 format.
Usage:
tweet-tokenize.py [options] < CoNLL20113-file
Optons:
-h print this help message
-l language select corpus language (default english)
"""
import os
import sys
import getopt
from __future__ import print_function
# Tanl director... | 2,175 | 22.397849 | 82 | py |
deepnl | deepnl-master/bin/dl-words-pca.py | #!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Learn word embeddings from plain text using Hellinger PCA.
See
Lebret, Rémi, and Ronan Collobert. "Word Embeddings through Hellinger PCA." EACL 2014 (2014): 482.
Author: Giuseppe Attardi
"""
import logging
import numpy as np
import argparse
from ConfigParser import ... | 4,666 | 34.356061 | 98 | py |
deepnl | deepnl-master/deepnl/reader.py | #!/usr/env python
# -*- coding: utf-8 -*-
#cython: embedsignature=True
"""
Classes for reading various types of corpora.
"""
# standard
import os
import logging
import numpy as np
from collections import Counter
import gzip
# local
from corpus import *
from embeddings import Plain
class Reader(object):
"""
... | 9,572 | 34.324723 | 138 | py |
deepnl | deepnl-master/deepnl/ner_tagger.py | # -*- coding: utf-8 -*-
"""
NER tagger exploiting a deep neural network.
"""
# standard
import sys
from itertools import izip
# local
from tagger import Tagger
from reader import TaggerReader
from corpus import *
# ----------------------------------------------------------------------
class ToIOBES(object):
""... | 2,105 | 25.325 | 74 | py |
deepnl | deepnl-master/deepnl/corpus.py | #!/usr/env python
# -*- coding: utf-8 -*-
#cython: embedsignature=True
"""
Classes for reading/writing various types of corpora.
"""
# standard
from __future__ import print_function
import sys
import codecs
class ConllReader(object):
"""
An iterator over sentences read from a file in CoNLL TSV format.
If... | 3,301 | 27.465517 | 76 | py |
deepnl | deepnl-master/deepnl/embeddings.py | # -*- coding: utf-8 -*-
"""
Load word embeddings from different representations.
"""
from __future__ import print_function
import os
import numpy as np
import logging
from itertools import izip
# local
from word_dictionary import WordDictionary
# ---------------------------------------------------------------------... | 4,684 | 30.02649 | 87 | py |
deepnl | deepnl-master/deepnl/utils.py | # -*- coding: utf-8 -*-
"""
Utility functions
"""
import re
import logging
import numpy as np
from itertools import islice
def tokenize(text, sent_splitter, tokenizer, clean=True):
"""
Returns a list of lists of the tokens in text, separated by sentences.
Each line break in the text starts a new list.
... | 8,281 | 31.351563 | 87 | py |
deepnl | deepnl-master/deepnl/pos_tagger.py | # -*- coding: utf-8 -*-
"""
POS tagger exploiting a deep neural network.
"""
# standard
import sys
from __future__ import print_function
# local
from network import Network
from tagger import Tagger
from reader import PosReader
from corpus import *
# -----------------------------------------------------------------... | 707 | 21.83871 | 72 | py |
deepnl | deepnl-master/deepnl/__init__.py | 0 | 0 | 0 | py | |
deepnl | deepnl-master/deepnl/word_dictionary.py | # -*- coding: utf-8 -*-
from collections import Counter, OrderedDict
import cPickle as pickle
import re
from numpy import int32 as INT
num = re.compile('[+\-]?([0-9][,.]?)+$')
def isNumber(key):
return num.match(key)
class WordDictionary(dict):
"""
Class to store words and their corresponding indices in... | 10,232 | 36.483516 | 117 | py |
isogeny | isogeny-master/verify_Proposition_5-1.py | from sage.all import *
import ast, sys
#################################################################
#This file verifies Proposition 5.1 parts (1) and (2) of
#''A local-global principle for isogenies of composite degree''
#by Isabel Vogt
#Part (3) is verified by the computing the genus of each of the
#subgroups ... | 15,551 | 30.738776 | 184 | py |
isogeny | isogeny-master/check_Theorem_3-7.py | from sage.all import *
import ast, sys
ell = 3
#################################################################
#This file confirms Theorem 3.7 for ell = 3 and n <= 5 of
#''A local-global principle for isogenies of composite degree''
#by Isabel Vogt (references are to arXiv version 2)
#The following files must be... | 16,550 | 32.368952 | 198 | py |
isogeny | isogeny-master/verify_Theorem_1.py | from sage.all import *
import ast, sys
from sage.modular.arithgroup.congroup_generic import CongruenceSubgroup_constructor as CS
#################################################################
#This file verifies Theorem 1 part (1) of
#''A local-global principle for isogenies of composite degree''
#by Isabel Vogt
... | 13,954 | 33.542079 | 441 | py |
isogeny | isogeny-master/auxiliary code/parse_drew_data.py | for i in xrange(2, 7):
N = 2**i
for line in open("gl_2_full/gl_2_" + str(N) + ".dat", "r"):
label = line.split()[0]
spl = line.split(":")
if len(spl) > 1:
gens = line.split(":")[1]
gen = gens[1:-2]
g = open("gl2_" + str(N) + ".txt", "a")
g.... | 396 | 32.083333 | 67 | py |
isogeny | isogeny-master/auxiliary code/coset_reps.py |
from sage.all import *
import ast, sys
#################################################################
#This file contains a function to make coset representatives of
#a subgroup in a larger group. It is optimized for large subgroups.
#################################################################
ell = 2
G ... | 2,774 | 25.428571 | 97 | py |
isogeny | isogeny-master/auxiliary code/parse_bads.py | from check_subgroups_2 import *
from sieve_max_subgroups import *
from sage.all import *
import ast, sys
#################################################################
#This file contains functions written to manipulate the output of
#check_exceptional_subgroups and similar functions that write
#labels or label... | 3,754 | 28.801587 | 72 | py |
SemFormer | SemFormer-main/inference_rw.py | # Copyright (C) 2020 * Ltd. All rights reserved.
# author : Sanghyeon Jo <josanghyeokn@gmail.com>
import os
import sys
import copy
import shutil
import random
import argparse
import numpy as np
import math
from tqdm import tqdm
import imageio
import torch
import torch.nn as nn
import torch.nn.functional as F
from t... | 6,873 | 34.802083 | 120 | py |
SemFormer | SemFormer-main/inference_classification.py | # Copyright (C) 2020 * Ltd. All rights reserved.
# author : Sanghyeon Jo <josanghyeokn@gmail.com>
import os
import sys
import copy
import shutil
import random
import argparse
import numpy as np
import imageio
import torch
import torch.nn as nn
import torch.nn.functional as F
from torchvision import transforms
from ... | 6,793 | 34.202073 | 156 | py |
SemFormer | SemFormer-main/evaluate.py | import os
import cv2
import math
import pandas as pd
import numpy as np
from PIL import Image
import multiprocessing
import argparse
from pprint import pprint
import copy
import joblib
import multiprocessing
from tools.ai.demo_utils import *
parser = argparse.ArgumentParser()
parser.add_argument('--experiment_name', ... | 10,918 | 36.139456 | 113 | py |
SemFormer | SemFormer-main/make_affinity_labels.py | # Copyright (C) 2020 * Ltd. All rights reserved.
# author : Sanghyeon Jo <josanghyeokn@gmail.com>
import os
import sys
import copy
import shutil
import random
import argparse
import numpy as np
import joblib
import multiprocessing
import imageio
import torch
import torch.nn as nn
import torch.nn.functional as F
fro... | 4,537 | 34.732283 | 149 | py |
SemFormer | SemFormer-main/train_classification.py | # Copyright (C) 2020 * Ltd. All rights reserved.
# author : Sanghyeon Jo <josanghyeokn@gmail.com>
import os
import sys
import copy
import shutil
import random
import argparse
import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
from torchvision import transforms
from torch.utils.tens... | 14,549 | 38.754098 | 132 | py |
SemFormer | SemFormer-main/train_segmentation.py | # Copyright (C) 2020 * Ltd. All rights reserved.
# author : Sanghyeon Jo <josanghyeokn@gmail.com>
import os
import sys
import copy
import shutil
import random
import argparse
import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
from torchvision import transforms
from torch.utils.tens... | 14,851 | 39.249322 | 133 | py |
SemFormer | SemFormer-main/train_affinitynet.py | # Copyright (C) 2020 * Ltd. All rights reserved.
# author : Sanghyeon Jo <josanghyeokn@gmail.com>
import os
import sys
import copy
import shutil
import random
import argparse
import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
from torchvision import transforms
from torch.utils.tens... | 12,118 | 38.865132 | 132 | py |
SemFormer | SemFormer-main/make_pseudo_labels.py | # Copyright (C) 2020 * Ltd. All rights reserved.
# author : Sanghyeon Jo <josanghyeokn@gmail.com>
import os
import sys
import copy
import shutil
import random
import argparse
import numpy as np
import joblib
import multiprocessing
import imageio
import torch
import torch.nn as nn
import torch.nn.functional as F
fro... | 4,297 | 34.520661 | 123 | py |
SemFormer | SemFormer-main/inference_segmentation.py | # Copyright (C) 2020 * Ltd. All rights reserved.
# author : Sanghyeon Jo <josanghyeokn@gmail.com>
import os
import sys
import copy
import shutil
import random
import argparse
import numpy as np
from tqdm import tqdm
import imageio
import torch
import torch.nn as nn
import torch.nn.functional as F
from torchvision i... | 7,906 | 37.014423 | 129 | py |
SemFormer | SemFormer-main/train_semformer.py | # Copyright (C) 2020 * Ltd. All rights reserved.
# author : Sanghyeon Jo <josanghyeokn@gmail.com>
import os
import sys
import copy
import shutil
import random
import argparse
import numpy as np
import math
import torch
import torch.nn as nn
import torch.nn.functional as F
from torchvision import transforms
from torc... | 22,528 | 38.803887 | 209 | py |
SemFormer | SemFormer-main/inference_semformer.py | # Copyright (C) 2020 * Ltd. All rights reserved.
# author : Sanghyeon Jo <josanghyeokn@gmail.com>
import os
import sys
import copy
import shutil
import random
import argparse
import numpy as np
from tqdm import tqdm
import imageio
import torch
import torch.nn as nn
import torch.nn.functional as F
from torchvision i... | 9,474 | 36.011719 | 135 | py |
SemFormer | SemFormer-main/train_caae.py | # Copyright (C) 2020 * Ltd. All rights reserved.
# author : Sanghyeon Jo <josanghyeokn@gmail.com>
import os
import sys
import copy
import shutil
import random
import argparse
import numpy as np
import math
import time
import torch
import torch.nn as nn
import torch.nn.functional as F
from torchvision import transfor... | 15,231 | 36.517241 | 133 | py |
SemFormer | SemFormer-main/tools/general/xml_utils.py | # Copyright (C) 2020 * Ltd. All rights reserved.
# author : Sanghyeon Jo <josanghyeokn@gmail.com>
import xml.etree.ElementTree as ET
def read_xml(xml_path):
tree = ET.parse(xml_path)
root = tree.getroot()
size = root.find('size')
image_width = int(size.find('width').text)
image_height = int(s... | 1,112 | 32.727273 | 92 | py |
SemFormer | SemFormer-main/tools/general/json_utils.py | # Copyright (C) 2020 * Ltd. All rights reserved.
# author : Sanghyeon Jo <josanghyeokn@gmail.com>
import json
def read_json(filepath):
with open(filepath, 'r') as f:
data = json.load(f)
return data
def write_json(filepath, data):
with open(filepath, 'w') as f:
json.dump(data, f, indent = ... | 327 | 20.866667 | 48 | py |
SemFormer | SemFormer-main/tools/general/txt_utils.py | # Copyright (C) 2020 * Ltd. All rights reserved.
# author : Sanghyeon Jo <josanghyeokn@gmail.com>
def read_txt(path):
with open(path, 'r') as f:
return [line.strip() for line in f.readlines()]
def write_txt(path, data_list):
with open(path, 'w') as f:
for data in data_list:
f.write... | 424 | 27.333333 | 55 | py |
SemFormer | SemFormer-main/tools/general/time_utils.py | # Copyright (C) 2020 * Ltd. All rights reserved.
# author : Sanghyeon Jo <josanghyeokn@gmail.com>
import time
def get_today():
now = time.localtime()
s = "%04d-%02d-%02d-%02dh%02dm%02ds" % (now.tm_year, now.tm_mon, now.tm_mday, now.tm_hour, now.tm_min, now.tm_sec)
return s
class Timer:
def __init__(s... | 784 | 23.53125 | 118 | py |
SemFormer | SemFormer-main/tools/general/pickle_utils.py | # Copyright (C) 2020 * Ltd. All rights reserved.
# author : Sanghyeon Jo <josanghyeokn@gmail.com>
import pickle
def dump_pickle(path, data):
pickle.dump(data, open(path, 'wb'))
def load_pickle(path):
return pickle.load(open(path, 'rb'))
| 249 | 19.833333 | 48 | py |
SemFormer | SemFormer-main/tools/general/io_utils.py | # Copyright (C) 2020 * Ltd. All rights reserved.
# author : Sanghyeon Jo <josanghyeokn@gmail.com>
import os
import random
import argparse
import numpy as np
def create_directory(path):
if not os.path.isdir(path):
os.makedirs(path)
return path
def str2bool(v):
if isinstance(v, bool):
retur... | 550 | 21.04 | 67 | py |
SemFormer | SemFormer-main/tools/dataset/voc_utils.py | import numpy as np
def color_map(N = 256):
def bitget(byteval, idx):
return ((byteval & (1 << idx)) != 0)
cmap = np.zeros((N, 3), dtype = np.uint8)
for i in range(N):
r = g = b = 0
c = i
for j in range(8):
r = r | (bitget(c, 0) << 7-j)
g = g | (bitge... | 1,275 | 28.674419 | 98 | py |
SemFormer | SemFormer-main/tools/ai/demo_utils.py | import cv2
import random
import numpy as np
import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plt
import copy
from PIL import Image
def get_strided_size(orig_size, stride):
return ((orig_size[0]-1)//stride+1, (orig_size[1]-1)//stride+1)
def get_strided_up_size(orig_size, stride):
strided_s... | 3,252 | 27.535088 | 113 | py |
SemFormer | SemFormer-main/tools/ai/augment_utils.py | import cv2
import random
import numpy as np
from torchvision.transforms import transforms
from torchvision.transforms import functional as TF
import torch.nn.functional as F
from PIL import Image
def convert_OpenCV_to_PIL(image):
return Image.fromarray(image[..., ::-1])
def convert_PIL_to_OpenCV(image):
re... | 14,808 | 29.597107 | 104 | py |
SemFormer | SemFormer-main/tools/ai/optim_utils.py | import torch
from .torch_utils import *
class PolyOptimizer(torch.optim.SGD):
def __init__(self, params, lr, weight_decay, max_step, momentum=0.9, nesterov=False):
super().__init__(params, lr, weight_decay, nesterov=nesterov)
self.global_step = 0
self.max_step = max_step
self.momen... | 770 | 31.125 | 89 | py |
SemFormer | SemFormer-main/tools/ai/torch_utils.py | import cv2
import math
import torch
import random
import numpy as np
import torch.nn.functional as F
from torch.optim.lr_scheduler import LambdaLR
def make_divisible(x, divisor, rounding='ceil'):
assert divisor != 0, 'divisor must be nonzero'
rounding_func = getattr(math, rounding)
return rounding_func(x... | 4,951 | 30.341772 | 115 | py |
SemFormer | SemFormer-main/tools/ai/evaluate_utils.py | import numpy as np
import torch
from sklearn.metrics import average_precision_score
from tools.general.json_utils import read_json
from core.functional import cosine_similarity
def calculate_for_tags(pred_tags, gt_tags):
"""This function calculates precision, recall, and f1-score using tags.
Args:
pr... | 8,682 | 28.334459 | 84 | py |
SemFormer | SemFormer-main/tools/ai/log_utils.py | # Copyright (C) 2020 * Ltd. All rights reserved.
# author : Sanghyeon Jo <josanghyeokn@gmail.com>
import numpy as np
from tools.general.txt_utils import add_txt
import time
import math
def get_str_time(time):
time_h = time // 3600
time_m = (time - (time_h * 3600)) // 60
time_s = time - ((time_h * 3600) +... | 2,744 | 27.010204 | 85 | py |
SemFormer | SemFormer-main/tools/ai/randaugment.py | # code in this file is adpated from
# https://github.com/ildoonet/pytorch-randaugment/blob/master/RandAugment/augmentations.py
# https://github.com/google-research/fixmatch/blob/master/third_party/auto_augment/augmentations.py
# https://github.com/google-research/fixmatch/blob/master/libml/ctaugment.py
import logging
i... | 5,864 | 24.951327 | 99 | py |
SemFormer | SemFormer-main/core/aff_utils.py | import torch
import torch.nn.functional as F
import numpy as np
class PathIndex:
def __init__(self, radius, default_size):
self.radius = radius
self.radius_floor = int(np.ceil(radius) - 1)
self.search_paths, self.search_dst = self.get_search_paths_dst(self.radius)
self.path_indices... | 6,785 | 36.910615 | 133 | py |
SemFormer | SemFormer-main/core/utils.py | import torch
import torch.nn.functional as F
def grad_enable(model, ignore_param_names=None):
for param_name, param in model.named_parameters():
if ignore_param_names is not None:
if param_name in ignore_param_names:
continue
param.requires_grad = True
def grad_disable... | 3,424 | 39.77381 | 110 | py |
SemFormer | SemFormer-main/core/networks_legacy.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from torchvision import models
import torch.utils.model_zoo as model_zoo
from .arch_resnet import resnet, resnet38
from .arch_resnest import resnest
from .arch_vgg import vgg
from .deeplab_utils import ASPP, Decoder
from .aff_utils import PathIndex
... | 5,016 | 33.6 | 137 | py |
SemFormer | SemFormer-main/core/networks.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from torchvision import models
import torch.utils.model_zoo as model_zoo
from .arch_resnet import resnet, resnet38
from .arch_resnest import resnest
from .arch_vgg import vgg
from .deeplab_utils import ASPP, Decoder
from .aff_utils import PathIndex
... | 651 | 24.076923 | 65 | py |
SemFormer | SemFormer-main/core/datasets.py | import os
import cv2
import glob
import torch
import copy
import torchvision.datasets as dset
import math
import imageio
import numpy as np
from PIL import Image
from core.aff_utils import *
from tools.ai.augment_utils import *
from tools.ai.torch_utils import one_hot_embedding
from tools.general.xml_utils import ... | 12,191 | 32.772853 | 121 | py |
SemFormer | SemFormer-main/core/deeplab_utils.py | # Copyright (C) 2021 * Ltd. All rights reserved.
# author : Sanghyeon Jo <josanghyeokn@gmail.com>
import torch
import torch.nn as nn
import torch.nn.functional as F
class ASPPModule(nn.Module):
def __init__(self, inplanes, planes, kernel_size, padding, dilation, norm_fn=None):
super().__init__()
s... | 4,572 | 34.449612 | 137 | py |
SemFormer | SemFormer-main/core/affinitynet.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from torchvision import models
import torch.utils.model_zoo as model_zoo
from .arch_resnet import resnet, resnet38
from .arch_resnest import resnest
from .arch_vgg import vgg
from .models.transformer_backbone import ViTBackbone
from . import functiona... | 5,071 | 37.424242 | 136 | py |
SemFormer | SemFormer-main/core/abc_modules.py |
import math
import torch
import torch.nn as nn
from abc import ABC
class BaseModule(nn.Module):
def forward(self, *x, stage='forward_x', **kwargs):
if isinstance(stage, (list, tuple)):
output = x
for s in stage:
func = getattr(self, stage)
output... | 2,492 | 29.777778 | 82 | py |
SemFormer | SemFormer-main/core/sync_batchnorm/replicate.py | # -*- coding: utf-8 -*-
# File : replicate.py
# Author : Jiayuan Mao
# Email : maojiayuan@gmail.com
# Date : 27/01/2018
#
# This file is part of Synchronized-BatchNorm-PyTorch.
# https://github.com/vacancy/Synchronized-BatchNorm-PyTorch
# Distributed under MIT License.
import functools
from torch.nn.parallel.dat... | 3,218 | 35.579545 | 115 | py |
SemFormer | SemFormer-main/core/sync_batchnorm/unittest.py | # -*- coding: utf-8 -*-
# File : unittest.py
# Author : Jiayuan Mao
# Email : maojiayuan@gmail.com
# Date : 27/01/2018
#
# This file is part of Synchronized-BatchNorm-PyTorch.
# https://github.com/vacancy/Synchronized-BatchNorm-PyTorch
# Distributed under MIT License.
import unittest
import numpy as np
from torc... | 834 | 26.833333 | 157 | py |
SemFormer | SemFormer-main/core/sync_batchnorm/batchnorm.py | # -*- coding: utf-8 -*-
# File : batchnorm.py
# Author : Jiayuan Mao
# Email : maojiayuan@gmail.com
# Date : 27/01/2018
#
# This file is part of Synchronized-BatchNorm-PyTorch.
# https://github.com/vacancy/Synchronized-BatchNorm-PyTorch
# Distributed under MIT License.
import collections
import torch
import torc... | 12,932 | 44.861702 | 116 | py |
SemFormer | SemFormer-main/core/sync_batchnorm/comm.py | # -*- coding: utf-8 -*-
# File : comm.py
# Author : Jiayuan Mao
# Email : maojiayuan@gmail.com
# Date : 27/01/2018
#
# This file is part of Synchronized-BatchNorm-PyTorch.
# https://github.com/vacancy/Synchronized-BatchNorm-PyTorch
# Distributed under MIT License.
import queue
import collections
import threading
... | 4,440 | 33.161538 | 117 | py |
SemFormer | SemFormer-main/core/sync_batchnorm/__init__.py | # -*- coding: utf-8 -*-
# File : __init__.py
# Author : Jiayuan Mao
# Email : maojiayuan@gmail.com
# Date : 27/01/2018
#
# This file is part of Synchronized-BatchNorm-PyTorch.
# https://github.com/vacancy/Synchronized-BatchNorm-PyTorch
# Distributed under MIT License.
from .batchnorm import SynchronizedBatchNorm1... | 447 | 36.333333 | 96 | py |
SemFormer | SemFormer-main/core/models/caae.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from timm.models.layers import Mlp
from ..module import SeparateLinear
from .modules import Token2Embed, Embed2Token
from .transformer_backbone import ViTBackbone
from ..functional import cosine_similarity
from ..arch_transformer.vit import VIT_NET_CF... | 6,160 | 30.433673 | 97 | py |
SemFormer | SemFormer-main/core/models/modules.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from timm.models.layers import Mlp, DropPath
from ..arch_transformer.vit import Attention as SelfAttention
from ..arch_transformer.vit import Block as ViTBlock
class ResBlock(nn.Module):
def __init__(self, in_channels, out_channels, kernel_size=... | 21,397 | 33.737013 | 117 | py |
SemFormer | SemFormer-main/core/models/base_backbone.py | import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.utils.model_zoo as model_zoo
import re
from ..module import FixedBatchNorm
from ..arch_resnet import resnet, resnet38
from ..arch_resnest import resnest
from ..arch_vgg import vgg
from ..abc_modules import ABC_Model
class BaseBackboneVG... | 5,212 | 33.296053 | 127 | py |
SemFormer | SemFormer-main/core/models/transformer_segmentor.py | import torch
import torch.nn as nn
import torch.nn.functional as F
import math
from .. import functional as _F
from ..module import SeparateLinear
from .transformer_backbone import ViTBackbone
from ..abc_modules import ABC_Model
class SemFormerSegmentor(nn.Module, ABC_Model):
def __init__(self,
model_n... | 2,732 | 35.44 | 101 | py |
SemFormer | SemFormer-main/core/models/transformer_backbone.py | import torch
import torch.nn as nn
import torch.nn.functional as F
import math
from ..arch_transformer import vit
from ..abc_modules import ABC_Model
class ViTBackbone(nn.Module, ABC_Model):
def __init__(self, model_name, with_last_norm=True,
with_posembed=False, with_cls_token=False, img_size=224, **kw... | 5,250 | 38.780303 | 107 | py |
SemFormer | SemFormer-main/core/models/__init__.py | from .base_backbone import (BaseBackboneVGG, BaseBackbone,
ReturnLastLayerBaseBackboneVGG,
ReturnLastLayerBaseBackbone)
from .caae import (ViTEncoder, ViTDecoder, ViTAutoEncoder, ClassAwareAutoEncoder)
from .base_segmentor import BaseClassifier
from .transformer_s... | 387 | 54.428571 | 81 | py |
SemFormer | SemFormer-main/core/models/semformer.py | import torch
import torch.nn as nn
import torch.nn.functional as F
import random
from .transformer_segmentor import SemFormerSegmentor
from ..abc_modules import BaseModule, ABC_Model
from ..functional import cosine_similarity
from ..utils import get_label_info
class SemFormer(BaseModule, ABC_Model):
def __init_... | 3,397 | 37.613636 | 120 | py |
SemFormer | SemFormer-main/core/models/base_segmentor.py | import torch
import torch.nn as nn
import torch.nn.functional as F
import functools
from ..module import SMDConv2d
from .modules import SemanticCorrelationModule
from .base_backbone import (BaseBackboneVGG,
BaseBackbone,
ReturnLastLayerBaseBackboneVGG,
... | 1,470 | 30.978261 | 91 | py |
SemFormer | SemFormer-main/core/arch_resnet/resnet.py | import torch.nn as nn
import torch.nn.functional as F
import torch.utils.model_zoo as model_zoo
urls_dic = {
'resnet18': 'https://download.pytorch.org/models/resnet18-5c106cde.pth',
'resnet34': 'https://download.pytorch.org/models/resnet34-333f7ec4.pth',
'resnet50': 'https://download.pytorch.org/models/res... | 5,537 | 33.830189 | 114 | py |
SemFormer | SemFormer-main/core/arch_resnet/resnet38.py | import torch
from torch import nn
import torch.nn.functional as F
import numpy as np
class ResBlock(nn.Module):
def __init__(self, in_channels, mid_channels, out_channels, stride=1, first_dilation=None, dilation=1):
super(ResBlock, self).__init__()
self.same_shape = (in_channels == out_channels a... | 7,556 | 29.844898 | 125 | py |
SemFormer | SemFormer-main/core/module/pooling.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.nn.modules.utils import _pair
class GlobalSumPool2d(nn.Module):
def forward(self, x):
return x.view(*x.shape[:-2], -1).sum(dim=-1)[..., None, None] | 241 | 21 | 69 | py |
SemFormer | SemFormer-main/core/module/aspp.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.nn.modules.utils import _pair
class CustomASPP(nn.Module):
def __init__(self, in_channels, out_channels, dilations=[1, 3, 6, 12], act_last=True):
super().__init__()
self.in_channels = in_channels
self.out_chan... | 1,744 | 33.215686 | 114 | py |
SemFormer | SemFormer-main/core/module/activation.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.nn.modules.utils import _pair
from .. import functional as FN
class SMU(nn.Module):
def __init__(self, miu=1e6):
super().__init__()
self.miu = nn.Parameter(torch.tensor(miu, dtype=torch.float))
def forward(self, ... | 778 | 18.475 | 69 | py |
SemFormer | SemFormer-main/core/module/non_local.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.nn.modules.utils import _pair
class NonLocal2d(nn.Module):
def __init__(self):
super().__init__()
def forward(self, x):
B, C, H, W = x.shape
# (B, C, HW)
k = x.view(B, C, -1)
# (B, HW, C)
... | 598 | 20.392857 | 50 | py |
SemFormer | SemFormer-main/core/module/convolution.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.nn.modules.utils import _pair
class MultiDilatedConv2d(nn.Conv2d):
def __init__(self, *args, dilations=[1], **kwargs):
super().__init__(*args, **kwargs)
self.dilations = dilations
self.num_branch = len(dilatio... | 2,389 | 33.637681 | 97 | py |
SemFormer | SemFormer-main/core/module/linear.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.nn.modules.utils import _pair
import math
class SeparateLinear(nn.Module):
def __init__(self, in_channels, out_channels, groups=1, bias=True):
super().__init__()
self.in_channels = in_channels
self.out_channel... | 1,692 | 34.270833 | 91 | py |
SemFormer | SemFormer-main/core/module/__init__.py | from .activation import SMU, SMUG, SMUL
from .aspp import CustomASPP
from .convolution import MultiDilatedConv2d, SMDConv2d
from .interpolate import Interpolate
from .linear import SeparateLinear
from .non_local import NonLocal2d
from .normalization import SynchronizedBatchNorm2d, FixedBatchNorm, group_norm
from .ops i... | 441 | 43.2 | 78 | py |
SemFormer | SemFormer-main/core/module/ops.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.nn.modules.utils import _pair
class Flatten(nn.Module):
def __init__(self, start_dim=0, end_dim=-1):
super().__init__()
self.start_dim = start_dim
self.end_dim = end_dim
def forward(self, x):
retu... | 1,050 | 19.211538 | 61 | py |
SemFormer | SemFormer-main/core/module/normalization.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.nn.modules.utils import _pair
from ..sync_batchnorm.batchnorm import SynchronizedBatchNorm2d
class FixedBatchNorm(nn.BatchNorm2d):
def forward(self, x):
return F.batch_norm(x, self.running_mean, self.running_var, self.weight, ... | 424 | 27.333333 | 121 | py |
SemFormer | SemFormer-main/core/module/padding.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.nn.modules.utils import _pair
from .. import functional as FN
class SamePad2d(nn.Module):
def __init__(self, kernel_size, stride=1, dilation=1, pad_mode='around'):
super().__init__()
self.kernel_size = _pair(kernel_si... | 846 | 25.46875 | 92 | py |
SemFormer | SemFormer-main/core/module/interpolate.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.nn.modules.utils import _pair
class Interpolate(nn.Module):
def __init__(self, size=None, scale_factor=None, mode='bilinear', align_corners=True):
super().__init__()
self.size = size
self.scale_factor ... | 559 | 28.473684 | 125 | py |
SemFormer | SemFormer-main/core/arch_vgg/vgg.py | import torch.nn as nn
import torch.utils.model_zoo as model_zoo
import math
__all__ = [
'VGG', 'vgg11', 'vgg11_bn', 'vgg13', 'vgg13_bn', 'vgg16', 'vgg16_bn',
'vgg19_bn', 'vgg19',
]
model_urls = {
'vgg11': 'https://download.pytorch.org/models/vgg11-bbd30ac9.pth',
'vgg13': 'https://download.pytorch.or... | 6,475 | 31.218905 | 113 | py |
SemFormer | SemFormer-main/core/arch_resnest/resnet.py | ##+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
## Created by: Hang Zhang
## Email: zhanghang0704@gmail.com
## Copyright (c) 2020
##
## LICENSE file in the root directory of this source tree
##+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
"""ResNet variants"""
im... | 13,241 | 41.854369 | 162 | py |
SemFormer | SemFormer-main/core/arch_resnest/resnest.py | ##+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
## Created by: Hang Zhang
## Email: zhanghang0704@gmail.com
## Copyright (c) 2020
##
## LICENSE file in the root directory of this source tree
##+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
"""ResNeSt models"""
im... | 2,938 | 39.819444 | 98 | py |
SemFormer | SemFormer-main/core/arch_resnest/splat.py | """Split-Attention"""
import torch
from torch import nn
import torch.nn.functional as F
from torch.nn import Conv2d, Module, Linear, BatchNorm2d, ReLU
from torch.nn.modules.utils import _pair
__all__ = ['SplAtConv2d']
class SplAtConv2d(Module):
"""Split-Attention Conv2d
"""
def __init__(self, in_channels... | 3,620 | 35.21 | 101 | py |
SemFormer | SemFormer-main/core/arch_transformer/vit.py | """ Vision Transformer (ViT) in PyTorch
A PyTorch implement of Vision Transformers as described in:
'An Image Is Worth 16 x 16 Words: Transformers for Image Recognition at Scale'
- https://arxiv.org/abs/2010.11929
`How to train your ViT? Data, Augmentation, and Regularization in Vision Transformers`
- https:... | 48,791 | 46.187621 | 140 | py |
SemFormer | SemFormer-main/core/arch_transformer/layers.py | """ Image to Patch Embedding using Conv2d
A convolution based approach to patchifying a 2D image w/ embedding projection.
Based on the impl in https://github.com/google-research/vision_transformer
Hacked together by / Copyright 2020 Ross Wightman
"""
from torch import nn as nn
import timm
from timm.models.layers.he... | 1,542 | 36.634146 | 111 | py |
SemFormer | SemFormer-main/core/functional/math.py | import torch
import torch.nn.functional as F
import math
from .utils import nanmean, nansum
def scale_thresed_sigmoid(x, scale=1.0, thres=0.0):
return (scale * (x - thres)).sigmoid()
def scale_2sigmoid(x, scale=1.0):
return 2. * (scale * x).sigmoid() - 1.
def fast_softmax(x, dim, eps=1e-12):
x = F.relu... | 5,067 | 29.902439 | 124 | py |
SemFormer | SemFormer-main/core/functional/utils.py | import torch
import torch.nn.functional as F
def check_all(x, func):
return torch.all(func(x))
def all_in(x, min, max):
return check_all(x, lambda x: (x >= min) & (x <= max))
def all_pos(x):
return check_all(x, lambda x: x > 0)
def all_neg(x):
return check_all(x, lambda x: x < 0)
def all_not_neg(... | 2,843 | 23.101695 | 83 | py |
SemFormer | SemFormer-main/core/functional/convolution.py | import torch
import torch.nn.functional as F
def dynamic_conv2d(self, x, weight, bias=None, stride=1, dilation=1, groups=1, padding=0, return_unview=False):
B, C, H, W = x.shape
C_out, C_in, *kernel_size = weight.shape
assert B * C == C_in
assert C_out % B == 0
# padding = ((K_h - 1) // 2, (K_w -... | 685 | 33.3 | 111 | py |
SemFormer | SemFormer-main/core/functional/__init__.py | from .convolution import dynamic_conv2d
from .fold import unfold_w_center, unfold_wo_center
from .math import (scale_thresed_sigmoid, scale_2sigmoid, fast_softmax,
info_entropy, kl_divergence, js_divergence,
dot_product, jsd_mutual_information,
fast_cosine_simila... | 786 | 64.583333 | 84 | py |
SemFormer | SemFormer-main/core/functional/padding.py | import torch
import torch.nn.functional as F
from torch.nn.modules.utils import _pair
import math
# code modified from mmcv
def same_pad2d(x, kernel_size, stride=1, dilation=1, pad_mode='corner'):
kernel_size = _pair(kernel_size)
stride = _pair(stride)
dilation = _pair(dilation)
img_h, img_w = x.siz... | 2,132 | 27.065789 | 86 | py |
SemFormer | SemFormer-main/core/functional/fold.py | import torch
import torch.nn.functional as F
def unfold_w_center(x, kernel_size, dilation):
assert x.dim() == 4
assert kernel_size % 2 == 1
# using SAME padding
padding = (kernel_size + (dilation - 1) * (kernel_size - 1)) // 2
unfolded_x = F.unfold(
x, kernel_size=kernel_size,
pa... | 1,301 | 24.038462 | 71 | py |
NerveNet | NerveNet-master/__init__.py | 0 | 0 | 0 | py | |
NerveNet | NerveNet-master/config/init_path.py | ../tool/init_path.py | 20 | 20 | 20 | py |
NerveNet | NerveNet-master/config/config.py | # ------------------------------------------------------------------------------
# @brief:
# record the parameters here
# @author:
# Tingwu Wang, 2017, June, 12th
# ------------------------------------------------------------------------------
import argparse
import init_path
def get_config():
# ... | 10,336 | 47.07907 | 81 | py |
NerveNet | NerveNet-master/config/__init__.py | 0 | 0 | 0 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.