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 |
|---|---|---|---|---|---|---|
MRE-ISE | MRE-ISE-main/VSG/VG_parser/dataloaders/__init__.py | 0 | 0 | 0 | py | |
MRE-ISE | MRE-ISE-main/VSG/VG_parser/dataloaders/mscoco.py | from config import COCO_PATH, IM_SCALE, BOX_SCALE
import os
from torch.utils.data import Dataset
from pycocotools.coco import COCO
from PIL import Image
from lib.fpn.anchor_targets import anchor_target_layer
from torchvision.transforms import Resize, Compose, ToTensor, Normalize
from dataloaders.image_transforms import... | 6,783 | 34.518325 | 125 | py |
MRE-ISE | MRE-ISE-main/VSG/VG_parser/dataloaders/image_transforms.py | # Some image transforms
from PIL import Image, ImageOps, ImageFilter, ImageEnhance
import numpy as np
from random import randint
# All of these need to be called on PIL imagez
class SquarePad(object):
def __call__(self, img):
w, h = img.size
img_padded = ImageOps.expand(img, border=(0, 0, max(h - ... | 4,172 | 30.613636 | 123 | py |
MRE-ISE | MRE-ISE-main/VSG/VG_parser/misc/motifs.py | """
SCRIPT TO MAKE MEMES. this was from an old version of the code, so it might require some fixes to get working.
"""
from dataloaders.visual_genome import VG
# import matplotlib
# # matplotlib.use('Agg')
from tqdm import tqdm
import seaborn as sns
import numpy as np
from lib.fpn.box_intersections_cpu.bbox import bbo... | 7,142 | 28.395062 | 110 | py |
MRE-ISE | MRE-ISE-main/VSG/VG_parser/misc/__init__.py | 0 | 0 | 0 | py | |
MRE-ISE | MRE-ISE-main/VSG/VG_parser/lib/rel_model_stanford.py | """
Let's get the relationships yo
"""
import torch
import torch.nn as nn
import torch.nn.parallel
from torch.autograd import Variable
from torch.nn import functional as F
from lib.surgery import filter_dets
from lib.fpn.proposal_assignments.rel_assignments import rel_assignments
from lib.pytorch_misc import arange
fr... | 9,332 | 44.305825 | 109 | py |
MRE-ISE | MRE-ISE-main/VSG/VG_parser/lib/pytorch_misc.py | """
Miscellaneous functions that might be useful for pytorch
"""
import h5py
import numpy as np
import torch
from torch.autograd import Variable
import os
import dill as pkl
from itertools import tee
from torch import nn
def optimistic_restore(network, state_dict):
mismatch = False
own_state = network.state_d... | 14,457 | 30.430435 | 110 | py |
MRE-ISE | MRE-ISE-main/VSG/VG_parser/lib/get_dataset_counts.py | """
Get counts of all of the examples in the example_dataset. Used for creating the baseline
dictionary model
"""
import numpy as np
from dataloaders.visual_genome import VG
from lib.fpn.box_intersections_cpu.bbox import bbox_overlaps
from lib.pytorch_misc import nonintersecting_2d_inds
def get_counts(train_data=VG(... | 2,293 | 31.309859 | 109 | py |
MRE-ISE | MRE-ISE-main/VSG/VG_parser/lib/resnet.py | import torch.nn as nn
import math
import torch.utils.model_zoo as model_zoo
from torchvision.models.resnet import model_urls, conv3x3, BasicBlock
from torchvision.models.vgg import vgg16
from config import BATCHNORM_MOMENTUM
class Bottleneck(nn.Module):
expansion = 4
def __init__(self, inplanes, planes, strid... | 4,805 | 31.693878 | 86 | py |
MRE-ISE | MRE-ISE-main/VSG/VG_parser/lib/rel_model.py | """
Let's get the relationships yo
"""
import numpy as np
import torch
import torch.nn as nn
import torch.nn.parallel
from torch.autograd import Variable
from torch.nn import functional as F
from torch.nn.utils.rnn import PackedSequence
from lib.resnet import resnet_l4
from config import BATCHNORM_MOMENTUM
from lib.fp... | 23,579 | 41.032086 | 136 | py |
MRE-ISE | MRE-ISE-main/VSG/VG_parser/lib/word_vectors.py | """
Adapted from PyTorch's text library.
"""
import array
import os
import zipfile
import six
import torch
from six.moves.urllib.request import urlretrieve
from tqdm import tqdm
from config import DATA_PATH
import sys
def obj_edge_vectors(names, wv_type='glove.6B', wv_dir=DATA_PATH, wv_dim=300):
wv_dict, wv_arr... | 4,711 | 34.428571 | 96 | py |
MRE-ISE | MRE-ISE-main/VSG/VG_parser/lib/object_detector.py | import numpy as np
import torch
import torch.nn as nn
import torch.nn.parallel
from torch.autograd import Variable
from torch.nn import functional as F
from config import ANCHOR_SIZE, ANCHOR_RATIOS, ANCHOR_SCALES
from lib.fpn.generate_anchors import generate_anchors
from lib.fpn.box_utils import bbox_preds, center_siz... | 25,429 | 39.11041 | 119 | py |
MRE-ISE | MRE-ISE-main/VSG/VG_parser/lib/get_union_boxes.py | """
credits to https://github.com/ruotianluo/pytorch-faster-rcnn/blob/master/lib/nets/network.py#L91
"""
import torch
from torch.autograd import Variable
from torch.nn import functional as F
from lib.fpn.roi_align.functions.roi_align import RoIAlignFunction
from lib.draw_rectangles.draw_rectangles import draw_union_bo... | 3,235 | 39.45 | 114 | py |
MRE-ISE | MRE-ISE-main/VSG/VG_parser/lib/__init__.py | 0 | 0 | 0 | py | |
MRE-ISE | MRE-ISE-main/VSG/VG_parser/lib/sparse_targets.py | from lib.word_vectors import obj_edge_vectors
import torch.nn as nn
import torch
from torch.autograd import Variable
import numpy as np
from config import DATA_PATH
import os
from lib.get_dataset_counts import get_counts
class FrequencyBias(nn.Module):
"""
The goal of this is to provide a simplified way of co... | 1,718 | 31.433962 | 87 | py |
MRE-ISE | MRE-ISE-main/VSG/VG_parser/lib/surgery.py | # create predictions from the other stuff
"""
Go from proposals + scores to relationships.
pred-cls: No bbox regression, obj dist is exactly known
sg-cls : No bbox regression
sg-det : Bbox regression
in all cases we'll return:
boxes, objs, rels, pred_scores
"""
import numpy as np
import torch
from lib.pytorch_misc ... | 2,059 | 33.333333 | 100 | py |
MRE-ISE | MRE-ISE-main/VSG/VG_parser/lib/evaluation/sg_eval_slow.py | # JUST TO CHECK THAT IT IS EXACTLY THE SAME..................................
import numpy as np
from config import MODES
class BasicSceneGraphEvaluator:
def __init__(self, mode):
self.result_dict = {}
self.mode = {'sgdet':'sg_det', 'sgcls':'sg_cls', 'predcls':'pred_cls'}[mode]
self.resul... | 7,743 | 35.018605 | 85 | py |
MRE-ISE | MRE-ISE-main/VSG/VG_parser/lib/evaluation/sg_eval.py | """
Adapted from Danfei Xu. In particular, slow code was removed
"""
import numpy as np
from functools import reduce
from lib.pytorch_misc import intersect_2d, argsort_desc
from lib.fpn.box_intersections_cpu.bbox import bbox_overlaps
from config import MODES
np.set_printoptions(precision=3)
class BasicSceneGraphEvalua... | 11,883 | 40.698246 | 111 | py |
MRE-ISE | MRE-ISE-main/VSG/VG_parser/lib/evaluation/test_sg_eval.py | # Just some tests so you can be assured that sg_eval.py works the same as the (original) stanford evaluation
import numpy as np
from six.moves import xrange
from dataloaders.visual_genome import VG
from lib.evaluation.sg_eval import evaluate_from_dict
from tqdm import trange
from lib.fpn.box_utils import center_size, ... | 9,840 | 39.004065 | 129 | py |
MRE-ISE | MRE-ISE-main/VSG/VG_parser/lib/evaluation/__init__.py | 0 | 0 | 0 | py | |
MRE-ISE | MRE-ISE-main/VSG/VG_parser/lib/evaluation/sg_eval_all_rel_cates.py | """
Adapted from Danfei Xu. In particular, slow code was removed
"""
import numpy as np
from functools import reduce
from lib.pytorch_misc import intersect_2d, argsort_desc
from lib.fpn.box_intersections_cpu.bbox import bbox_overlaps
from config import MODES
import sys
np.set_printoptions(precision=3)
class BasicScene... | 14,355 | 39.439437 | 135 | py |
MRE-ISE | MRE-ISE-main/VSG/VG_parser/lib/lstm/decoder_rnn.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.autograd import Variable
from torch.nn.utils.rnn import PackedSequence
from typing import Optional, Tuple
from lib.fpn.box_utils import nms_overlaps
from lib.word_vectors import obj_edge_vectors
from .highway_lstm_cuda.alternating_highway_ls... | 12,192 | 47.384921 | 109 | py |
MRE-ISE | MRE-ISE-main/VSG/VG_parser/lib/lstm/__init__.py | 0 | 0 | 0 | py | |
MRE-ISE | MRE-ISE-main/VSG/VG_parser/lib/lstm/highway_lstm_cuda/alternating_highway_lstm.py | from typing import Tuple
from overrides import overrides
import torch
from torch.autograd import Function, Variable
from torch.nn import Parameter
from torch.nn.utils.rnn import PackedSequence, pad_packed_sequence, pack_padded_sequence
import itertools
from ._ext import highway_lstm_layer
def block_orthogonal(tensor... | 15,176 | 48.924342 | 109 | py |
MRE-ISE | MRE-ISE-main/VSG/VG_parser/lib/lstm/highway_lstm_cuda/__init__.py | 0 | 0 | 0 | py | |
MRE-ISE | MRE-ISE-main/VSG/VG_parser/lib/lstm/highway_lstm_cuda/build.py | # pylint: disable=invalid-name
import os
import torch
from torch.utils.ffi import create_extension
if not torch.cuda.is_available():
raise Exception('HighwayLSTM can only be compiled with CUDA')
sources = ['src/highway_lstm_cuda.c']
headers = ['src/highway_lstm_cuda.h']
defines = [('WITH_CUDA', None)]
with_cuda =... | 798 | 25.633333 | 75 | py |
MRE-ISE | MRE-ISE-main/VSG/VG_parser/lib/lstm/highway_lstm_cuda/_ext/__init__.py | 0 | 0 | 0 | py | |
MRE-ISE | MRE-ISE-main/VSG/VG_parser/lib/lstm/highway_lstm_cuda/_ext/highway_lstm_layer/__init__.py |
from torch.utils.ffi import _wrap_function
from ._highway_lstm_layer import lib as _lib, ffi as _ffi
__all__ = []
def _import_symbols(locals):
for symbol in dir(_lib):
fn = getattr(_lib, symbol)
locals[symbol] = _wrap_function(fn, _ffi)
__all__.append(symbol)
_import_symbols(locals())
| 317 | 23.461538 | 57 | py |
MRE-ISE | MRE-ISE-main/VSG/VG_parser/lib/fpn/box_utils.py | import torch
import numpy as np
from torch.nn import functional as F
from lib.fpn.box_intersections_cpu.bbox import bbox_overlaps as bbox_overlaps_np
from lib.fpn.box_intersections_cpu.bbox import bbox_intersections as bbox_intersections_np
def bbox_loss(prior_boxes, deltas, gt_boxes, eps=1e-4, scale_before=1):
"... | 5,965 | 37.24359 | 98 | py |
MRE-ISE | MRE-ISE-main/VSG/VG_parser/lib/fpn/generate_anchors.py | # --------------------------------------------------------
# Faster R-CNN
# Copyright (c) 2015 Microsoft
# Licensed under The MIT License [see LICENSE for details]
# Written by Ross Girshick and Sean Bell
# --------------------------------------------------------
from config import IM_SCALE
import numpy as np
def g... | 2,824 | 29.053191 | 101 | py |
MRE-ISE | MRE-ISE-main/VSG/VG_parser/lib/fpn/anchor_targets.py | """
Generates anchor targets to train the detector. Does this during the collate step in training
as it's much cheaper to do this on a separate thread.
Heavily adapted from faster_rcnn/rpn_msr/anchor_target_layer.py.
"""
import numpy as np
import numpy.random as npr
from config import IM_SCALE, RPN_NEGATIVE_OVERLAP, ... | 4,047 | 40.306122 | 118 | py |
MRE-ISE | MRE-ISE-main/VSG/VG_parser/lib/fpn/proposal_assignments/proposal_assignments_rel.py | # --------------------------------------------------------
# Goal: assign ROIs to targets
# --------------------------------------------------------
import numpy as np
import numpy.random as npr
from config import BG_THRESH_HI, BG_THRESH_LO, FG_FRACTION_REL, ROIS_PER_IMG_REL, REL_FG_FRACTION, \
RELS_PER_IMG
from ... | 9,678 | 41.451754 | 150 | py |
MRE-ISE | MRE-ISE-main/VSG/VG_parser/lib/fpn/proposal_assignments/proposal_assignments_gtbox.py | from lib.pytorch_misc import enumerate_by_image, gather_nd, random_choose
from lib.fpn.box_utils import bbox_preds, center_size, bbox_overlaps
import torch
from lib.pytorch_misc import diagonal_inds, to_variable
from config import RELS_PER_IMG, REL_FG_FRACTION
@to_variable
def proposal_assignments_gtbox(rois, gt_boxe... | 3,434 | 38.034091 | 97 | py |
MRE-ISE | MRE-ISE-main/VSG/VG_parser/lib/fpn/proposal_assignments/rel_assignments.py | # --------------------------------------------------------
# Goal: assign ROIs to targets
# --------------------------------------------------------
import numpy as np
import numpy.random as npr
from config import BG_THRESH_HI, BG_THRESH_LO, REL_FG_FRACTION, RELS_PER_IMG_REFINE
from lib.fpn.box_utils import bbox_over... | 6,381 | 42.712329 | 98 | py |
MRE-ISE | MRE-ISE-main/VSG/VG_parser/lib/fpn/proposal_assignments/proposal_assignments_det.py |
import numpy as np
import numpy.random as npr
from config import BG_THRESH_HI, BG_THRESH_LO, FG_FRACTION, ROIS_PER_IMG
from lib.fpn.box_utils import bbox_overlaps
from lib.pytorch_misc import to_variable
import torch
#############################################################
# The following is only for object dete... | 4,477 | 36.949153 | 98 | py |
MRE-ISE | MRE-ISE-main/VSG/VG_parser/lib/fpn/proposal_assignments/proposal_assignments_postnms.py | # --------------------------------------------------------
# Goal: assign ROIs to targets
# --------------------------------------------------------
import numpy as np
import numpy.random as npr
from .proposal_assignments_rel import _sel_rels
from lib.fpn.box_utils import bbox_overlaps
from lib.pytorch_misc import to... | 5,420 | 39.455224 | 100 | py |
MRE-ISE | MRE-ISE-main/VSG/VG_parser/lib/fpn/box_intersections_cpu/setup.py | from distutils.core import setup
from Cython.Build import cythonize
import numpy
setup(name="bbox_cython", ext_modules=cythonize('bbox.pyx'), include_dirs=[numpy.get_include()]) | 178 | 34.8 | 96 | py |
MRE-ISE | MRE-ISE-main/VSG/VG_parser/lib/fpn/roi_align/__init__.py | 0 | 0 | 0 | py | |
MRE-ISE | MRE-ISE-main/VSG/VG_parser/lib/fpn/roi_align/build.py | import os
import torch
from torch.utils.ffi import create_extension
# Might have to export PATH=/usr/local/cuda-8.0/bin${PATH:+:${PATH}}
# sources = ['src/roi_align.c']
# headers = ['src/roi_align.h']
sources = []
headers = []
defines = []
with_cuda = False
if torch.cuda.is_available():
print('Including CUDA code... | 901 | 23.378378 | 75 | py |
MRE-ISE | MRE-ISE-main/VSG/VG_parser/lib/fpn/roi_align/functions/roi_align.py | """
performs ROI aligning
"""
import torch
from torch.autograd import Function
from .._ext import roi_align
class RoIAlignFunction(Function):
def __init__(self, aligned_height, aligned_width, spatial_scale):
self.aligned_width = int(aligned_width)
self.aligned_height = int(aligned_height)
... | 2,455 | 31.746667 | 79 | py |
MRE-ISE | MRE-ISE-main/VSG/VG_parser/lib/fpn/roi_align/functions/__init__.py | 0 | 0 | 0 | py | |
MRE-ISE | MRE-ISE-main/VSG/VG_parser/lib/fpn/roi_align/modules/roi_align.py | from torch.nn.modules.module import Module
from torch.nn.functional import avg_pool2d, max_pool2d
from ..functions.roi_align import RoIAlignFunction
class RoIAlign(Module):
def __init__(self, aligned_height, aligned_width, spatial_scale):
super(RoIAlign, self).__init__()
self.aligned_width = int(... | 1,672 | 37.906977 | 74 | py |
MRE-ISE | MRE-ISE-main/VSG/VG_parser/lib/fpn/roi_align/modules/__init__.py | 0 | 0 | 0 | py | |
MRE-ISE | MRE-ISE-main/VSG/VG_parser/lib/fpn/roi_align/_ext/__init__.py | 0 | 0 | 0 | py | |
MRE-ISE | MRE-ISE-main/VSG/VG_parser/lib/fpn/roi_align/_ext/roi_align/__init__.py |
from torch.utils.ffi import _wrap_function
from ._roi_align import lib as _lib, ffi as _ffi
__all__ = []
def _import_symbols(locals):
for symbol in dir(_lib):
fn = getattr(_lib, symbol)
locals[symbol] = _wrap_function(fn, _ffi)
__all__.append(symbol)
_import_symbols(locals())
| 308 | 22.769231 | 49 | py |
MRE-ISE | MRE-ISE-main/VSG/VG_parser/lib/fpn/nms/build.py | import os
import torch
from torch.utils.ffi import create_extension
# Might have to export PATH=/usr/local/cuda-8.0/bin${PATH:+:${PATH}}
sources = []
headers = []
defines = []
with_cuda = False
if torch.cuda.is_available():
print('Including CUDA code.')
sources += ['src/nms_cuda.c']
headers += ['src/nms_c... | 814 | 21.638889 | 75 | py |
MRE-ISE | MRE-ISE-main/VSG/VG_parser/lib/fpn/nms/functions/nms.py | # Le code for doing NMS
import torch
import numpy as np
from .._ext import nms
def apply_nms(scores, boxes, pre_nms_topn=12000, post_nms_topn=2000, boxes_per_im=None,
nms_thresh=0.7):
"""
Note - this function is non-differentiable so everything is assumed to be a tensor, not
a variable.
... | 1,312 | 27.543478 | 98 | py |
MRE-ISE | MRE-ISE-main/processor/create_bow.py | import numpy as np
import os
from sklearn.cluster import KMeans
from PIL import Image
import cv2
import pickle
from transformers import CLIPModel, CLIPProcessor
import torch
import json
from tqdm import tqdm
from sklearn.feature_extraction.text import CountVectorizer
from nltk.corpus import stopwords as stop_words
from... | 9,510 | 38.962185 | 113 | py |
MRE-ISE | MRE-ISE-main/processor/dataset.py | import pickle
import random
import os
import numpy as np
import torch
import json
import ast
from PIL import Image
from torch.utils.data import Dataset, DataLoader
from transformers import BertTokenizer
from torchvision import transforms
from transformers import CLIPTokenizer
from torch_geometric.utils import to_dense... | 12,476 | 42.024138 | 120 | py |
MRE-ISE | MRE-ISE-main/cores/__init__.py | 0 | 0 | 0 | py | |
MRE-ISE | MRE-ISE-main/cores/lamo/decoding_network.py | import torch
from torch import nn
from torch.nn import functional as F
from cores.lamo.inference_network import CombinedInferenceNetwork, ContextualInferenceNetwork
class DecoderNetwork(nn.Module):
def __init__(self, text_input_size, visual_input_size, bert_size, infnet, n_components=10, model_type='prodLDA',
... | 7,129 | 39.977011 | 125 | py |
MRE-ISE | MRE-ISE-main/cores/lamo/ctm.py | import datetime
import multiprocessing as mp
import os
import warnings
from collections import defaultdict
import matplotlib.pyplot as plt
import numpy as np
import torch
import wordcloud
from scipy.special import softmax
from torch import optim
from torch.optim.lr_scheduler import ReduceLROnPlateau
from torch.utils.da... | 30,164 | 41.545839 | 167 | py |
MRE-ISE | MRE-ISE-main/cores/lamo/early_stopping.py | import numpy as np
import torch
class EarlyStopping:
"""Early stops the training if validation loss doesn't improve after a given patience.
Source code: https://github.com/Bjarten/early-stopping-pytorch """
def __init__(self, patience=7, verbose=False, delta=0, path='checkpoint.pt', trace_func=print):
... | 2,353 | 36.967742 | 121 | py |
MRE-ISE | MRE-ISE-main/cores/lamo/inference_network.py | from collections import OrderedDict
from torch import nn
import torch
class ContextualInferenceNetwork(nn.Module):
"""Inference Network."""
def __init__(self, text_input_size, visual_input_size, bert_size, output_size, hidden_sizes,
activation='softplus', dropout=0.2, label_size=0):
... | 5,742 | 37.033113 | 103 | py |
MRE-ISE | MRE-ISE-main/cores/lamo/__init__.py | 0 | 0 | 0 | py | |
MRE-ISE | MRE-ISE-main/cores/lamo/evaluation/measures.py | from gensim.corpora.dictionary import Dictionary
from gensim.models.coherencemodel import CoherenceModel
from gensim.models import KeyedVectors
import gensim.downloader as api
from scipy.spatial.distance import cosine
import abc
from contextualized_topic_models.evaluation.rbo import rbo
import numpy as np
import itert... | 12,526 | 35.415698 | 79 | py |
MRE-ISE | MRE-ISE-main/cores/lamo/evaluation/__init__.py | 0 | 0 | 0 | py | |
MRE-ISE | MRE-ISE-main/cores/lamo/evaluation/rbo/__init__.py | 0 | 0 | 0 | py | |
MRE-ISE | MRE-ISE-main/cores/lamo/evaluation/rbo/rbo.py | """Rank-biased overlap, a ragged sorted list similarity measure.
See http://doi.acm.org/10.1145/1852102.1852106 for details. All functions
directly corresponding to concepts from the paper are named so that they can be
clearly cross-identified.
The definition of overlap has been modified to account for ties. Without ... | 10,640 | 31.944272 | 87 | py |
MRE-ISE | MRE-ISE-main/cores/gene/model.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.autograd import Variable
from torch_geometric.utils import dense_to_sparse
from cores.gene.backbone import GAT, FustionLayer, GraphLearner
from cores.lamo.decoding_network import DecoderNetwork
class MRE(nn.Module):
def __init__(self, a... | 11,439 | 47.680851 | 137 | py |
MRE-ISE | MRE-ISE-main/cores/gene/backbone.py | import math
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch import linalg as LA
from torch.autograd import Variable
from torch_geometric.utils import to_dense_adj, dense_to_sparse
from torch.distributions.relaxed_bernoulli import RelaxedBernoulli, LogitRelaxedBernoulli
from torch.distribut... | 21,984 | 43.414141 | 161 | py |
MRE-ISE | MRE-ISE-main/cores/gene/train.py | import pickle
import torch
import torch.nn as nn
from torch import optim
from tqdm import tqdm
from sklearn.metrics import classification_report
from transformers.optimization import get_linear_schedule_with_warmup
from modules.metrics import eval_result
import math
class Trainer(object):
def __init__(self, train... | 14,294 | 56.874494 | 122 | py |
MRE-ISE | MRE-ISE-main/TSG/textual_scene_graph.py | import os
import json
import subprocess
import threading
import json
import numpy as np
import ast
import tempfile
import re
def load_data(filename):
res = []
with open(filename, mode='r') as f:
for line in f:
json_line = ast.literal_eval(line)
res.append(json_line)
return ... | 5,031 | 32.105263 | 125 | py |
latex2mathml | latex2mathml-master/example.py | from latex2mathml.converter import convert
def convert_to_mathml(latex_input):
mathml_output = convert(latex_input)
print(mathml_output)
if __name__ == "__main__":
convert_to_mathml(r"x = {-b \pm \sqrt{b^2-4ac} \over 2a}")
| 239 | 20.818182 | 62 | py |
latex2mathml | latex2mathml-master/tests/test_symbol_parser.py | import pytest
from latex2mathml.symbols_parser import convert_symbol
@pytest.mark.parametrize(
"latex, expected",
[pytest.param("+", "0002B", id="operator-plus"), pytest.param(r"\to", "02192", id="alias-command")],
)
def test_convert_symbol(latex: str, expected: str) -> None:
assert convert_symbol(latex)... | 333 | 26.833333 | 104 | py |
latex2mathml | latex2mathml-master/tests/test_converter.py | import pytest
from multidict import MultiDict
from xmljson import BadgerFish
# noinspection PyProtectedMember
from latex2mathml.converter import _convert, convert
@pytest.mark.parametrize(
"latex, json",
[
pytest.param("x", {"mi": "x"}, id="single-identifier"),
pytest.param("xyz", MultiDict([... | 178,944 | 41.44426 | 120 | py |
latex2mathml | latex2mathml-master/tests/test_walker.py | import string
from typing import Any, Tuple, Union
import pytest
from latex2mathml.exceptions import (
DenominatorNotFoundError,
DoubleSubscriptsError,
DoubleSuperscriptsError,
ExtraLeftOrMissingRightError,
InvalidAlignmentError,
InvalidStyleForGenfracError,
InvalidWidthError,
LimitsMu... | 70,402 | 39.070006 | 120 | py |
latex2mathml | latex2mathml-master/tests/__init__.py | 0 | 0 | 0 | py | |
latex2mathml | latex2mathml-master/tests/test_tokenizer.py | import string
import pytest
from latex2mathml.tokenizer import tokenize
@pytest.mark.parametrize(
"latex, expected",
[
pytest.param("\\", ["\\"], id="single-backslash"),
pytest.param(string.ascii_letters, list(string.ascii_letters), id="alphabets"),
pytest.param(string.digits, [strin... | 14,921 | 27.314991 | 120 | py |
latex2mathml | latex2mathml-master/latex2mathml/exceptions.py | class NumeratorNotFoundError(Exception):
pass
class DenominatorNotFoundError(Exception):
pass
class ExtraLeftOrMissingRightError(Exception):
pass
class MissingSuperScriptOrSubscriptError(Exception):
pass
class DoubleSubscriptsError(Exception):
pass
class DoubleSuperscriptsError(Exception):... | 645 | 12.744681 | 52 | py |
latex2mathml | latex2mathml-master/latex2mathml/walker.py | from typing import Any, Dict, Iterator, List, NamedTuple, Optional, Tuple
from latex2mathml import commands
from latex2mathml.exceptions import (
DenominatorNotFoundError,
DoubleSubscriptsError,
DoubleSuperscriptsError,
ExtraLeftOrMissingRightError,
InvalidAlignmentError,
InvalidStyleForGenfrac... | 19,969 | 42.60262 | 120 | py |
latex2mathml | latex2mathml-master/latex2mathml/symbols_parser.py | import codecs
import os
import re
from typing import Dict, Optional, Union
SYMBOLS_FILE: str = os.path.join(os.path.dirname(os.path.realpath(__file__)), "unimathsymbols.txt")
SYMBOLS: Optional[Dict[str, str]] = None
def convert_symbol(symbol: str) -> Union[str, None]:
global SYMBOLS
if not SYMBOLS:
S... | 2,954 | 36.405063 | 99 | py |
latex2mathml | latex2mathml-master/latex2mathml/commands.py | from collections import OrderedDict, defaultdict
from typing import DefaultDict, Dict, Optional, Tuple
OPENING_BRACE = "{"
CLOSING_BRACE = "}"
BRACES = "{}"
OPENING_BRACKET = "["
CLOSING_BRACKET = "]"
BRACKETS = "[]"
OPENING_PARENTHESIS = "("
CLOSING_PARENTHESIS = ")"
PARENTHESES = "()"
SUBSUP = "_^"
SUBSCRIPT = "_... | 13,087 | 24.814596 | 119 | py |
latex2mathml | latex2mathml-master/latex2mathml/tokenizer.py | import re
from typing import Iterator
from latex2mathml import commands
from latex2mathml.symbols_parser import convert_symbol
UNITS = ("in", "mm", "cm", "pt", "em", "ex", "pc", "bp", "dd", "cc", "sp", "mu")
PATTERN = re.compile(
rf"""
(%[^\n]+) | # comment
(a-zA-Z) | ... | 2,360 | 41.160714 | 100 | py |
latex2mathml | latex2mathml-master/latex2mathml/converter.py | import copy
import enum
import re
from collections import OrderedDict
from typing import Dict, Iterable, Iterator, List, Optional, Tuple
from xml.etree.cElementTree import Element, SubElement, tostring
from xml.sax.saxutils import unescape
from latex2mathml import commands
from latex2mathml.symbols_parser import conve... | 22,814 | 38.404145 | 120 | py |
latex2mathml | latex2mathml-master/latex2mathml/__init__.py | from importlib import metadata
__version__ = metadata.version("latex2mathml")
| 79 | 19 | 46 | py |
zorba | zorba-master/swig/python/tests/test04.py | # Copyright 2006-2016 zorba.io
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,... | 1,076 | 24.046512 | 74 | py |
zorba | zorba-master/swig/python/tests/test05.py | # Copyright 2006-2016 zorba.io
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,... | 1,100 | 24.604651 | 74 | py |
zorba | zorba-master/swig/python/tests/test02.py | # Copyright 2006-2016 zorba.io
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,... | 1,102 | 25.261905 | 74 | py |
zorba | zorba-master/swig/python/tests/test14.py | # Copyright 2006-2016 zorba.io
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,... | 1,488 | 28.196078 | 115 | py |
zorba | zorba-master/swig/python/tests/test12.py | # Copyright 2006-2016 zorba.io
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,... | 1,579 | 29.384615 | 94 | py |
zorba | zorba-master/swig/python/tests/test01.py | # Copyright 2006-2016 zorba.io
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,... | 854 | 30.666667 | 74 | py |
zorba | zorba-master/swig/python/tests/test10.py | # Copyright 2006-2016 zorba.io
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,... | 1,318 | 24.365385 | 76 | py |
zorba | zorba-master/swig/python/tests/test08.py | # Copyright 2006-2016 zorba.io
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,... | 3,432 | 29.651786 | 132 | py |
zorba | zorba-master/swig/python/tests/test11.py | # Copyright 2006-2016 zorba.io
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,... | 1,404 | 31.674419 | 92 | py |
zorba | zorba-master/swig/python/tests/test07.1.py | # Copyright 2006-2016 zorba.io
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,... | 1,377 | 24.054545 | 74 | py |
zorba | zorba-master/swig/python/tests/test07.2.py | # Copyright 2006-2016 zorba.io
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,... | 2,516 | 29.695122 | 92 | py |
zorba | zorba-master/swig/python/tests/test03.py | # Copyright 2006-2016 zorba.io
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,... | 1,247 | 27.363636 | 74 | py |
zorba | zorba-master/swig/python/tests/test06.py | # Copyright 2006-2016 zorba.io
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,... | 1,100 | 24.604651 | 74 | py |
zorba | zorba-master/scripts/cmake.py | """
# Copyright 2006-2016 zorba.io
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing... | 2,105 | 38 | 94 | py |
DEAT | DEAT-main/preactresnet.py | '''Pre-activation ResNet in PyTorch.
Reference:
[1] Kaiming He, Xiangyu Zhang, Shaoqing Ren, Jian Sun
Identity Mappings in Deep Residual Networks. arXiv:1603.05027
'''
import torch
import torch.nn as nn
import torch.nn.functional as F
track_running_stats=True
affine=True
normal_func = nn.BatchNorm2d
# track_runn... | 7,760 | 37.044118 | 152 | py |
DEAT | DEAT-main/utils.py | import numpy as np
from collections import namedtuple
import torch
from torch import nn
import torchvision
from torch.optim.optimizer import Optimizer, required
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
################################################################
## Components from htt... | 9,103 | 34.84252 | 122 | py |
DEAT | DEAT-main/train_cifar_DEAT.py | import argparse
import logging
import sys
import time
import math
import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.autograd import Variable
from Positive_Negative_Momentum.pnm_optim import *
import os
from wideresnet import WideResNet
from preactresnet import PreActRe... | 40,722 | 41.287643 | 208 | py |
DEAT | DEAT-main/eval_cifar.py | import argparse
import copy
import logging
import os
import time
import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
from preactresnet import PreActResNet18
from wideresnet import WideResNet
from utils_plus import (upper_limit, lower_limit, std, clamp, get_loaders,
attack_pgd, ev... | 3,080 | 32.129032 | 119 | py |
DEAT | DEAT-main/utils_plus.py | #import apex.amp as amp
import torch
import torch.nn.functional as F
from torchvision import datasets, transforms
from torch.utils.data.sampler import SubsetRandomSampler
import numpy as np
upper_limit, lower_limit = 1, 0
cifar10_mean = (0.4914, 0.4822, 0.4465)
cifar10_std = (0.2471, 0.2435, 0.2616)
mu = torch.tensor... | 4,589 | 34.307692 | 106 | py |
DEAT | DEAT-main/train_cifar.py | import argparse
import logging
import sys
import time
import math
import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.autograd import Variable
import os
from wideresnet import WideResNet
from preactresnet import PreActResNet18, PreActResNet50
from models import *
from ut... | 39,863 | 40.962105 | 208 | py |
DEAT | DEAT-main/wideresnet.py | import math
import torch
import torch.nn as nn
import torch.nn.functional as F
class BasicBlock(nn.Module):
def __init__(self, in_planes, out_planes, stride, dropRate=0.0, activation='ReLU', softplus_beta=1):
super(BasicBlock, self).__init__()
self.bn1 = nn.BatchNorm2d(in_planes)
self.conv1 ... | 5,747 | 43.90625 | 141 | py |
DEAT | DEAT-main/models/shufflenetv2.py | '''ShuffleNetV2 in PyTorch.
See the paper "ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design" for more details.
'''
import torch
import torch.nn as nn
import torch.nn.functional as F
class ShuffleBlock(nn.Module):
def __init__(self, groups=2):
super(ShuffleBlock, self).__init__()
... | 5,530 | 32.932515 | 107 | py |
DEAT | DEAT-main/models/regnet.py | '''RegNet in PyTorch.
Paper: "Designing Network Design Spaces".
Reference: https://github.com/keras-team/keras-applications/blob/master/keras_applications/efficientnet.py
'''
import torch
import torch.nn as nn
import torch.nn.functional as F
class SE(nn.Module):
'''Squeeze-and-Excitation block.'''
def __in... | 4,548 | 28.160256 | 106 | py |
DEAT | DEAT-main/models/efficientnet.py | '''EfficientNet in PyTorch.
Paper: "EfficientNet: Rethinking Model Scaling for Convolutional Neural Networks".
Reference: https://github.com/keras-team/keras-applications/blob/master/keras_applications/efficientnet.py
'''
import torch
import torch.nn as nn
import torch.nn.functional as F
def swish(x):
return x ... | 5,719 | 31.5 | 106 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.