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 |
|---|---|---|---|---|---|---|
TREMBA | TREMBA-master/imagenet_model/Resnet.py | import torch.nn as nn
import torch
import math
def conv3x3(in_planes, out_planes, stride=1, groups=1, dilation=1):
"""3x3 convolution with padding"""
return nn.Conv2d(in_planes, out_planes, kernel_size=3, stride=stride,
padding=dilation, groups=groups, bias=False, dilation=dilation)
def ... | 10,508 | 35.113402 | 108 | 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/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/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/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/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/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/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/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 |
tensorflow-onnx | tensorflow-onnx-main/tools/profile_conversion_time.py | # SPDX-License-Identifier: Apache-2.0
# coding: utf-8
"""
Profiles the conversion of a Keras model.
"""
import sys
import cProfile
from pstats import SortKey, Stats
import io
import argparse
import tensorflow as tf
from tensorflow.keras.applications import MobileNet, EfficientNetB2
from tf2onnx import tfonnx
try:
... | 3,675 | 29.890756 | 82 | py |
tensorflow-onnx | tensorflow-onnx-main/examples/end2end_tfhub.py | # SPDX-License-Identifier: Apache-2.0
"""
This example retrieves a model from tensorflowhub.
It is converted into ONNX. Predictions are compared to
the predictions from tensorflow to check there is no
discrepencies. Inferencing time is also compared between
*onnxruntime*, *tensorflow* and *tensorflow.lite*.
"""
from o... | 2,389 | 29.641026 | 68 | py |
tensorflow-onnx | tensorflow-onnx-main/examples/end2end_tfkeras.py | # SPDX-License-Identifier: Apache-2.0
"""
This example builds a simple model without training.
It is converted into ONNX. Predictions are compared to
the predictions from tensorflow to check there is no
discrepencies. Inferencing time is also compared between
*onnxruntime*, *tensorflow* and *tensorflow.lite*.
"""
from... | 2,202 | 29.178082 | 75 | py |
tensorflow-onnx | tensorflow-onnx-main/examples/getting_started.py | # SPDX-License-Identifier: Apache-2.0
"""
This example shows how to convert tf functions and keras models using the Python API.
It also demonstrates converting saved_models from the command line.
"""
import tensorflow as tf
import tf2onnx
import numpy as np
import onnxruntime as ort
import os
##################### t... | 1,673 | 25.15625 | 94 | py |
tensorflow-onnx | tensorflow-onnx-main/tf2onnx/tf_utils.py | # SPDX-License-Identifier: Apache-2.0
"""
tf2onnx.tf_utils - misc utilities for tf2onnx that interface with tensorflow
"""
import collections
from packaging.version import Version
import numpy as np
import tensorflow as tf
from tensorflow.core.framework import types_pb2, tensor_pb2, graph_pb2
from tensorflow.pytho... | 19,760 | 40.514706 | 120 | py |
tensorflow-onnx | tensorflow-onnx-main/tf2onnx/constants.py | # SPDX-License-Identifier: Apache-2.0
"""
common constants
"""
from onnx import helper
TF2ONNX_PACKAGE_NAME = __name__.split('.')[0]
# Built-in supported domains
ONNX_DOMAIN = ""
AI_ONNX_ML_DOMAIN = "ai.onnx.ml"
MICROSOFT_DOMAIN = "com.microsoft"
CONTRIB_OPS_DOMAIN = "ai.onnx.contrib"
# Default opset version for ... | 1,860 | 30.016667 | 119 | py |
tensorflow-onnx | tensorflow-onnx-main/tf2onnx/graph.py | # SPDX-License-Identifier: Apache-2.0
"""
tf2onnx.graph - class to manage graph manipulation on top of onnx
"""
import collections
import copy
import logging
import six
import numpy as np
from onnx import helper, numpy_helper, shape_inference, AttributeProto, TensorProto
from tf2onnx import utils, __version__, git_... | 73,318 | 39.687569 | 120 | py |
tensorflow-onnx | tensorflow-onnx-main/tf2onnx/tfjs_utils.py | # SPDX-License-Identifier: Apache-2.0
"""
tf2onnx.tfjs_utils - utilities for parsing tfjs files into onnx graphs
Main functions of interest are graphs_from_tfjs and read_tfjs_graph
"""
import json
import os
import base64
import gzip
import struct
import logging
from onnx import numpy_helper, helper
import numpy as... | 20,879 | 40.428571 | 118 | py |
tensorflow-onnx | tensorflow-onnx-main/tf2onnx/convert.py | # SPDX-License-Identifier: Apache-2.0
"""
python -m tf2onnx.convert : api and commandline tool to convert a tensorflow model to onnx
"""
# pylint: disable=unused-argument,unused-import,ungrouped-imports,wrong-import-position
import argparse
import os
import sys
from packaging.version import Version
os.environ['TF_... | 32,900 | 45.274262 | 119 | py |
tensorflow-onnx | tensorflow-onnx-main/tf2onnx/keras2onnx_api.py | # SPDX-License-Identifier: Apache-2.0
"""
tf2onnx.keras2onnx_api - Ease migration from keras2onnx to tf2onnx.
Use tf2onnx.keras2onnx_api.convert_keras instead of deprecated keras2onnx.convert_keras
"""
# pylint: disable=unused-argument,missing-docstring
from onnx import mapping, defs
import tensorflow as tf
import t... | 2,350 | 35.169231 | 109 | py |
tensorflow-onnx | tensorflow-onnx-main/tf2onnx/tf_loader.py | # SPDX-License-Identifier: Apache-2.0
"""Methods to load tensorflow graph from graphdef, checkpoint or saved_model."""
import logging
import uuid
from packaging.version import Version
import tensorflow as tf
import numpy as np
from google.protobuf.message import DecodeError
from tensorflow.core.framework import ten... | 36,808 | 45.358942 | 119 | py |
tensorflow-onnx | tensorflow-onnx-main/tf2onnx/onnx_opset/math.py | # SPDX-License-Identifier: Apache-2.0
"""
math
"""
import logging
import numpy as np
from onnx import onnx_pb
from tf2onnx import constants, utils
from tf2onnx.handler import tf_op
from tf2onnx.onnx_opset import common
from tf2onnx.graph_builder import GraphBuilder
logger = logging.getLogger(__name__)
# pylint:... | 49,158 | 45.158685 | 120 | py |
tensorflow-onnx | tensorflow-onnx-main/tf2onnx/onnx_opset/nn.py | # SPDX-License-Identifier: Apache-2.0
"""
nn
"""
import logging
import numpy as np
from onnx import onnx_pb, helper
from onnx.onnx_pb import TensorProto
from tf2onnx import constants, utils
from tf2onnx.graph_builder import GraphBuilder
from tf2onnx.handler import tf_op
from tf2onnx.onnx_opset import common, contro... | 112,073 | 52.598278 | 120 | py |
tensorflow-onnx | tensorflow-onnx-main/tf2onnx/onnx_opset/common.py | # SPDX-License-Identifier: Apache-2.0
"""
common
"""
import logging
from tf2onnx import constants
logger = logging.getLogger(__name__)
# pylint: disable=unused-argument,missing-docstring
class BroadcastOp:
@classmethod
def version_1(cls, ctx, node, **kwargs):
"""Elementwise Ops with broadcast fl... | 2,487 | 36.69697 | 95 | py |
tensorflow-onnx | tensorflow-onnx-main/tf2onnx/rewriter/gru_tf2_rewriter.py | # SPDX-License-Identifier: Apache-2.0
"""
tf2onnx.rewriter.gru_tf2_rewriter - Rewrites GRU pattern used by tf2.
"""
from tf2onnx.graph_matcher import GraphMatcher
from tf2onnx.rewriter.rnn_utils import make_grucell_pattern, keras_gru_pattern
from tf2onnx.tf_loader import find_function
from tf2onnx.rewriter.unit_rnn_... | 7,461 | 42.132948 | 103 | py |
tensorflow-onnx | tensorflow-onnx-main/tf2onnx/rewriter/gru_rewriter.py | # SPDX-License-Identifier: Apache-2.0
"""
tf2onnx.rewriter.gru_rewriter
"""
import logging
import numpy as np
from tf2onnx import utils
from tf2onnx.graph_builder import GraphBuilder
from tf2onnx.rewriter.rnn_utils import RNNUnitType, get_weights_from_const_node
from tf2onnx.rewriter.unit_rnn_rewriter_base import U... | 12,892 | 45.713768 | 116 | py |
tensorflow-onnx | tensorflow-onnx-main/tf2onnx/rewriter/unit_rnn_rewriter_base.py | # SPDX-License-Identifier: Apache-2.0
"""
tf2onnx.rewriter.unit_rnn_rewriter_base
"""
import logging
from tf2onnx.rewriter.loop_rewriter_base import LoopRewriterBase, Context
from tf2onnx.rewriter.rnn_utils import REWRITER_RESULT, get_pattern, \
get_rnn_scope_name, parse_rnn_loop, seq_len_pattern0, seq_len_patt... | 11,475 | 36.503268 | 114 | py |
tensorflow-onnx | tensorflow-onnx-main/tf2onnx/rewriter/rnn_utils.py | # SPDX-License-Identifier: Apache-2.0
"""
tf2onnx.rewriter.rnn_utils - rnn support
"""
from collections import defaultdict
from enum import Enum
import logging
import numpy as np
from tf2onnx import utils
from tf2onnx.graph_builder import GraphBuilder
from tf2onnx.graph_matcher import OpTypePattern # pylint: disabl... | 26,847 | 35.929849 | 118 | py |
tensorflow-onnx | tensorflow-onnx-main/tf2onnx/rewriter/lstm_tf2_rewriter.py | # SPDX-License-Identifier: Apache-2.0
"""
tf2onnx.rewriter.lstm_tf2_rewriter - Rewrites LSTM pattern used by tf2.
"""
import numpy as np
from tf2onnx.graph_matcher import GraphMatcher
from tf2onnx.rewriter.rnn_utils import make_lstm_pattern
from tf2onnx.tf_loader import find_function
from tf2onnx.rewriter.lstm_rewri... | 13,566 | 42.207006 | 112 | py |
tensorflow-onnx | tensorflow-onnx-main/tf2onnx/rewriter/lstm_rewriter.py | # SPDX-License-Identifier: Apache-2.0
"""
tf2onnx.rewriter.lstm_rewriter
"""
import logging
import numpy as np
from tf2onnx import utils
from tf2onnx.graph_builder import GraphBuilder
from tf2onnx.rewriter.rnn_utils import RNNUnitType, get_weights_from_const_node
from tf2onnx.utils import is_tf_concat_op, is_tf_slic... | 20,582 | 43.359914 | 114 | py |
tensorflow-onnx | tensorflow-onnx-main/tests/test_lstm.py | # SPDX-License-Identifier: Apache-2.0
"""Unit Tests for lstm."""
import numpy as np
import tensorflow as tf
from tensorflow.python.ops import init_ops
from tensorflow.python.ops import variable_scope
from backend_test_base import Tf2OnnxBackendTestBase
from common import check_tf_min_version, unittest_main, check_o... | 32,175 | 39.320802 | 119 | py |
tensorflow-onnx | tensorflow-onnx-main/tests/test_api.py | # SPDX-License-Identifier: Apache-2.0
"""Unit tests using onnx backends."""
# pylint: disable=missing-docstring,unused-import
import os
import zipfile
import numpy as np
import tensorflow as tf
from onnx import helper
from common import check_tf_min_version, unittest_main, requires_custom_ops, check_opset_min_ver... | 12,073 | 44.390977 | 119 | py |
tensorflow-onnx | tensorflow-onnx-main/tests/test_example.py | # SPDX-License-Identifier: Apache-2.0
"""Test examples."""
import os
import subprocess
import unittest
from common import check_opset_min_version, check_opset_max_version, check_tf_min_version
class TestExample(unittest.TestCase):
"""test examples"""
def run_example(self, name, expected=None):
"Ex... | 2,053 | 30.6 | 89 | py |
tensorflow-onnx | tensorflow-onnx-main/tests/huggingface.py | # SPDX-License-Identifier: Apache-2.0
"""
Unit tests for huggingface tensorflow transformers.
tested with tf-2.4.1, transformers-4.5.1
"""
# pylint: disable=missing-docstring,invalid-name,unused-argument
# pylint: disable=bad-classmethod-argument,wrong-import-position
# pylint: disable=import-outside-toplevel
impo... | 24,026 | 41.45053 | 117 | py |
tensorflow-onnx | tensorflow-onnx-main/tests/test_backend.py | # SPDX-License-Identifier: Apache-2.0
"""Unit tests using onnx backends."""
import os
import unittest
from itertools import product
import numpy as np
from numpy.testing import assert_almost_equal
from packaging.version import Version
import tensorflow as tf
from tensorflow.python.ops import lookup_ops
from backen... | 305,157 | 47.530216 | 120 | py |
tensorflow-onnx | tensorflow-onnx-main/tests/test_gru.py | # SPDX-License-Identifier: Apache-2.0
"""Unit Tests for gru."""
import numpy as np
import tensorflow as tf
from tensorflow.python.ops import init_ops
from tensorflow.python.ops import variable_scope
from backend_test_base import Tf2OnnxBackendTestBase
from common import * # pylint: disable=wildcard-import,unused-w... | 30,029 | 39.635995 | 118 | py |
tensorflow-onnx | tensorflow-onnx-main/tests/backend_test_base.py | # SPDX-License-Identifier: Apache-2.0
"""Unit Test Base."""
# pylint: disable=missing-docstring,invalid-name,unused-argument,using-constant-test,import-outside-toplevel
# pylint: disable=wrong-import-position,invalid-unary-operand-type
import logging
import os
import unittest
import re
os.environ["TF_CPP_MIN_LOG_L... | 24,541 | 47.791252 | 117 | py |
tensorflow-onnx | tensorflow-onnx-main/tests/common.py | # SPDX-License-Identifier: Apache-2.0
""" test common utilities."""
import argparse
import os
import sys
import unittest
from collections import defaultdict
from packaging.version import Version
from parameterized import parameterized
import timeout_decorator
import numpy as np
import tensorflow as tf
from tf2onnx... | 18,336 | 34.536822 | 117 | py |
tensorflow-onnx | tensorflow-onnx-main/tests/run_pretrained_models.py | # SPDX-License-Identifier: Apache-2.0
"""Tool to convert and test pre-trained tensorflow models."""
# pylint: disable=broad-except,logging-not-lazy,unused-argument,unnecessary-lambda,import-outside-toplevel
# pylint: disable=wrong-import-position,too-many-nested-blocks
import argparse
import os
import re
import shu... | 34,586 | 40.872881 | 117 | py |
tensorflow-onnx | tensorflow-onnx-main/tests/keras2onnx_applications/yolov3/yolov3.py | # SPDX-License-Identifier: Apache-2.0
import os
import sys
import inspect
import colorsys
import onnx
import numpy as np
import tensorflow as tf
import keras
from PIL import Image, ImageFont, ImageDraw
from keras import backend as K
from keras.layers import Input
from keras.models import load_model
from mock_keras2onn... | 19,425 | 43.657471 | 158 | py |
tensorflow-onnx | tensorflow-onnx-main/tests/keras2onnx_applications/lpcnet/convert_lpcnet_to_onnx.py | # SPDX-License-Identifier: Apache-2.0
import lpcnet
import sys
model, enc, dec = lpcnet.new_lpcnet_model(use_gpu=False)
model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['sparse_categorical_accuracy'])
model_file = sys.argv[1]
model.load_weights(model_file)
import mock_keras2onnx
oxml_... | 526 | 28.277778 | 112 | py |
tensorflow-onnx | tensorflow-onnx-main/tests/keras2onnx_applications/model_source/densenet_2/densenet_2.py | # SPDX-License-Identifier: Apache-2.0
# From https://github.com/tdeboissiere/DeepLearningImplementations/blob/master/DenseNet/densenet.py
# Modifications Copyright (c) Microsoft.
from mock_keras2onnx.proto import keras
from keras.models import Model
from keras.layers.core import Dense, Dropout, Activation
from keras.... | 7,208 | 34.338235 | 99 | py |
tensorflow-onnx | tensorflow-onnx-main/tests/keras2onnx_applications/model_source/densenet_1/densenet_1.py | # SPDX-License-Identifier: Apache-2.0
# From https://github.com/titu1994/DenseNet/blob/master/densenet.py
# Modifications Copyright (c) Microsoft.
'''DenseNet models for Keras.
# Reference
- [Densely Connected Convolutional Networks](https://arxiv.org/pdf/1608.06993.pdf)
- [The One Hundred Layers Tiramisu: Fully Conv... | 38,501 | 46.828571 | 130 | py |
tensorflow-onnx | tensorflow-onnx-main/tests/keras2onnx_applications/model_source/densenet_1/tensorflow_backend.py | # SPDX-License-Identifier: Apache-2.0
# From https://github.com/titu1994/DenseNet/blob/master/tensorflow_backend.py
# Modifications Copyright (c) Microsoft.
import tensorflow as tf
from mock_keras2onnx.proto import keras
from keras.backend import tensorflow_backend as KTF
from keras.backend.common import image_data_... | 782 | 28 | 87 | py |
tensorflow-onnx | tensorflow-onnx-main/tests/keras2onnx_applications/model_source/densenet_1/subpixel.py | # SPDX-License-Identifier: Apache-2.0
# From https://github.com/titu1994/DenseNet/blob/master/subpixel.py
# Modifications Copyright (c) Microsoft.
from mock_keras2onnx.proto import keras
from keras import backend as K
from keras.engine import Layer
from keras.utils.generic_utils import get_custom_objects
from keras.b... | 3,693 | 42.458824 | 107 | py |
tensorflow-onnx | tensorflow-onnx-main/tests/keras2onnx_applications/mask_rcnn/mask_rcnn.py | # SPDX-License-Identifier: Apache-2.0
import os
import sys
import numpy as np
import skimage
import onnx
import mock_keras2onnx
from mrcnn.config import Config
from mrcnn.model import BatchNorm, DetectionLayer
from mrcnn import model as modellib
from mrcnn import visualize
from mock_keras2onnx import set_converter
f... | 9,141 | 40.93578 | 136 | py |
tensorflow-onnx | tensorflow-onnx-main/tests/keras2onnx_applications/nightly_build/test_wavenet.py | # SPDX-License-Identifier: Apache-2.0
import os
import sys
import unittest
import mock_keras2onnx
import numpy as np
from mock_keras2onnx.proto import keras
from os.path import dirname, abspath
sys.path.insert(0, os.path.join(dirname(abspath(__file__)), '../../keras2onnx_tests/'))
from test_utils import run_keras_and_... | 3,709 | 34.673077 | 112 | py |
tensorflow-onnx | tensorflow-onnx-main/tests/keras2onnx_applications/nightly_build/test_super_resolution.py | # SPDX-License-Identifier: Apache-2.0
import os
import sys
import unittest
import mock_keras2onnx
import numpy as np
from mock_keras2onnx.proto import keras
from os.path import dirname, abspath
sys.path.insert(0, os.path.join(dirname(abspath(__file__)), '../../keras2onnx_tests/'))
from test_utils import run_keras_and_... | 32,874 | 35.126374 | 134 | py |
tensorflow-onnx | tensorflow-onnx-main/tests/keras2onnx_applications/nightly_build/test_prn.py | # SPDX-License-Identifier: Apache-2.0
import os
import sys
import unittest
import mock_keras2onnx
import numpy as np
from mock_keras2onnx.proto import keras
from os.path import dirname, abspath
sys.path.insert(0, os.path.join(dirname(abspath(__file__)), '../../keras2onnx_tests/'))
from test_utils import run_keras_and_... | 3,588 | 30.761062 | 112 | py |
tensorflow-onnx | tensorflow-onnx-main/tests/keras2onnx_applications/nightly_build/test_se_densenet.py | # SPDX-License-Identifier: Apache-2.0
import os
import sys
import unittest
import mock_keras2onnx
import numpy as np
from mock_keras2onnx.proto import keras
from mock_keras2onnx.proto.tfcompat import is_tf2
from os.path import dirname, abspath
sys.path.insert(0, os.path.join(dirname(abspath(__file__)), '../../keras2on... | 10,900 | 36.332192 | 119 | py |
tensorflow-onnx | tensorflow-onnx-main/tests/keras2onnx_applications/nightly_build/test_name_entity_recognition.py | # SPDX-License-Identifier: Apache-2.0
import os
import sys
import unittest
import mock_keras2onnx
import numpy as np
from mock_keras2onnx.proto import keras
from onnxconverter_common.onnx_ex import get_maximum_opset_supported
from os.path import dirname, abspath
sys.path.insert(0, os.path.join(dirname(abspath(__file__... | 3,685 | 41.367816 | 118 | py |
tensorflow-onnx | tensorflow-onnx-main/tests/keras2onnx_applications/nightly_build/test_segnet.py | # SPDX-License-Identifier: Apache-2.0
import os
import sys
import unittest
import keras_segmentation
from os.path import dirname, abspath
sys.path.insert(0, os.path.join(dirname(abspath(__file__)), '../../keras2onnx_tests/'))
from test_utils import run_image
img_path = os.path.join(os.path.dirname(__file__), '../data... | 1,563 | 35.372093 | 117 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.