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 |
|---|---|---|---|---|---|---|
BMXNet-v2 | BMXNet-v2-master/example/numpy-ops/custom_softmax.py | # Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not u... | 3,190 | 34.455556 | 79 | py |
BMXNet-v2 | BMXNet-v2-master/example/vae-gan/convert_data.py | # Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not u... | 3,581 | 33.776699 | 187 | py |
BMXNet-v2 | BMXNet-v2-master/example/vae-gan/vaegan_mxnet.py | # Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not u... | 31,039 | 40.945946 | 334 | py |
BMXNet-v2 | BMXNet-v2-master/benchmark/python/sparse/dot.py | # Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not u... | 20,888 | 43.730193 | 123 | py |
BMXNet-v2 | BMXNet-v2-master/benchmark/python/sparse/memory_benchmark.py | # Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not u... | 3,792 | 39.351064 | 100 | py |
BMXNet-v2 | BMXNet-v2-master/benchmark/python/sparse/updater.py | # Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not u... | 2,695 | 33.126582 | 88 | py |
BMXNet-v2 | BMXNet-v2-master/benchmark/python/sparse/sparse_end2end.py | # Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not u... | 12,675 | 40.155844 | 128 | py |
BMXNet-v2 | BMXNet-v2-master/benchmark/python/sparse/cast_storage.py | # Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not u... | 3,691 | 35.92 | 107 | py |
BMXNet-v2 | BMXNet-v2-master/benchmark/python/sparse/sparse_op.py | from __future__ import print_function
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Versio... | 9,244 | 36.278226 | 117 | py |
BMXNet-v2 | BMXNet-v2-master/benchmark/python/control_flow/rnn.py | # Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not u... | 5,005 | 34.757143 | 113 | py |
BMXNet-v2 | BMXNet-v2-master/benchmark/python/gluon/benchmark_gluon.py | # Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not u... | 7,754 | 46 | 113 | py |
BMXNet-v2 | BMXNet-v2-master/benchmark/python/quantization/benchmark_op.py | # Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not u... | 5,279 | 57.021978 | 117 | py |
BMXNet-v2 | BMXNet-v2-master/benchmark/opperf/opperf.py | #!/usr/bin/env python3
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# ... | 6,873 | 46.082192 | 120 | py |
BMXNet-v2 | BMXNet-v2-master/benchmark/opperf/nd_operations/gemm_operators.py | # Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not u... | 3,173 | 34.266667 | 85 | py |
BMXNet-v2 | BMXNet-v2-master/benchmark/opperf/nd_operations/reduction_operators.py | # Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not u... | 2,227 | 36.762712 | 101 | py |
BMXNet-v2 | BMXNet-v2-master/benchmark/opperf/nd_operations/unary_operators.py | # Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not u... | 2,633 | 40.809524 | 113 | py |
BMXNet-v2 | BMXNet-v2-master/benchmark/opperf/nd_operations/nn_basic_operators.py | # Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not u... | 4,546 | 53.130952 | 108 | py |
BMXNet-v2 | BMXNet-v2-master/benchmark/opperf/nd_operations/nn_activation_operators.py | # Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not u... | 5,451 | 49.953271 | 118 | py |
BMXNet-v2 | BMXNet-v2-master/benchmark/opperf/nd_operations/random_sampling_operators.py | # Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not u... | 2,529 | 39.806452 | 108 | py |
BMXNet-v2 | BMXNet-v2-master/benchmark/opperf/nd_operations/binary_operators.py | # Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not u... | 3,693 | 38.72043 | 108 | py |
BMXNet-v2 | BMXNet-v2-master/benchmark/opperf/nd_operations/nn_conv_operators.py | # Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not u... | 7,245 | 50.757143 | 97 | py |
BMXNet-v2 | BMXNet-v2-master/benchmark/opperf/utils/benchmark_utils.py | # Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not u... | 5,294 | 38.81203 | 118 | py |
BMXNet-v2 | BMXNet-v2-master/benchmark/opperf/utils/profiler_utils.py | # Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not u... | 8,368 | 43.047368 | 113 | py |
BMXNet-v2 | BMXNet-v2-master/benchmark/opperf/utils/op_registry_utils.py | # Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not u... | 11,692 | 34.21988 | 110 | py |
BMXNet-v2 | BMXNet-v2-master/benchmark/opperf/utils/ndarray_utils.py | # Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not u... | 4,403 | 33.40625 | 120 | py |
BMXNet-v2 | BMXNet-v2-master/benchmark/opperf/custom_operations/custom_operations.py | # Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not u... | 2,253 | 32.147059 | 98 | py |
BMXNet-v2 | BMXNet-v2-master/ci/build_windows.py | #!/usr/bin/env python
# -*- coding: utf-8 -*-
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache Licen... | 9,431 | 34.592453 | 118 | py |
BMXNet-v2 | BMXNet-v2-master/ci/util.py | # Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not u... | 3,866 | 32.336207 | 100 | py |
BMXNet-v2 | BMXNet-v2-master/ci/build.py | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache Licen... | 23,403 | 39.075342 | 135 | py |
BMXNet-v2 | BMXNet-v2-master/ci/docker/qemu/vmcontrol.py | #!/usr/bin/env python3
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "... | 12,402 | 33.357341 | 149 | py |
BMXNet-v2 | BMXNet-v2-master/ci/docker/qemu/runtime_functions.py | #!/usr/bin/env python3
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "... | 4,673 | 33.622222 | 185 | py |
CHERRY | CHERRY-main/layer.py | import torch
from torch import nn
from torch.nn import functional as F
from utils import sparse_dropout, dot
class GraphConvolution(nn.Module):
def __init__(self, node_dim,input_dim, output_dim, num_features_nonzero,
dropout=0.,
is_sparse_inputs=False,
... | 1,688 | 28.12069 | 76 | py |
CHERRY | CHERRY-main/utils.py | import os
import sys
import Bio
import scipy as sp
import numpy as np
import pandas as pd
import pickle as pkl
import networkx as nx
import scipy.stats as stats
import scipy.sparse as sparse
import subprocess
from Bio import SeqIO
from Bio.Seq import Seq
from Bio.SeqRecord import SeqRecord
import torch
from torch i... | 13,635 | 36.877778 | 129 | py |
CHERRY | CHERRY-main/model.py | import torch
from torch import nn
from torch.nn import functional as F
from layer import GraphConvolution
import numpy as np
from config import args
import random
class encoder(nn.Module):
def __init__(self, node_dim, input_dim, output_dim, num_features_nonzero):
super(encoder, self).__init__(... | 2,568 | 30.329268 | 122 | py |
CHERRY | CHERRY-main/run_Cherry.py | import os
import numpy as np
import torch
from torch import nn
from torch import optim
from torch.nn import functional as F
import torch.utils.data as Data
from data import load_data, preprocess_features, preprocess_adj, sample_mask
import model
from config import args
from utils import masked... | 10,910 | 32.164134 | 135 | py |
vits-for-small-scale-datasets | vits-for-small-scale-datasets-main/projection_head.py | """
Mostly copy-paste from timm library.
https://github.com/rwightman/pytorch-image-models/blob/master/timm/models/vision_transformer.py
"""
""" projection head for Self-supervised training """
import math
from functools import partial
from turtle import forward
import torch
import torch.nn as nn
import torch.nn.func... | 1,847 | 32.6 | 123 | py |
vits-for-small-scale-datasets | vits-for-small-scale-datasets-main/finetune.py | from utils.mix import cutmix_data, mixup_data, mixup_criterion
import numpy as np
import random
import logging as log
import torch
import torch.nn as nn
import torch.optim
import torch.utils.data
import torchvision.transforms as transforms
from colorama import Fore, Style
from torchsummary import summary
from utils.los... | 18,265 | 35.314115 | 159 | py |
vits-for-small-scale-datasets | vits-for-small-scale-datasets-main/train_ssl.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# 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 ... | 28,001 | 46.062185 | 181 | py |
vits-for-small-scale-datasets | vits-for-small-scale-datasets-main/models/build_model.py | from .vit import VisionTransformer
from .swin import SwinTransformer
from .cait import cait_models
from functools import partial
from torch import nn
def create_model(img_size, n_classes, args):
if args.arch == "vit":
patch_size = 4 if img_size == 32 else 8 #4 if img_size = 32 else 8
model = Vi... | 1,602 | 33.847826 | 131 | py |
vits-for-small-scale-datasets | vits-for-small-scale-datasets-main/models/swin.py | # Copyright (c) ByteDance, Inc. and its affiliates.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
"""
Mostly copy-paste from Swin-Transformer libarary:
https://github.com/facebookresearch/dino
https://github.com/microsof... | 32,714 | 39.388889 | 119 | py |
vits-for-small-scale-datasets | vits-for-small-scale-datasets-main/models/cait.py | import torch
import torch.nn as nn
from functools import partial
from timm.models.vision_transformer import Mlp, PatchEmbed , _cfg
from timm.models.registry import register_model
from timm.models.layers import trunc_normal_, DropPath
from einops.layers.torch import Rearrange
def pair(t):
return t if isinstance(t... | 10,998 | 38.851449 | 116 | py |
vits-for-small-scale-datasets | vits-for-small-scale-datasets-main/models/vit.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# 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 ... | 9,515 | 37.840816 | 112 | py |
vits-for-small-scale-datasets | vits-for-small-scale-datasets-main/utils/losses.py | # Thanks to rwightman's timm package
# github.com:rwightman/pytorch-image-models
import torch.nn as nn
import torch.nn.functional as F
class LabelSmoothingCrossEntropy(nn.Module):
"""
NLL loss with label smoothing.
"""
def __init__(self, smoothing=0.1):
"""
Constructor for the LabelSmo... | 986 | 30.83871 | 72 | py |
vits-for-small-scale-datasets | vits-for-small-scale-datasets-main/utils/sampler.py | # Copyright (c) 2015-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the CC-by-NC license found in the
# LICENSE file in the root directory of this source tree.
#
from torch.utils.data.sampler import BatchSampler
import torch
import numpy as np
from torch.utils.data.dataloader impo... | 2,746 | 32.91358 | 111 | py |
vits-for-small-scale-datasets | vits-for-small-scale-datasets-main/utils/dataloader.py | import os
from colorama import Fore, Style
import torchvision.transforms as transforms
import torchvision.datasets as datasets
import torchvision
import torch
def datainfo(logger, args):
if args.dataset == 'CIFAR10':
print(Fore.YELLOW+'*'*80)
logger.debug('CIFAR10')
print('*'*80 + Style.RES... | 3,964 | 37.495146 | 124 | py |
vits-for-small-scale-datasets | vits-for-small-scale-datasets-main/utils/cosine_annealing_with_warmup.py | import math
import torch
from torch.optim.lr_scheduler import _LRScheduler
class CosineAnnealingWarmupRestarts(_LRScheduler):
"""
optimizer (Optimizer): Wrapped optimizer.
first_cycle_steps (int): First cycle step size.
cycle_mult(float): Cycle steps magnification. Default: -1.
max... | 4,192 | 42.677083 | 122 | py |
vits-for-small-scale-datasets | vits-for-small-scale-datasets-main/utils/scheduler.py |
import math
import torch
from torch.optim.lr_scheduler import _LRScheduler
class CosineAnnealingWarmupRestarts(_LRScheduler):
"""
optimizer (Optimizer): Wrapped optimizer.
first_cycle_steps (int): First cycle step size.
cycle_mult(float): Cycle steps magnification. Default: -1.
max... | 4,780 | 40.573913 | 129 | py |
vits-for-small-scale-datasets | vits-for-small-scale-datasets-main/utils/training_functions.py | import torch
class EarlyStopping:
def __init__(self, patience=0, verbose=0, mode='max'):
self._step = 0
self._loss = 0.0
self.patience = patience
self.verbose = verbose
self.best_value = 0.0
if mode == 'max':
self.mode = 1
else:
self.m... | 1,296 | 28.477273 | 74 | py |
vits-for-small-scale-datasets | vits-for-small-scale-datasets-main/utils/utils_ssl.py | import os
import sys
import time
import math
import random
import datetime
import subprocess
from collections import defaultdict, deque
import numpy as np
import torch
from torch import nn
import torch.distributed as dist
from PIL import ImageFilter, ImageOps
import argparse
import warnings
from einops import rearrange... | 27,248 | 32.47543 | 119 | py |
vits-for-small-scale-datasets | vits-for-small-scale-datasets-main/utils/random_erasing.py | from __future__ import absolute_import
from torchvision.transforms import *
import random
import math
class RandomErasing(object):
def __init__(self, probability = 0.5, sl = 0.02, sh = 0.4, r1 = 0.3, mean=[0.4914, 0.4822, 0.4465]):
self.EPSILON = probability
self.mean = mean
self.sl = sl
... | 1,727 | 36.565217 | 104 | py |
vits-for-small-scale-datasets | vits-for-small-scale-datasets-main/utils/drop_path.py | import torch
from torch.nn import Module
def drop_path(x, drop_prob: float = 0., training: bool = False):
"""
Obtained from: github.com:rwightman/pytorch-image-models
Drop paths (Stochastic Depth) per sample (when applied in main path of residual blocks).
This is the same as the DropConnect impl I crea... | 1,504 | 43.264706 | 108 | py |
vits-for-small-scale-datasets | vits-for-small-scale-datasets-main/utils/mix.py | import numpy as np
import torch
def rand_bbox(size, lam):
W = size[2]
H = size[3]
cut_rat = np.sqrt(1. - lam)
cut_w = np.int(W * cut_rat)
cut_h = np.int(H * cut_rat)
# uniform
cx = np.random.randint(W)
cy = np.random.randint(H)
bbx1 = np.clip(cx - cut_w // 2, 0, W)
bby1 = np.c... | 1,572 | 26.12069 | 77 | py |
SLN | SLN-master/utils.py | import torch
import torch.nn.functional as F
import numpy as np
""" Training/testing """
# training
def train_noise(args, model, device, loader, optimizer, epoch, ema_optimizer=None):
model.train()
train_loss = 0
correct = 0
for data, target in loader:
if len(target.size())==1:
... | 4,157 | 33.65 | 125 | py |
SLN | SLN-master/dataset.py | # from __future__ import print_function
from torchvision import datasets, transforms
from torchvision.datasets.vision import VisionDataset
from PIL import Image
import warnings
import os
import os.path
import numpy as np
import pandas as pd
import torch
import codecs
import zipfile
import random
random.seed(0)
import ... | 5,608 | 40.548148 | 149 | py |
SLN | SLN-master/noise_cifar_train.py | import os
import time
import argparse
import numpy as np
import random
import torch
import torch.optim as optim
import torch.backends.cudnn as cudnn
from utils import train_noise, test, get_output, WeightEMA
from dataset import get_cifar_dataset
from networks.wideresnet import Wide_ResNet
def log(path, str):
pri... | 4,428 | 38.900901 | 129 | py |
SLN | SLN-master/noise_clothing1m_train.py | import os
import time
import math
import argparse
import numpy as np
import random
import torch
import torch.optim as optim
import torch.backends.cudnn as cudnn
from torchvision import datasets, transforms
from utils import train_noise, test, get_output, WeightEMA
import networks.resnet as resnet
from dataset import C... | 5,955 | 39.517007 | 201 | py |
SLN | SLN-master/networks/resnet.py | import torch
import torch.nn as nn
import math
import torch.utils.model_zoo as model_zoo
import torch.nn.functional as F
__all__ = ['ResNet', 'resnet18', 'resnet34', 'resnet50', 'resnet101',
'resnet152']
model_urls = {
'resnet18': 'https://download.pytorch.org/models/resnet18-5c106cde.pth',
'resne... | 7,272 | 31.324444 | 78 | py |
SLN | SLN-master/networks/wideresnet.py | import torch
import torch.nn as nn
import torch.nn.init as init
import torch.nn.functional as F
import numpy as np
""" Wide Resnet """
def conv3x3(in_planes, out_planes, stride=1):
return nn.Conv2d(in_planes, out_planes, kernel_size=3, stride=stride, padding=1, bias=True)
def conv_init(m):
classname = m.__cl... | 3,120 | 34.465909 | 98 | py |
out-of-body-detector | out-of-body-detector-main/model.py | #!/usr/bin/env python3
"""
(c) Research Group CAMMA, University of Strasbourg, IHU Strasbourg, France
Website: http://camma.u-strasbg.fr
"""
import tensorflow as tf
import os
def preprocess(image, shape=[64, 64]):
image = tf.cast(image, tf.float32)
image = tf.image.resize(image, shape)
image = tf.resh... | 1,250 | 26.8 | 84 | py |
MedicalZooPytorch | MedicalZooPytorch-master/examples/train_mrbrains_4_classes.py | # Python libraries
import argparse, os
import torch
# Lib files
import lib.utils as utils
import lib.medloaders as medical_loaders
import lib.medzoo as medzoo
import lib.train as train
from lib.losses3D import DiceLoss
os.environ["CUDA_VISIBLE_DEVICES"] = "1"
seed = 1777777
torch.manual_seed(seed)
def main():
a... | 3,089 | 38.113924 | 116 | py |
MedicalZooPytorch | MedicalZooPytorch-master/examples/train_mrbrains_9_classes.py | # Python libraries
import argparse
import os
import torch
import lib.medloaders as medical_loaders
import lib.medzoo as medzoo
import lib.train as train
# Lib files
import lib.utils as utils
from lib.losses3D.dice import DiceLoss
os.environ["CUDA_VISIBLE_DEVICES"] = "1"
seed = 1777777
torch.manual_seed(seed)
def m... | 3,178 | 37.768293 | 116 | py |
MedicalZooPytorch | MedicalZooPytorch-master/examples/test_miccai_2019.py | """
MICCAI 2019 Medical Deep Learning 2D high resolution image segmentation project:
MICCAI 2019 Prostate Cancer segmentation challenge
Data can be downloaded from here: https://gleason2019.grand-challenge.org/
"""
import argparse
import torch, os
from torch.utils.tensorboard import SummaryWriter
# Lib files
import ... | 3,225 | 38.82716 | 116 | py |
MedicalZooPytorch | MedicalZooPytorch-master/examples/train_brats2018_new.py | # Python libraries
import argparse
import os
import lib.medloaders as medical_loaders
import lib.medzoo as medzoo
import lib.train as train
# Lib files
import lib.utils as utils
from lib.losses3D import DiceLoss
os.environ["CUDA_VISIBLE_DEVICES"] = "0"
seed = 1777777
def main():
args = get_arguments()
utils... | 3,295 | 42.368421 | 116 | py |
MedicalZooPytorch | MedicalZooPytorch-master/tests/inference.py | import argparse
import os
import torch
import torch.nn.functional as F
# Lib files
import lib.utils as utils
import lib.medloaders as medical_loaders
import lib.medzoo as medzoo
from lib.visual3D_temp import non_overlap_padding,test_padding
from lib.losses3D import DiceLoss
#
def main():
args = get_arguments()
... | 5,282 | 38.425373 | 148 | py |
MedicalZooPytorch | MedicalZooPytorch-master/tests/test_losses3D.py | # TODO write tests for all loss functions
import torch
# these losses work with target 4D shape [batch, dim_1, dim_2, dim_3 ]
from lib.losses3D.BCE_dice import BCEDiceLoss
from lib.losses3D.generalized_dice import GeneralizedDiceLoss
from lib.losses3D.dice import DiceLoss
from lib.losses3D.weight_smooth_l1 import Weig... | 3,868 | 36.931373 | 93 | py |
MedicalZooPytorch | MedicalZooPytorch-master/tests/train_with_trainer_class.py | import argparse
import os
import lib.medloaders as medical_loaders
import lib.medzoo as medzoo
# Lib files
import lib.utils as utils
from lib.losses3D import DiceLoss, create_loss
from lib.train.trainer import Trainer
import torch
def main():
args = get_arguments()
os.environ["CUDA_VISIBLE_DEVICES"] = "0"
... | 3,003 | 40.150685 | 116 | py |
MedicalZooPytorch | MedicalZooPytorch-master/tests/test_augmentations.py | from lib.medloaders.medical_loader_utils import generate_padded_subvolumes
import torch
import matplotlib.pyplot as plt
import lib.augment3D as augment
size = 32
from lib.medloaders.medical_image_process import load_medical_image
# t1 = torch.randn(size,size,size).numpy()
# t2 = torch.randn(size,size,size).numpy()
b... | 856 | 30.740741 | 110 | py |
MedicalZooPytorch | MedicalZooPytorch-master/tests/test_covid_ct.py | # Python libraries
import argparse
import os
from torch.utils.tensorboard import SummaryWriter
import lib.medloaders as medical_loaders
import lib.medzoo as medzoo
import lib.utils as utils
from lib.train.train_covid import train, validation
def main():
args = get_arguments()
os.environ["CUDA_VISIBLE_DEVIC... | 3,120 | 39.532468 | 116 | py |
MedicalZooPytorch | MedicalZooPytorch-master/lib/losses3D/weight_smooth_l1.py | import torch
from lib.losses3D.basic import expand_as_one_hot
# Code was adapted and mofified from https://github.com/wolny/pytorch-3dunet/blob/master/pytorch3dunet/unet3d/losses.py
class WeightedSmoothL1Loss(torch.nn.SmoothL1Loss):
def __init__(self, threshold=0, initial_weight=0.1, apply_below_threshold=True,c... | 979 | 34 | 119 | py |
MedicalZooPytorch | MedicalZooPytorch-master/lib/losses3D/VAEloss.py | # Reconstruction + KL divergence losses3D summed over all elements and batch
import torch
import torch.functional as F
#TODO test and class
def loss_vae(recon_x, x, mu, logvar, type="BCE", h1=0.1,h2=0.1):
"""
see Appendix B from VAE paper:
Kingma and Welling. Auto-Encoding Variational Bayes. ICLR, 2014
... | 1,175 | 34.636364 | 76 | py |
MedicalZooPytorch | MedicalZooPytorch-master/lib/losses3D/BCE_dice.py | import torch.nn as nn
from lib.losses3D.dice import DiceLoss
from lib.losses3D.basic import expand_as_one_hot
# Code was adapted and mofified from https://github.com/wolny/pytorch-3dunet/blob/master/pytorch3dunet/unet3d/losses.py
class BCEDiceLoss(nn.Module):
"""Linear combination of BCE and Dice losses3D"""
... | 986 | 40.125 | 119 | py |
MedicalZooPytorch | MedicalZooPytorch-master/lib/losses3D/weight_cross_entropy.py | from lib.losses3D.basic import *
# Code was adapted and mofified from https://github.com/wolny/pytorch-3dunet/blob/master/pytorch3dunet/unet3d/losses.py
class WeightedCrossEntropyLoss(torch.nn.Module):
"""
WeightedCrossEntropyLoss (WCE) as described in https://arxiv.org/pdf/1707.03237.pdf
"""
def __i... | 1,029 | 37.148148 | 119 | py |
MedicalZooPytorch | MedicalZooPytorch-master/lib/losses3D/Dice2D.py | import torch
import torch.nn as nn
# TODO TEST
class DiceLoss2D(nn.Module):
def __init__(self, classes, epsilon=1e-5, sigmoid_normalization=True):
super(DiceLoss2D, self).__init__()
self.epsilon = epsilon
self.classes = classes
if sigmoid_normalization:
self.normalizat... | 1,965 | 35.407407 | 142 | py |
MedicalZooPytorch | MedicalZooPytorch-master/lib/losses3D/tags_angular_loss.py | import torch
from lib.losses3D.basic import expand_as_one_hot
# Code was adapted and modified from https://github.com/wolny/pytorch-3dunet/blob/master/pytorch3dunet/unet3d/losses.py
class TagsAngularLoss(torch.nn.Module):
def __init__(self, tags_coefficients=[1.0, 0.8, 0.5], classes=4):
super(TagsAngula... | 2,438 | 42.553571 | 119 | py |
MedicalZooPytorch | MedicalZooPytorch-master/lib/losses3D/dice.py | from lib.losses3D.BaseClass import _AbstractDiceLoss
from lib.losses3D.basic import *
# Code was adapted and mofified from https://github.com/wolny/pytorch-3dunet/blob/master/pytorch3dunet/unet3d/losses.py
class DiceLoss(_AbstractDiceLoss):
"""Computes Dice Loss according to https://arxiv.org/abs/1606.04797.
... | 828 | 42.631579 | 119 | py |
MedicalZooPytorch | MedicalZooPytorch-master/lib/losses3D/generalized_dice.py | from lib.losses3D.BaseClass import _AbstractDiceLoss
from lib.losses3D.basic import *
# Code was adapted and modified from https://github.com/wolny/pytorch-3dunet/blob/master/pytorch3dunet/unet3d/losses.py
class GeneralizedDiceLoss(_AbstractDiceLoss):
"""Computes Generalized Dice Loss (GDL) as described in http... | 1,686 | 38.232558 | 119 | py |
MedicalZooPytorch | MedicalZooPytorch-master/lib/losses3D/pixel_wise_cross_entropy.py | from lib.losses3D.basic import *
import torch.nn as nn
# Code was adapted and mofified from https://github.com/wolny/pytorch-3dunet/blob/master/pytorch3dunet/unet3d/losses.py
class PixelWiseCrossEntropyLoss(nn.Module):
def __init__(self, class_weights=None, ignore_index=None):
super(PixelWiseCrossEntropyL... | 1,580 | 39.538462 | 119 | py |
MedicalZooPytorch | MedicalZooPytorch-master/lib/losses3D/__init__.py | import torch
import torch.nn as nn
from torch.nn import MSELoss, SmoothL1Loss, L1Loss
# Code was adapted and mofified from https://github.com/wolny/pytorch-3dunet/blob/master/pytorch3dunet/unet3d/losses.py
from .BCE_dice import BCEDiceLoss
from .weight_cross_entropy import WeightedCrossEntropyLoss
from .pixel_wise_cr... | 3,896 | 37.584158 | 119 | py |
MedicalZooPytorch | MedicalZooPytorch-master/lib/losses3D/BaseClass.py | import torch
from torch import nn as nn
from lib.losses3D.basic import expand_as_one_hot
# Code was adapted and mofified from https://github.com/wolny/pytorch-3dunet/blob/master/pytorch3dunet/unet3d/losses.py
class _AbstractDiceLoss(nn.Module):
"""
Base class for different implementations of Dice loss.
... | 2,652 | 39.19697 | 119 | py |
MedicalZooPytorch | MedicalZooPytorch-master/lib/losses3D/basic.py | import torch
# Code was adapted and mofified from https://github.com/wolny/pytorch-3dunet/blob/master/pytorch3dunet/unet3d/losses.py
def expand_as_one_hot(input, C, ignore_index=None):
"""
Converts NxDxHxW label image to NxCxDxHxW, where each label gets converted to its corresponding one-hot vector
:param... | 3,078 | 37.012346 | 119 | py |
MedicalZooPytorch | MedicalZooPytorch-master/lib/losses3D/ContrastiveLoss.py | from lib.losses3D.basic import *
# Code was adapted and modified from https://github.com/wolny/pytorch-3dunet/blob/master/pytorch3dunet/unet3d/losses.py
class ContrastiveLoss(torch.nn.Module):
"""
Implementation of contrastive loss defined in https://arxiv.org/pdf/1708.02551.pdf
'Semantic Instance Segme... | 5,952 | 47.008065 | 119 | py |
MedicalZooPytorch | MedicalZooPytorch-master/lib/visual3D_temp/conf_matrix.py | import itertools
import matplotlib.pyplot as plt
import numpy as np
import torch
# TODO test!!!!!!
# conf_matrix = tnt.meter.ConfusionMeter(classes)
# conf_matrix.add(y_pred.detach(), y_true)
# plot_confusion_matrix(conf_matrix.conf, list_keys, normalize=False, title="Confusion Matrix TEST - Last epoch")
def plot_con... | 2,786 | 32.987805 | 113 | py |
MedicalZooPytorch | MedicalZooPytorch-master/lib/visual3D_temp/BaseWriter.py | import os
import numpy as np
from torch.utils.tensorboard import SummaryWriter
import lib.utils as utils
dict_class_names = {"iseg2017": ["Air", "CSF", "GM", "WM"],
"iseg2019": ["Air", "CSF", "GM", "WM"],
"mrbrains4": ["Air", "CSF", "GM", "WM"],
"mrbrains9":... | 7,043 | 49.676259 | 117 | py |
MedicalZooPytorch | MedicalZooPytorch-master/lib/visual3D_temp/viz_old.py | from .viz import *
from lib.utils.general import prepare_input
def visualize_offline(args, epoch, model, full_volume, affine, writer):
model.eval()
test_loss = 0
classes, slices, height, width = 4, 144, 192, 256
predictions = torch.tensor([]).cpu()
segment_map = torch.tensor([]).cpu()
for ba... | 3,029 | 36.407407 | 112 | py |
MedicalZooPytorch | MedicalZooPytorch-master/lib/visual3D_temp/viz_2d.py | import matplotlib.pyplot as plt
import os
import numpy as np
def show_mid_slice(img_numpy, return_views=False):
"""
Accepts an 3D numpy array and shows median slices in all three planes
:param img_numpy:
"""
assert img_numpy.ndim == 3, "please provide a 3d numpy image"
n_i, n_j, n_k = img_nump... | 4,864 | 32.321918 | 107 | py |
MedicalZooPytorch | MedicalZooPytorch-master/lib/visual3D_temp/viz.py | import math
import nibabel as nib
import torch
import torch.nn.functional as F
from .viz_2d import *
def test_padding():
x = torch.randn(1, 144, 192, 256)
kc, kh, kw = 32, 32, 32 # kernel size
dc, dh, dw = 32, 32, 32 # stride
# Pad to multiples of 32
x = F.pad(x, (x.size(3) % kw // 2, x.size(3... | 7,338 | 32.665138 | 98 | py |
MedicalZooPytorch | MedicalZooPytorch-master/lib/medloaders/iseg2019.py | import glob
import os
import numpy as np
import torch
from torch.utils.data import Dataset
import lib.augment3D as augment3D
import lib.utils as utils
from lib.medloaders import medical_image_process as img_loader
from lib.medloaders.medical_loader_utils import get_viz_set, create_sub_volumes
class MRIDatasetISEG20... | 4,741 | 45.038835 | 110 | py |
MedicalZooPytorch | MedicalZooPytorch-master/lib/medloaders/mrbrains2018.py | import glob
import os
import numpy as np
from torch.utils.data import Dataset
import lib.utils as utils
from lib.medloaders import medical_image_process as img_loader
from lib.medloaders.medical_loader_utils import create_sub_volumes
from lib.medloaders.medical_loader_utils import get_viz_set
class MRIDatasetMRBRAI... | 3,272 | 40.43038 | 117 | py |
MedicalZooPytorch | MedicalZooPytorch-master/lib/medloaders/Covid_Segmentation_dataset.py | import glob
import os
import numpy as np
from torch.utils.data import Dataset
import lib.utils as utils
from lib.medloaders import medical_image_process as img_loader
from lib.medloaders.medical_loader_utils import create_sub_volumes
class COVID_Seg_Dataset(Dataset):
"""
Code for reading the COVID Segmentat... | 3,594 | 41.797619 | 117 | py |
MedicalZooPytorch | MedicalZooPytorch-master/lib/medloaders/COVIDxdataset.py | import os
import torch
from torch.utils.data import Dataset
from torchvision import transforms
from lib.medloaders import medical_image_process as img_loader
COVIDxDICT = {'pneumonia': 0, 'normal': 1, 'COVID-19': 2}
class COVIDxDataset(Dataset):
"""
Code for reading the COVIDxDataset
"""
def __in... | 2,132 | 30.367647 | 103 | py |
MedicalZooPytorch | MedicalZooPytorch-master/lib/medloaders/iseg2017.py | import glob
import os
import numpy as np
import torch
from torch.utils.data import Dataset
import lib.augment3D as augment3D
import lib.utils as utils
from lib.medloaders import medical_image_process as img_loader
from lib.medloaders.medical_loader_utils import get_viz_set, create_sub_volumes
class MRIDatasetISEG20... | 5,273 | 44.076923 | 111 | py |
MedicalZooPytorch | MedicalZooPytorch-master/lib/medloaders/brats2019.py | import glob
import os
import numpy as np
import torch
from torch.utils.data import Dataset
import lib.augment3D as augment3D
import lib.utils as utils
from lib.medloaders import medical_image_process as img_loader
from lib.medloaders.medical_loader_utils import create_sub_volumes
class MICCAIBraTS2019(Dataset):
... | 6,200 | 51.550847 | 117 | py |
MedicalZooPytorch | MedicalZooPytorch-master/lib/medloaders/brats2020.py | import glob
import os
import numpy as np
import torch
from torch.utils.data import Dataset
import lib.augment3D as augment3D
import lib.utils as utils
from lib.medloaders import medical_image_process as img_loader
from lib.medloaders.medical_loader_utils import create_sub_volumes
class MICCAIBraTS2020(Dataset):
... | 6,242 | 51.025 | 115 | py |
MedicalZooPytorch | MedicalZooPytorch-master/lib/medloaders/ixi_t1_t2.py | import os
import torch
from torch.utils.data import Dataset
import glob
import numpy as np
import lib.utils as utils
#from lib.medloaders import img_loader
from lib.medloaders import medical_image_process as img_loader
class IXIMRIdataset(Dataset):
"""
Code for reading the IXI brain MRI dataset
This load... | 4,036 | 39.37 | 120 | py |
MedicalZooPytorch | MedicalZooPytorch-master/lib/medloaders/covid_ct_dataset.py | import os
import torch
from torch.utils.data import Dataset
from lib.utils.covid_utils import read_txt
from PIL import Image
import torchvision.transforms as transforms
class CovidCTDataset(Dataset):
def __init__(self,mode, root_dir, txt_COVID, txt_NonCOVID, transform=None):
"""
Args:
... | 2,413 | 29.175 | 119 | py |
MedicalZooPytorch | MedicalZooPytorch-master/lib/medloaders/miccai_2019_pathology.py | import torch
import numpy as np
import glob
from torch.utils.data import Dataset
import lib.utils as utils
from lib.medloaders import medical_image_process as img_loader
"""
Based on this repository: https://github.com/black0017/MICCAI-2019-Prostate-Cancer-segmentation-challenge
"""
class MICCAI2019_gleason_patholo... | 7,877 | 34.013333 | 120 | py |
MedicalZooPytorch | MedicalZooPytorch-master/lib/medloaders/brats2018.py | import glob
import os
import numpy as np
import torch
from torch.utils.data import Dataset
import lib.augment3D as augment3D
import lib.utils as utils
from lib.medloaders import medical_image_process as img_loader
from lib.medloaders.medical_loader_utils import create_sub_volumes
class MICCAIBraTS2018(Dataset):
... | 5,897 | 48.983051 | 115 | py |
MedicalZooPytorch | MedicalZooPytorch-master/lib/medloaders/__init__.py | from torch.utils.data import DataLoader
from .COVIDxdataset import COVIDxDataset
from .Covid_Segmentation_dataset import COVID_Seg_Dataset
from .brats2018 import MICCAIBraTS2018
from .brats2019 import MICCAIBraTS2019
from .brats2020 import MICCAIBraTS2020
from .covid_ct_dataset import CovidCTDataset
from .iseg2017 imp... | 12,798 | 54.406926 | 119 | py |
MedicalZooPytorch | MedicalZooPytorch-master/lib/medloaders/medical_loader_utils.py | from lib.medloaders import medical_image_process as img_loader
from lib.visual3D_temp import *
def get_viz_set(*ls, dataset_name, test_subject=0, save=False, sub_vol_path=None):
"""
Returns total 3d input volumes (t1 and t2 or more) and segmentation maps
3d total vol shape : torch.Size([1, 144, 192, 256])... | 9,463 | 37.008032 | 120 | py |
MedicalZooPytorch | MedicalZooPytorch-master/lib/medloaders/medical_image_process.py | import nibabel as nib
import numpy as np
import torch
from PIL import Image
from nibabel.processing import resample_to_output
from scipy import ndimage
"""
concentrate all pre-processing here here
"""
def load_medical_image(path, type=None, resample=None,
viz3d=False, to_canonical=False, resca... | 6,866 | 32.334951 | 116 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.