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 |
|---|---|---|---|---|---|---|
Few-shot-WSI | Few-shot-WSI-master/configs/base.py | train_cfg = {}
test_cfg = {}
optimizer_config = dict() # grad_clip, coalesce, bucket_size_mb
# yapf:disable
log_config = dict(
interval=50,
hooks=[
dict(type='TextLoggerHook'),
dict(type='TensorboardLoggerHook')
])
# yapf:enable
# runtime settings
dist_params = dict(backend='nccl')
cudnn_be... | 433 | 20.7 | 64 | py |
Few-shot-WSI | Few-shot-WSI-master/configs/extraction/extract_feats_PAIP_test.py | _base_ = '../base.py'
# model settings
model = dict(
type='Extractor',
pretrained=None,
backbone=dict(
type='ResNet',
depth=18,
out_indices=[4], # 0: conv-1, x: stage-x
norm_cfg=dict(type='BN')))
# dataset settings
data_source_cfg = dict(type='ImageList')
data_root = 'data... | 842 | 23.085714 | 74 | py |
Few-shot-WSI | Few-shot-WSI-master/configs/extraction/extract_feats_NCT_train.py | _base_ = '../base.py'
# model settings
model = dict(
type='Extractor',
pretrained=None,
backbone=dict(
type='ResNet',
depth=18,
out_indices=[4], # 0: conv-1, x: stage-x
norm_cfg=dict(type='BN')))
# dataset settings
data_source_cfg = dict(type='ImageList')
data_root = 'data... | 832 | 22.8 | 74 | py |
Few-shot-WSI | Few-shot-WSI-master/configs/extraction/extract_feats_LC.py | _base_ = '../base.py'
# model settings
model = dict(
type='Extractor',
pretrained=None,
backbone=dict(
type='ResNet',
depth=18,
out_indices=[4], # 0: conv-1, x: stage-x
norm_cfg=dict(type='BN')))
# dataset settings
data_source_cfg = dict(type='ImageList')
data_root = 'data... | 843 | 23.114286 | 74 | py |
Few-shot-WSI | Few-shot-WSI-master/configs/extraction/extract_feats_PAIP_train.py | _base_ = '../base.py'
# model settings
model = dict(
type='Extractor',
pretrained=None,
backbone=dict(
type='ResNet',
depth=18,
out_indices=[4], # 0: conv-1, x: stage-x
norm_cfg=dict(type='BN')))
# dataset settings
data_source_cfg = dict(type='ImageList')
data_root = 'data... | 843 | 23.114286 | 74 | py |
Few-shot-WSI | Few-shot-WSI-master/configs/extraction/extract_feats_NCT_aug.py | _base_ = '../base.py'
# model settings
model = dict(
type='Extractor',
pretrained=None,
backbone=dict(
type='ResNet',
depth=18,
out_indices=[4], # 0: conv-1, x: stage-x
norm_cfg=dict(type='BN')))
# dataset settings
data_source_cfg = dict(type='ImageList')
data_root = 'data... | 1,153 | 24.086957 | 74 | py |
Few-shot-WSI | Few-shot-WSI-master/configs/extraction/extract_feats_NCT_test.py | _base_ = '../base.py'
# model settings
model = dict(
type='Extractor',
pretrained=None,
backbone=dict(
type='ResNet',
depth=18,
out_indices=[4], # 0: conv-1, x: stage-x
norm_cfg=dict(type='BN')))
# dataset settings
data_source_cfg = dict(type='ImageList')
data_root = 'data... | 831 | 22.771429 | 74 | py |
Few-shot-WSI | Few-shot-WSI-master/configs/extraction/r18_extract.py | _base_ = '../base.py'
# model settings
model = dict(
type='Extractor',
pretrained=None,
backbone=dict(
type='ResNet',
depth=18,
out_indices=[4], # 0: conv-1, x: stage-x
norm_cfg=dict(type='BN')))
# dataset settings
data_source_cfg = dict(type='ImageList')
data_root = 'data/... | 829 | 24.151515 | 74 | py |
Few-shot-WSI | Few-shot-WSI-master/configs/classification/nct/r18_bs512_ep100_wo_4.py | _base_ = '../../base.py'
# model settings
model = dict(
type='Classification',
pretrained=None,
backbone=dict(
type='ResNet',
depth=18,
out_indices=[4], # 0: conv-1, x: stage-x
norm_cfg=dict(type='BN')),
head=dict(
type='ClsHead', with_avg_pool=True, in_channels=... | 1,454 | 25.454545 | 74 | py |
Few-shot-WSI | Few-shot-WSI-master/configs/classification/nct/r18_bs512_ep100_all.py | _base_ = '../../base.py'
# model settings
model = dict(
type='Classification',
pretrained=None,
backbone=dict(
type='ResNet',
depth=18,
out_indices=[4], # 0: conv-1, x: stage-x
norm_cfg=dict(type='BN')),
head=dict(
type='ClsHead', with_avg_pool=True, in_channels=... | 1,449 | 25.363636 | 74 | py |
Few-shot-WSI | Few-shot-WSI-master/configs/classification/nct/r18_bs512_ep100_wo_3.py | _base_ = '../../base.py'
# model settings
model = dict(
type='Classification',
pretrained=None,
backbone=dict(
type='ResNet',
depth=18,
out_indices=[4], # 0: conv-1, x: stage-x
norm_cfg=dict(type='BN')),
head=dict(
type='ClsHead', with_avg_pool=True, in_channels=... | 1,454 | 25.454545 | 74 | py |
Few-shot-WSI | Few-shot-WSI-master/configs/classification/nct/r18_bs512_ep100_wo_7.py | _base_ = '../../base.py'
# model settings
model = dict(
type='Classification',
pretrained=None,
backbone=dict(
type='ResNet',
depth=18,
out_indices=[4], # 0: conv-1, x: stage-x
norm_cfg=dict(type='BN')),
head=dict(
type='ClsHead', with_avg_pool=True, in_channels=... | 1,454 | 25.454545 | 74 | py |
Few-shot-WSI | Few-shot-WSI-master/configs/classification/nct/r18_bs512_ep100_wo_0.py | _base_ = '../../base.py'
# model settings
model = dict(
type='Classification',
pretrained=None,
backbone=dict(
type='ResNet',
depth=18,
out_indices=[4], # 0: conv-1, x: stage-x
norm_cfg=dict(type='BN')),
head=dict(
type='ClsHead', with_avg_pool=True, in_channels=... | 1,454 | 25.454545 | 74 | py |
Few-shot-WSI | Few-shot-WSI-master/configs/classification/nct/r18_bs512_ep100_wo_6.py | _base_ = '../../base.py'
# model settings
model = dict(
type='Classification',
pretrained=None,
backbone=dict(
type='ResNet',
depth=18,
out_indices=[4], # 0: conv-1, x: stage-x
norm_cfg=dict(type='BN')),
head=dict(
type='ClsHead', with_avg_pool=True, in_channels=... | 1,454 | 25.454545 | 74 | py |
Few-shot-WSI | Few-shot-WSI-master/configs/classification/nct/r18_bs512_ep100_wo_2.py | _base_ = '../../base.py'
# model settings
model = dict(
type='Classification',
pretrained=None,
backbone=dict(
type='ResNet',
depth=18,
out_indices=[4], # 0: conv-1, x: stage-x
norm_cfg=dict(type='BN')),
head=dict(
type='ClsHead', with_avg_pool=True, in_channels=... | 1,454 | 25.454545 | 74 | py |
Few-shot-WSI | Few-shot-WSI-master/configs/classification/nct/r18_bs512_ep100_wo_1.py | _base_ = '../../base.py'
# model settings
model = dict(
type='Classification',
pretrained=None,
backbone=dict(
type='ResNet',
depth=18,
out_indices=[4], # 0: conv-1, x: stage-x
norm_cfg=dict(type='BN')),
head=dict(
type='ClsHead', with_avg_pool=True, in_channels=... | 1,454 | 25.454545 | 74 | py |
Few-shot-WSI | Few-shot-WSI-master/configs/classification/nct/r18_bs512_ep100_wo_78.py | _base_ = '../../base.py'
# model settings
model = dict(
type='Classification',
pretrained=None,
backbone=dict(
type='ResNet',
depth=18,
out_indices=[4], # 0: conv-1, x: stage-x
norm_cfg=dict(type='BN')),
head=dict(
type='ClsHead', with_avg_pool=True, in_channels=... | 1,455 | 25.472727 | 74 | py |
Few-shot-WSI | Few-shot-WSI-master/configs/classification/nct/r18_bs512_ep100_wo_8.py | _base_ = '../../base.py'
# model settings
model = dict(
type='Classification',
pretrained=None,
backbone=dict(
type='ResNet',
depth=18,
out_indices=[4], # 0: conv-1, x: stage-x
norm_cfg=dict(type='BN')),
head=dict(
type='ClsHead', with_avg_pool=True, in_channels=... | 1,454 | 25.454545 | 74 | py |
Few-shot-WSI | Few-shot-WSI-master/configs/classification/nct/r18_bs512_ep100_wo_5.py | _base_ = '../../base.py'
# model settings
model = dict(
type='Classification',
pretrained=None,
backbone=dict(
type='ResNet',
depth=18,
out_indices=[4], # 0: conv-1, x: stage-x
norm_cfg=dict(type='BN')),
head=dict(
type='ClsHead', with_avg_pool=True, in_channels=... | 1,454 | 25.454545 | 74 | py |
Few-shot-WSI | Few-shot-WSI-master/configs/wsi_selfsup/moco_v3/r18_bs256_ep200_wo_8.py | _base_ = '../../base.py'
# model settings
model = dict(
type='MOCOv3',
base_momentum=0.996,
backbone=dict(
type='ResNet',
depth=18,
in_channels=3,
out_indices=[4], # 0: conv-1, x: stage-x
norm_cfg=dict(type='BN')),
projector=dict(
type='NonLinearNeckSimCL... | 2,665 | 23.458716 | 90 | py |
Few-shot-WSI | Few-shot-WSI-master/configs/wsi_selfsup/moco_v3/r18_bs256_ep200_wo_4.py | _base_ = '../../base.py'
# model settings
model = dict(
type='MOCOv3',
base_momentum=0.996,
backbone=dict(
type='ResNet',
depth=18,
in_channels=3,
out_indices=[4], # 0: conv-1, x: stage-x
norm_cfg=dict(type='BN')),
projector=dict(
type='NonLinearNeckSimCL... | 2,665 | 23.458716 | 90 | py |
Few-shot-WSI | Few-shot-WSI-master/configs/wsi_selfsup/moco_v3/r18_bs256_ep200_wo_5.py | _base_ = '../../base.py'
# model settings
model = dict(
type='MOCOv3',
base_momentum=0.996,
backbone=dict(
type='ResNet',
depth=18,
in_channels=3,
out_indices=[4], # 0: conv-1, x: stage-x
norm_cfg=dict(type='BN')),
projector=dict(
type='NonLinearNeckSimCL... | 2,665 | 23.458716 | 90 | py |
Few-shot-WSI | Few-shot-WSI-master/configs/wsi_selfsup/moco_v3/r18_bs256_ep200_wo_78.py | _base_ = '../../base.py'
# model settings
model = dict(
type='MOCOv3',
base_momentum=0.996,
backbone=dict(
type='ResNet',
depth=18,
in_channels=3,
out_indices=[4], # 0: conv-1, x: stage-x
norm_cfg=dict(type='BN')),
projector=dict(
type='NonLinearNeckSimCL... | 2,666 | 23.46789 | 90 | py |
Few-shot-WSI | Few-shot-WSI-master/configs/wsi_selfsup/moco_v3/r18_bs256_ep200_wo_2.py | _base_ = '../../base.py'
# model settings
model = dict(
type='MOCOv3',
base_momentum=0.996,
backbone=dict(
type='ResNet',
depth=18,
in_channels=3,
out_indices=[4], # 0: conv-1, x: stage-x
norm_cfg=dict(type='BN')),
projector=dict(
type='NonLinearNeckSimCL... | 2,665 | 23.458716 | 90 | py |
Few-shot-WSI | Few-shot-WSI-master/configs/wsi_selfsup/moco_v3/r18_bs256_ep200_wo_6.py | _base_ = '../../base.py'
# model settings
model = dict(
type='MOCOv3',
base_momentum=0.996,
backbone=dict(
type='ResNet',
depth=18,
in_channels=3,
out_indices=[4], # 0: conv-1, x: stage-x
norm_cfg=dict(type='BN')),
projector=dict(
type='NonLinearNeckSimCL... | 2,665 | 23.458716 | 90 | py |
Few-shot-WSI | Few-shot-WSI-master/configs/wsi_selfsup/moco_v3/r18_bs256_ep200_wo_0.py | _base_ = '../../base.py'
# model settings
model = dict(
type='MOCOv3',
base_momentum=0.996,
backbone=dict(
type='ResNet',
depth=18,
in_channels=3,
out_indices=[4], # 0: conv-1, x: stage-x
norm_cfg=dict(type='BN')),
projector=dict(
type='NonLinearNeckSimCL... | 2,665 | 23.458716 | 90 | py |
Few-shot-WSI | Few-shot-WSI-master/configs/wsi_selfsup/moco_v3/r18_bs256_ep200_all.py | _base_ = '../../base.py'
# model settings
model = dict(
type='MOCOv3',
base_momentum=0.996,
backbone=dict(
type='ResNet',
depth=18,
in_channels=3,
out_indices=[4], # 0: conv-1, x: stage-x
norm_cfg=dict(type='BN')),
projector=dict(
type='NonLinearNeckSimCL... | 2,660 | 23.412844 | 90 | py |
Few-shot-WSI | Few-shot-WSI-master/configs/wsi_selfsup/moco_v3/r18_bs256_ep200_wo_7.py | _base_ = '../../base.py'
# model settings
model = dict(
type='MOCOv3',
base_momentum=0.996,
backbone=dict(
type='ResNet',
depth=18,
in_channels=3,
out_indices=[4], # 0: conv-1, x: stage-x
norm_cfg=dict(type='BN')),
projector=dict(
type='NonLinearNeckSimCL... | 2,665 | 23.458716 | 90 | py |
Few-shot-WSI | Few-shot-WSI-master/configs/wsi_selfsup/moco_v3/r18_bs256_ep200_wo_3.py | _base_ = '../../base.py'
# model settings
model = dict(
type='MOCOv3',
base_momentum=0.996,
backbone=dict(
type='ResNet',
depth=18,
in_channels=3,
out_indices=[4], # 0: conv-1, x: stage-x
norm_cfg=dict(type='BN')),
projector=dict(
type='NonLinearNeckSimCL... | 2,665 | 23.458716 | 90 | py |
Few-shot-WSI | Few-shot-WSI-master/configs/wsi_selfsup/moco_v3/r18_bs256_ep200_wo_1.py | _base_ = '../../base.py'
# model settings
model = dict(
type='MOCOv3',
base_momentum=0.996,
backbone=dict(
type='ResNet',
depth=18,
in_channels=3,
out_indices=[4], # 0: conv-1, x: stage-x
norm_cfg=dict(type='BN')),
projector=dict(
type='NonLinearNeckSimCL... | 2,665 | 23.458716 | 90 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/__init__.py | from .version import __version__, short_version
__all__ = ['__version__', 'short_version']
| 92 | 22.25 | 47 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/apis/__init__.py | from .train import get_root_logger, set_random_seed, train_model
| 65 | 32 | 64 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/apis/train.py | import random
import re
from collections import OrderedDict
import numpy as np
import torch
import torch.distributed as dist
from mmcv.parallel import MMDataParallel, MMDistributedDataParallel
from mmcv.runner import DistSamplerSeedHook, Runner, obj_from_dict
from openselfsup.datasets import build_dataloader
from ope... | 10,378 | 34.913495 | 87 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/third_party/clustering.py | # This file is modified from
# https://github.com/facebookresearch/deepcluster/blob/master/clustering.py
import time
import numpy as np
import faiss
import torch
from scipy.sparse import csr_matrix
__all__ = ['Kmeans', 'PIC']
def preprocess_features(npdata, pca):
"""Preprocess an array of features.
Args:
... | 9,576 | 29.5 | 84 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/models/classification.py | import numpy as np
import torch.nn as nn
from openselfsup.utils import print_log
from . import builder
from .registry import MODELS
from .utils import Sobel
@MODELS.register_module
class Classification(nn.Module):
"""Simple image classification.
Args:
backbone (dict): Config dict for module of bac... | 3,370 | 31.413462 | 85 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/models/simclr.py | import torch
import torch.nn as nn
from openselfsup.utils import print_log
from . import builder
from .registry import MODELS
from .utils import GatherLayer
@MODELS.register_module
class SimCLR(nn.Module):
"""SimCLR.
Implementation of "A Simple Framework for Contrastive Learning
of Visual Representatio... | 3,961 | 35.018182 | 88 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/models/rotation_pred.py | import torch
import torch.nn as nn
from openselfsup.utils import print_log
from . import builder
from .registry import MODELS
@MODELS.register_module
class RotationPred(nn.Module):
"""Rotation prediction.
Implementation of "Unsupervised Representation Learning
by Predicting Image Rotations (https://arx... | 3,294 | 33.684211 | 79 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/models/deepcluster.py | import numpy as np
import torch
import torch.nn as nn
from openselfsup.utils import print_log
from . import builder
from .registry import MODELS
from .utils import Sobel
@MODELS.register_module
class DeepCluster(nn.Module):
"""DeepCluster.
Implementation of "Deep Clustering for Unsupervised Learning
o... | 4,526 | 33.557252 | 88 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/models/relative_loc.py | import torch
import torch.nn as nn
from openselfsup.utils import print_log
from . import builder
from .registry import MODELS
@MODELS.register_module
class RelativeLoc(nn.Module):
"""Relative patch location.
Implementation of "Unsupervised Visual Representation Learning
by Context Prediction (https://a... | 3,948 | 35.564815 | 88 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/models/moco.py | import torch
import torch.nn as nn
from openselfsup.utils import print_log
from . import builder
from .registry import MODELS
@MODELS.register_module
class MOCO(nn.Module):
"""MOCO.
Implementation of "Momentum Contrast for Unsupervised Visual
Representation Learning (https://arxiv.org/abs/1911.05722)".... | 7,486 | 33.187215 | 88 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/models/moco_v3.py | import torch
import torch.nn as nn
from openselfsup.utils import print_log
from . import builder
from .registry import MODELS
import torch.nn.functional as F
@MODELS.register_module
class MOCOv3(nn.Module):
def __init__(self,
backbone,
projector=None,
predictor=... | 3,177 | 33.923077 | 77 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/models/registry.py | from openselfsup.utils import Registry
MODELS = Registry('model')
BACKBONES = Registry('backbone')
NECKS = Registry('neck')
HEADS = Registry('head')
MEMORIES = Registry('memory')
LOSSES = Registry('loss')
| 206 | 22 | 38 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/models/extractor.py | import torch.nn as nn
import torch.nn.functional as F
import numpy as np
import cv2
import math
from sklearn.cluster import KMeans
from openselfsup.utils import print_log
from . import builder
from .registry import MODELS
from .utils import Sobel
### For visualization.
@MODELS.register_module
class Extractor(nn.Mo... | 8,632 | 41.318627 | 121 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/models/npid.py | import torch
import torch.nn as nn
from openselfsup.utils import print_log
from . import builder
from .registry import MODELS
@MODELS.register_module
class NPID(nn.Module):
"""NPID.
Implementation of "Unsupervised Feature Learning via Non-parametric
Instance Discrimination (https://arxiv.org/abs/1805.0... | 4,658 | 34.564885 | 88 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/models/byol.py | import torch
import torch.nn as nn
from openselfsup.utils import print_log
from . import builder
from .registry import MODELS
@MODELS.register_module
class BYOL(nn.Module):
"""BYOL.
Implementation of "Bootstrap Your Own Latent: A New Approach to
Self-Supervised Learning (https://arxiv.org/abs/2006.0773... | 4,225 | 36.070175 | 88 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/models/__init__.py | from .backbones import * # noqa: F401,F403
from .builder import (build_backbone, build_model, build_head, build_loss)
from .byol import BYOL
from .heads import *
from .classification import Classification
from .deepcluster import DeepCluster
from .odc import ODC
from .necks import *
from .npid import NPID
from .memori... | 594 | 34 | 74 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/models/builder.py | from torch import nn
from openselfsup.utils import build_from_cfg
from .registry import (BACKBONES, MODELS, NECKS, HEADS, MEMORIES, LOSSES)
def build(cfg, registry, default_args=None):
"""Build a module.
Args:
cfg (dict, list[dict]): The config of modules, it is either a dict
or a list o... | 1,274 | 21.368421 | 77 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/models/odc.py | import numpy as np
import torch
import torch.nn as nn
from openselfsup.utils import print_log
from . import builder
from .registry import MODELS
from .utils import Sobel
@MODELS.register_module
class ODC(nn.Module):
"""ODC.
Official implementation of
"Online Deep Clustering for Unsupervised Representati... | 5,322 | 34.966216 | 88 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/models/necks.py | import torch
import torch.nn as nn
from packaging import version
from mmcv.cnn import kaiming_init, normal_init
from .registry import NECKS
from .utils import build_norm_layer
def _init_weights(module, init_linear='normal', std=0.01, bias=0.):
assert init_linear in ['normal', 'kaiming'], \
"Undefined ini... | 11,269 | 30.836158 | 85 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/models/memories/simple_memory.py | import torch
import torch.nn as nn
import torch.distributed as dist
from mmcv.runner import get_dist_info
from openselfsup.utils import AliasMethod
from ..registry import MEMORIES
@MEMORIES.register_module
class SimpleMemory(nn.Module):
"""Simple memory bank for NPID.
Args:
length (int): Number of f... | 2,305 | 33.939394 | 77 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/models/memories/odc_memory.py | import numpy as np
from sklearn.cluster import KMeans
import torch
import torch.nn as nn
import torch.distributed as dist
from mmcv.runner import get_dist_info
from ..registry import MEMORIES
@MEMORIES.register_module
class ODCMemory(nn.Module):
"""Memory modules for ODC.
Args:
length (int): Number... | 10,441 | 43.623932 | 81 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/models/memories/__init__.py | from .odc_memory import ODCMemory
from .simple_memory import SimpleMemory
| 74 | 24 | 39 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/models/utils/multi_pooling.py | import torch.nn as nn
class MultiPooling(nn.Module):
"""Pooling layers for features from multiple depth."""
POOL_PARAMS = {
'resnet50': [
dict(kernel_size=10, stride=10, padding=4),
dict(kernel_size=16, stride=8, padding=0),
dict(kernel_size=13, stride=5, padding=0... | 1,280 | 31.846154 | 66 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/models/utils/norm.py | import torch.nn as nn
norm_cfg = {
# format: layer_type: (abbreviation, module)
'BN': ('bn', nn.BatchNorm2d),
'SyncBN': ('bn', nn.SyncBatchNorm),
'GN': ('gn', nn.GroupNorm),
# and potentially 'SN'
}
def build_norm_layer(cfg, num_features, postfix=''):
"""Build normalization layer.
Args:
... | 1,684 | 29.089286 | 74 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/models/utils/scale.py | import torch
import torch.nn as nn
class Scale(nn.Module):
"""A learnable scale parameter."""
def __init__(self, scale=1.0):
super(Scale, self).__init__()
self.scale = nn.Parameter(torch.tensor(scale, dtype=torch.float))
def forward(self, x):
return x * self.scale
| 305 | 20.857143 | 73 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/models/utils/sobel.py | import torch
import torch.nn as nn
class Sobel(nn.Module):
"""Sobel layer."""
def __init__(self):
super(Sobel, self).__init__()
grayscale = nn.Conv2d(3, 1, kernel_size=1, stride=1, padding=0)
grayscale.weight.data.fill_(1.0 / 3.0)
grayscale.bias.data.zero_()
sobel_filt... | 840 | 32.64 | 74 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/models/utils/conv_ws.py | import torch.nn as nn
import torch.nn.functional as F
def conv_ws_2d(input,
weight,
bias=None,
stride=1,
padding=0,
dilation=1,
groups=1,
eps=1e-5):
c_in = weight.size(0)
weight_flat = weight.view(c_in, -1... | 1,335 | 27.425532 | 79 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/models/utils/conv_module.py | import warnings
import torch.nn as nn
from mmcv.cnn import constant_init, kaiming_init
from .conv_ws import ConvWS2d
from .norm import build_norm_layer
conv_cfg = {
'Conv': nn.Conv2d,
'ConvWS': ConvWS2d,
}
def build_conv_layer(cfg, *args, **kwargs):
"""Build convolution layer.
Args:
cfg (N... | 5,723 | 33.902439 | 78 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/models/utils/accuracy.py | import torch.nn as nn
def accuracy(pred, target, topk=1):
assert isinstance(topk, (int, tuple))
if isinstance(topk, int):
topk = (topk, )
return_single = True
else:
return_single = False
maxk = max(topk)
_, pred_label = pred.topk(maxk, dim=1)
pred_label = pred_label.t(... | 801 | 24.0625 | 69 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/models/utils/gather_layer.py | import torch
import torch.distributed as dist
class GatherLayer(torch.autograd.Function):
"""Gather tensors from all process, supporting backward propagation.
"""
@staticmethod
def forward(ctx, input):
ctx.save_for_backward(input)
output = [torch.zeros_like(input) \
for _ ... | 618 | 25.913043 | 72 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/models/utils/__init__.py | from .accuracy import Accuracy, accuracy
from .conv_module import ConvModule, build_conv_layer
from .conv_ws import ConvWS2d, conv_ws_2d
from .gather_layer import GatherLayer
from .multi_pooling import MultiPooling
from .norm import build_norm_layer
from .scale import Scale
#from .weight_init import (bias_init_with_pro... | 643 | 36.882353 | 74 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/models/backbones/resnet.py | import torch.nn as nn
import torch.utils.checkpoint as cp
from mmcv.cnn import constant_init, kaiming_init
from mmcv.runner import load_checkpoint
from torch.nn.modules.batchnorm import _BatchNorm
from openselfsup.utils import get_root_logger
from ..registry import BACKBONES
from ..utils import build_conv_layer, build... | 13,648 | 30.74186 | 79 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/models/backbones/resnext.py | import math
import torch.nn as nn
from ..registry import BACKBONES
from ..utils import build_conv_layer, build_norm_layer
from .resnet import Bottleneck as _Bottleneck
from .resnet import ResNet
class Bottleneck(_Bottleneck):
def __init__(self, inplanes, planes, groups=1, base_width=4, **kwargs):
"""Bo... | 7,594 | 33.058296 | 79 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/models/backbones/__init__.py | from .resnet import ResNet, make_res_layer
| 43 | 21 | 42 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/models/heads/contrastive_head.py | import torch
import torch.nn as nn
from ..registry import HEADS
@HEADS.register_module
class ContrastiveHead(nn.Module):
"""Head for contrastive learning.
Args:
temperature (float): The temperature hyper-parameter that
controls the concentration level of the distribution.
Def... | 1,053 | 26.025641 | 65 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/models/heads/cls_head.py | import torch.nn as nn
from mmcv.cnn import kaiming_init, normal_init
from ..utils import accuracy
from ..registry import HEADS
@HEADS.register_module
class ClsHead(nn.Module):
"""Simplest classifier head, with only one fc layer.
"""
def __init__(self,
with_avg_pool=False,
... | 2,119 | 33.754098 | 78 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/models/heads/__init__.py | from .contrastive_head import ContrastiveHead
from .cls_head import ClsHead
from .latent_pred_head import LatentPredictHead
from .multi_cls_head import MultiClsHead
| 165 | 32.2 | 47 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/models/heads/multi_cls_head.py | import torch.nn as nn
from ..utils import accuracy
from ..registry import HEADS
from ..utils import build_norm_layer, MultiPooling
@HEADS.register_module
class MultiClsHead(nn.Module):
"""Multiple classifier heads.
"""
FEAT_CHANNELS = {'resnet50': [64, 256, 512, 1024, 2048]}
FEAT_LAST_UNPOOL = {'res... | 2,682 | 32.962025 | 78 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/models/heads/latent_pred_head.py | import torch
import torch.nn as nn
from mmcv.cnn import normal_init
from ..registry import HEADS
from .. import builder
@HEADS.register_module
class LatentPredictHead(nn.Module):
"""Head for contrastive learning.
"""
def __init__(self, predictor, size_average=True):
super(LatentPredictHead, self)... | 2,048 | 28.695652 | 72 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/datasets/base.py | from abc import ABCMeta, abstractmethod
import torch
from torch.utils.data import Dataset
from openselfsup.utils import print_log, build_from_cfg
from torchvision.transforms import Compose
from .registry import DATASETS, PIPELINES
from .builder import build_datasource
class BaseDataset(Dataset, metaclass=ABCMeta)... | 1,105 | 26.65 | 76 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/datasets/classification.py | import torch
from openselfsup.utils import print_log
from .registry import DATASETS
from .base import BaseDataset
from .utils import to_numpy
@DATASETS.register_module
class ClassificationDataset(BaseDataset):
"""Dataset for classification.
"""
def __init__(self, data_source, pipeline, prefetch=False):... | 1,565 | 33.8 | 84 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/datasets/extraction.py | from .registry import DATASETS
from .base import BaseDataset
@DATASETS.register_module
class ExtractDataset(BaseDataset):
"""Dataset for feature extraction.
"""
def __init__(self, data_source, pipeline):
super(ExtractDataset, self).__init__(data_source, pipeline)
def __getitem__(self, idx):
... | 513 | 24.7 | 67 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/datasets/rotation_pred.py | import torch
from PIL import Image
from .registry import DATASETS
from .base import BaseDataset
def rotate(img):
"""Rotate input image with 0, 90, 180, and 270 degrees.
Args:
img (Tensor): input image of shape (C, H, W).
Returns:
list[Tensor]: A list of four rotated images.
"""
... | 1,288 | 27.021739 | 78 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/datasets/deepcluster.py | from PIL import Image
from .registry import DATASETS
from .base import BaseDataset
@DATASETS.register_module
class DeepClusterDataset(BaseDataset):
"""Dataset for DC and ODC.
"""
def __init__(self, data_source, pipeline):
super(DeepClusterDataset, self).__init__(data_source, pipeline)
# i... | 1,161 | 32.2 | 78 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/datasets/relative_loc.py | from openselfsup.utils import build_from_cfg
import torch
from PIL import Image
from torchvision.transforms import Compose, RandomCrop
import torchvision.transforms.functional as TF
from .registry import DATASETS, PIPELINES
from .base import BaseDataset
def image_to_patches(img):
"""Crop split_per_side x split_... | 2,327 | 34.272727 | 94 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/datasets/registry.py | from openselfsup.utils import Registry
DATASOURCES = Registry('datasource')
DATASETS = Registry('dataset')
PIPELINES = Registry('pipeline')
| 141 | 22.666667 | 38 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/datasets/utils.py | import numpy as np
def to_numpy(pil_img):
np_img = np.array(pil_img, dtype=np.uint8)
if np_img.ndim < 3:
np_img = np.expand_dims(np_img, axis=-1)
np_img = np.rollaxis(np_img, 2) # HWC to CHW
return np_img
| 232 | 22.3 | 49 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/datasets/dataset_wrappers.py | import numpy as np
from torch.utils.data.dataset import ConcatDataset as _ConcatDataset
from .registry import DATASETS
@DATASETS.register_module
class ConcatDataset(_ConcatDataset):
"""A wrapper of concatenated dataset.
Same as :obj:`torch.utils.data.dataset.ConcatDataset`, but
concat the group flag for... | 1,639 | 28.285714 | 78 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/datasets/npid.py | from PIL import Image
from .registry import DATASETS
from .base import BaseDataset
@DATASETS.register_module
class NPIDDataset(BaseDataset):
"""Dataset for NPID.
"""
def __init__(self, data_source, pipeline):
super(NPIDDataset, self).__init__(data_source, pipeline)
def __getitem__(self, idx)... | 748 | 27.807692 | 78 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/datasets/byol.py | import torch
from torch.utils.data import Dataset
from openselfsup.utils import build_from_cfg
from torchvision.transforms import Compose
from .registry import DATASETS, PIPELINES
from .builder import build_datasource
from .utils import to_numpy
@DATASETS.register_module
class BYOLDataset(Dataset):
"""Dataset ... | 1,284 | 29.595238 | 74 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/datasets/__init__.py | from .builder import build_dataset
from .byol import BYOLDataset
from .data_sources import *
from .pipelines import *
from .classification import ClassificationDataset
from .deepcluster import DeepClusterDataset
from .extraction import ExtractDataset
from .npid import NPIDDataset
from .rotation_pred import RotationPred... | 583 | 37.933333 | 75 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/datasets/contrastive.py | import torch
from PIL import Image
from .registry import DATASETS
from .base import BaseDataset
from .utils import to_numpy
@DATASETS.register_module
class ContrastiveDataset(BaseDataset):
"""Dataset for contrastive learning methods that forward
two views of the image at a time (MoCo, SimCLR).
"""
... | 1,210 | 34.617647 | 81 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/datasets/builder.py | import copy
from openselfsup.utils import build_from_cfg
from .dataset_wrappers import ConcatDataset, RepeatDataset
from .registry import DATASETS, DATASOURCES
def _concat_dataset(cfg, default_args=None):
ann_files = cfg['ann_file']
img_prefixes = cfg.get('img_prefix', None)
seg_prefixes = cfg.get('seg_p... | 1,441 | 31.772727 | 78 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/datasets/data_sources/image_list.py | import os
from PIL import Image
from ..registry import DATASOURCES
from .utils import McLoader
@DATASOURCES.register_module
class ImageList(object):
def __init__(self, root, list_file, memcached=False, mclient_path=None, return_label=True):
with open(list_file, 'r') as f:
lines = f.readlines... | 1,541 | 30.469388 | 95 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/datasets/data_sources/utils.py | import io
from PIL import Image
try:
import mc
except ImportError as E:
pass
def pil_loader(img_str):
buff = io.BytesIO(img_str)
return Image.open(buff)
class McLoader(object):
def __init__(self, mclient_path):
assert mclient_path is not None, \
"Please specify 'data_mclient... | 1,060 | 27.675676 | 78 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/datasets/data_sources/__init__.py | from .cifar import Cifar10, Cifar100
from .image_list import ImageList
from .imagenet import ImageNet
from .places205 import Places205
| 135 | 26.2 | 36 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/datasets/data_sources/cifar.py | from abc import ABCMeta, abstractmethod
from PIL import Image
from torchvision.datasets import CIFAR10, CIFAR100
from ..registry import DATASOURCES
class Cifar(metaclass=ABCMeta):
CLASSES = None
def __init__(self, root, split, return_label=True):
assert split in ['train', 'test']
self.root... | 1,990 | 26.273973 | 76 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/datasets/data_sources/imagenet.py | from ..registry import DATASOURCES
from .image_list import ImageList
@DATASOURCES.register_module
class ImageNet(ImageList):
def __init__(self, root, list_file, memcached, mclient_path, return_label=True, *args, **kwargs):
super(ImageNet, self).__init__(
root, list_file, memcached, mclient_pa... | 338 | 29.818182 | 101 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/datasets/data_sources/places205.py | from ..registry import DATASOURCES
from .image_list import ImageList
@DATASOURCES.register_module
class Places205(ImageList):
def __init__(self, root, list_file, memcached, mclient_path, return_label=True, *args, **kwargs):
super(Places205, self).__init__(
root, list_file, memcached, mclient_... | 340 | 30 | 101 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/datasets/loader/sampler.py | from __future__ import division
import math
import numpy as np
import torch
from mmcv.runner import get_dist_info
from torch.utils.data import DistributedSampler as _DistributedSampler
from torch.utils.data import Sampler
class DistributedSampler(_DistributedSampler):
def __init__(self,
dataset... | 10,628 | 34.079208 | 92 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/datasets/loader/build_loader.py | import platform
import random
import torch
from functools import partial
import numpy as np
from mmcv.parallel import collate
from mmcv.runner import get_dist_info
from torch.utils.data import DataLoader
#from .sampler import DistributedGroupSampler, DistributedSampler, GroupSampler
from .sampler import DistributedSa... | 4,179 | 30.428571 | 92 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/datasets/loader/__init__.py | from .build_loader import build_dataloader
from .sampler import DistributedGroupSampler, GroupSampler, DistributedGivenIterationSampler
__all__ = [
'GroupSampler', 'DistributedGroupSampler', 'build_dataloader',
'DistributedGivenIterationSampler'
]
| 257 | 31.25 | 92 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/datasets/pipelines/__init__.py | from .transforms import *
| 26 | 12.5 | 25 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/datasets/pipelines/transforms.py | import cv2
import inspect
import numpy as np
from PIL import Image, ImageFilter
import torch
from torchvision import transforms as _transforms
from openselfsup.utils import build_from_cfg
from ..registry import PIPELINES
# register all existing transforms in torchvision
_EXCLUDED_TRANSFORMS = ['GaussianBlur']
for ... | 3,142 | 26.330435 | 80 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/hooks/optimizer_hook.py | from mmcv.runner import OptimizerHook
try:
import apex
except:
print('apex is not installed')
class DistOptimizerHook(OptimizerHook):
"""Optimizer hook for distributed training."""
def __init__(self, update_interval=1, grad_clip=None, coalesce=True, bucket_size_mb=-1, use_fp16=False):
self.gra... | 1,125 | 34.1875 | 108 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/hooks/byol_hook.py | from math import cos, pi
from mmcv.runner import Hook
from mmcv.parallel import is_module_wrapper
from .registry import HOOKS
@HOOKS.register_module
class BYOLHook(Hook):
"""Hook for BYOL.
This hook includes momentum adjustment in BYOL following:
m = 1 - ( 1- m_0) * (cos(pi * k / K) + 1) / 2,
... | 1,590 | 35.159091 | 75 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/hooks/registry.py | from openselfsup.utils import Registry
HOOKS = Registry('hook')
| 65 | 15.5 | 38 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/hooks/extractor.py | import torch.nn as nn
from torch.utils.data import Dataset
from openselfsup.utils import nondist_forward_collect, dist_forward_collect
class Extractor(object):
"""Feature extractor.
Args:
dataset (Dataset | dict): A PyTorch dataset or dict that indicates
the dataset.
imgs_per_gpu... | 2,196 | 34.435484 | 77 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/hooks/validate_hook.py | from mmcv.runner import Hook
import torch
from torch.utils.data import Dataset
from openselfsup.utils import nondist_forward_collect, dist_forward_collect
from .registry import HOOKS
@HOOKS.register_module
class ValidateHook(Hook):
"""Validation hook.
Args:
dataset (Dataset | dict): A PyTorch datas... | 3,003 | 33.528736 | 77 | py |
Few-shot-WSI | Few-shot-WSI-master/openselfsup/hooks/odc_hook.py | import numpy as np
from mmcv.runner import Hook
from openselfsup.utils import print_log
from .registry import HOOKS
@HOOKS.register_module
class ODCHook(Hook):
"""Hook for ODC.
Args:
centroids_update_interval (int): Frequency of iterations
to update centroids.
deal_with_small_cl... | 3,020 | 36.7625 | 78 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.