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 |
|---|---|---|---|---|---|---|
Swin-Transformer-Semantic-Segmentation-mmseg | Swin-Transformer-Semantic-Segmentation-mmseg-master/configs/_base_/models/fpn_r50.py | # model settings
norm_cfg = dict(type='SyncBN', requires_grad=True)
model = dict(
type='EncoderDecoder',
pretrained='open-mmlab://resnet50_v1c',
backbone=dict(
type='ResNetV1c',
depth=50,
num_stages=4,
out_indices=(0, 1, 2, 3),
dilations=(1, 1, 1, 1),
strides=... | 1,056 | 27.567568 | 74 | py |
Swin-Transformer-Semantic-Segmentation-mmseg | Swin-Transformer-Semantic-Segmentation-mmseg-master/configs/_base_/models/deeplabv3_r50-d8.py | # model settings
norm_cfg = dict(type='SyncBN', requires_grad=True)
model = dict(
type='EncoderDecoder',
pretrained='open-mmlab://resnet50_v1c',
backbone=dict(
type='ResNetV1c',
depth=50,
num_stages=4,
out_indices=(0, 1, 2, 3),
dilations=(1, 1, 2, 4),
strides=... | 1,273 | 27.311111 | 74 | py |
Swin-Transformer-Semantic-Segmentation-mmseg | Swin-Transformer-Semantic-Segmentation-mmseg-master/configs/_base_/models/pointrend_r50.py | # model settings
norm_cfg = dict(type='SyncBN', requires_grad=True)
model = dict(
type='CascadeEncoderDecoder',
num_stages=2,
pretrained='open-mmlab://resnet50_v1c',
backbone=dict(
type='ResNetV1c',
depth=50,
num_stages=4,
out_indices=(0, 1, 2, 3),
dilations=(1, 1... | 1,704 | 28.912281 | 78 | py |
Swin-Transformer-Semantic-Segmentation-mmseg | Swin-Transformer-Semantic-Segmentation-mmseg-master/configs/_base_/models/ocrnet_r50-d8.py | # model settings
norm_cfg = dict(type='SyncBN', requires_grad=True)
model = dict(
type='CascadeEncoderDecoder',
num_stages=2,
pretrained='open-mmlab://resnet50_v1c',
backbone=dict(
type='ResNetV1c',
depth=50,
num_stages=4,
out_indices=(0, 1, 2, 3),
dilations=(1, 1... | 1,385 | 27.875 | 78 | py |
Swin-Transformer-Semantic-Segmentation-mmseg | Swin-Transformer-Semantic-Segmentation-mmseg-master/configs/_base_/models/nonlocal_r50-d8.py | # model settings
norm_cfg = dict(type='SyncBN', requires_grad=True)
model = dict(
type='EncoderDecoder',
pretrained='open-mmlab://resnet50_v1c',
backbone=dict(
type='ResNetV1c',
depth=50,
num_stages=4,
out_indices=(0, 1, 2, 3),
dilations=(1, 1, 2, 4),
strides=... | 1,315 | 27 | 74 | py |
Swin-Transformer-Semantic-Segmentation-mmseg | Swin-Transformer-Semantic-Segmentation-mmseg-master/configs/_base_/models/fcn_r50-d8.py | # model settings
norm_cfg = dict(type='SyncBN', requires_grad=True)
model = dict(
type='EncoderDecoder',
pretrained='open-mmlab://resnet50_v1c',
backbone=dict(
type='ResNetV1c',
depth=50,
num_stages=4,
out_indices=(0, 1, 2, 3),
dilations=(1, 1, 2, 4),
strides=... | 1,285 | 26.956522 | 74 | py |
Swin-Transformer-Semantic-Segmentation-mmseg | Swin-Transformer-Semantic-Segmentation-mmseg-master/configs/deeplabv3plus/deeplabv3plus_r101b-d8_512x1024_80k_cityscapes.py | _base_ = './deeplabv3plus_r50-d8_512x1024_80k_cityscapes.py'
model = dict(
pretrained='torchvision://resnet101',
backbone=dict(type='ResNet', depth=101))
| 162 | 31.6 | 60 | py |
Swin-Transformer-Semantic-Segmentation-mmseg | Swin-Transformer-Semantic-Segmentation-mmseg-master/configs/deeplabv3plus/deeplabv3plus_r18b-d8_512x1024_80k_cityscapes.py | _base_ = './deeplabv3plus_r50-d8_512x1024_80k_cityscapes.py'
model = dict(
pretrained='torchvision://resnet18',
backbone=dict(type='ResNet', depth=18),
decode_head=dict(
c1_in_channels=64,
c1_channels=12,
in_channels=512,
channels=128,
),
auxiliary_head=dict(in_channe... | 342 | 27.583333 | 60 | py |
Swin-Transformer-Semantic-Segmentation-mmseg | Swin-Transformer-Semantic-Segmentation-mmseg-master/configs/deeplabv3plus/deeplabv3plus_r18b-d8_769x769_80k_cityscapes.py | _base_ = './deeplabv3plus_r50-d8_769x769_80k_cityscapes.py'
model = dict(
pretrained='torchvision://resnet18',
backbone=dict(type='ResNet', depth=18),
decode_head=dict(
c1_in_channels=64,
c1_channels=12,
in_channels=512,
channels=128,
),
auxiliary_head=dict(in_channel... | 341 | 27.5 | 59 | py |
Swin-Transformer-Semantic-Segmentation-mmseg | Swin-Transformer-Semantic-Segmentation-mmseg-master/configs/deeplabv3plus/deeplabv3plus_r50b-d8_769x769_80k_cityscapes.py | _base_ = './deeplabv3plus_r50-d8_769x769_80k_cityscapes.py'
model = dict(pretrained='torchvision://resnet50', backbone=dict(type='ResNet'))
| 140 | 46 | 79 | py |
Swin-Transformer-Semantic-Segmentation-mmseg | Swin-Transformer-Semantic-Segmentation-mmseg-master/configs/deeplabv3plus/deeplabv3plus_r101b-d8_769x769_80k_cityscapes.py | _base_ = './deeplabv3plus_r50-d8_769x769_80k_cityscapes.py'
model = dict(
pretrained='torchvision://resnet101',
backbone=dict(type='ResNet', depth=101))
| 161 | 31.4 | 59 | py |
Swin-Transformer-Semantic-Segmentation-mmseg | Swin-Transformer-Semantic-Segmentation-mmseg-master/configs/deeplabv3plus/deeplabv3plus_r50b-d8_512x1024_80k_cityscapes.py | _base_ = './deeplabv3plus_r50-d8_512x1024_80k_cityscapes.py'
model = dict(pretrained='torchvision://resnet50', backbone=dict(type='ResNet'))
| 141 | 46.333333 | 79 | py |
Swin-Transformer-Semantic-Segmentation-mmseg | Swin-Transformer-Semantic-Segmentation-mmseg-master/configs/deeplabv3/deeplabv3_r18b-d8_769x769_80k_cityscapes.py | _base_ = './deeplabv3_r50-d8_769x769_80k_cityscapes.py'
model = dict(
pretrained='torchvision://resnet18',
backbone=dict(type='ResNet', depth=18),
decode_head=dict(
in_channels=512,
channels=128,
),
auxiliary_head=dict(in_channels=256, channels=64))
| 286 | 27.7 | 55 | py |
Swin-Transformer-Semantic-Segmentation-mmseg | Swin-Transformer-Semantic-Segmentation-mmseg-master/configs/deeplabv3/deeplabv3_r101b-d8_769x769_80k_cityscapes.py | _base_ = './deeplabv3_r50-d8_769x769_80k_cityscapes.py'
model = dict(
pretrained='torchvision://resnet101',
backbone=dict(type='ResNet', depth=101))
| 157 | 30.6 | 55 | py |
Swin-Transformer-Semantic-Segmentation-mmseg | Swin-Transformer-Semantic-Segmentation-mmseg-master/configs/deeplabv3/deeplabv3_r101b-d8_512x1024_80k_cityscapes.py | _base_ = './deeplabv3_r50-d8_512x1024_80k_cityscapes.py'
model = dict(
pretrained='torchvision://resnet101',
backbone=dict(type='ResNet', depth=101))
| 158 | 30.8 | 56 | py |
Swin-Transformer-Semantic-Segmentation-mmseg | Swin-Transformer-Semantic-Segmentation-mmseg-master/configs/deeplabv3/deeplabv3_r50b-d8_769x769_80k_cityscapes.py | _base_ = './deeplabv3_r50-d8_769x769_80k_cityscapes.py'
model = dict(pretrained='torchvision://resnet50', backbone=dict(type='ResNet'))
| 136 | 44.666667 | 79 | py |
Swin-Transformer-Semantic-Segmentation-mmseg | Swin-Transformer-Semantic-Segmentation-mmseg-master/configs/deeplabv3/deeplabv3_r50b-d8_512x1024_80k_cityscapes.py | _base_ = './deeplabv3_r50-d8_512x1024_80k_cityscapes.py'
model = dict(pretrained='torchvision://resnet50', backbone=dict(type='ResNet'))
| 137 | 45 | 79 | py |
Swin-Transformer-Semantic-Segmentation-mmseg | Swin-Transformer-Semantic-Segmentation-mmseg-master/configs/deeplabv3/deeplabv3_r18b-d8_512x1024_80k_cityscapes.py | _base_ = './deeplabv3_r50-d8_512x1024_80k_cityscapes.py'
model = dict(
pretrained='torchvision://resnet18',
backbone=dict(type='ResNet', depth=18),
decode_head=dict(
in_channels=512,
channels=128,
),
auxiliary_head=dict(in_channels=256, channels=64))
| 287 | 27.8 | 56 | py |
Swin-Transformer-Semantic-Segmentation-mmseg | Swin-Transformer-Semantic-Segmentation-mmseg-master/.dev/gather_models.py | import argparse
import glob
import json
import os
import os.path as osp
import shutil
import subprocess
import mmcv
import torch
# build schedule look-up table to automatically find the final model
RESULTS_LUT = ['mIoU', 'mAcc', 'aAcc']
def process_checkpoint(in_file, out_file):
checkpoint = torch.load(in_file,... | 6,967 | 34.191919 | 79 | py |
ml2 | ml2-main/ml2/experiment.py | """Base experiment class"""
import argparse
import inspect
import json
import logging
import os
from typing import Dict
from ray import tune
from ray.tune.integration.wandb import WandbLoggerCallback
import wandb
from wandb.keras import WandbCallback
import tensorflow as tf
from .artifact import Artifact
from .gcp_b... | 19,476 | 35.270019 | 99 | py |
ml2 | ml2-main/ml2/seq2seq_experiment.py | """Prototypical class for sequence to sequence experiments"""
import logging
import os
from tensorflow import keras
from .experiment import Experiment
logger = logging.getLogger(__name__)
class EncoderErrorCallback(keras.callbacks.Callback):
def __init__(self, dataset, model_dir):
super().__init__()
... | 5,532 | 37.692308 | 99 | py |
ml2 | ml2-main/ml2/models/transformer.py | """Transformer implementation
The Transformer architecture was introduced in https://arxiv.org/abs/1706.03762
The implementation is partially based on https://github.com/tensorflow/models/blob/master/official/nlp/transformer/transformer.py
"""
import tensorflow as tf
from ..layers import attention
from ..layers impo... | 24,986 | 42.913884 | 130 | py |
ml2 | ml2-main/ml2/models/hierarchical_transformer_2d.py | """Hierarchical Transformer implementation
The hierarchical Transformer architecture was introduced in https://arxiv.org/abs/2006.09265
"""
import tensorflow as tf
from ..layers import positional_encoding as pe
from . import transformer
from .beam_search import BeamSearch, flatten_beam_dim
def create_model(params,... | 18,011 | 43.255528 | 149 | py |
ml2 | ml2-main/ml2/layers/attention.py | """Implementation of scaled dot-product attention and multi-head attention as described in 'Attention Is All You Need' (Vaswani et al., 2017) based on https://www.tensorflow.org/tutorials/text/transformer"""
import tensorflow as tf
def scaled_dot_product_attention(queries, keys, values, mask=None, dtype=tf.float32):... | 6,064 | 40.541096 | 207 | py |
ml2 | ml2-main/ml2/optimization/lr_schedules.py | """Learning rate schedules"""
import tensorflow as tf
class TransformerSchedule(tf.keras.optimizers.schedules.LearningRateSchedule):
"""Learning Rate Schedule proposed by Vaswani et al. (2017) that corresponds to a linear increase
during the warmup phase followed by a decrease proportional to the inverse of ... | 888 | 36.041667 | 101 | py |
ml2 | ml2-main/ml2/ltl/ltl_syn/ltl_syn_transformer_experiment.py | """LTL synthesis using the Transformer"""
import logging
import sys
import numpy as np
import tensorflow as tf
from ... import models
from ...data import ExprNotation, TPEFormat
from ...optimization import lr_schedules
from ..ltl_spec import LTLSpecTreeEncoder
from .ltl_syn_experiment import LTLSynExperiment
logging... | 8,134 | 40.93299 | 98 | py |
ml2 | ml2-main/ml2/ltl/ltl_syn/ltl_syn_hier_transformer_experiment.py | """LTL synthesis using hierarchical Transformer"""
import logging
import numpy as np
import sys
import tensorflow as tf
from ... import models
from ...data import TPEFormat
from ...data import ExprNotation
from ...optimization import lr_schedules
from ..ltl_spec import LTLSpecPropertyEncoder
from .ltl_syn_experiment... | 11,685 | 43.098113 | 99 | py |
ml2 | ml2-main/ml2/ltl/ltl_sat/ltl_sat_transformer_experiment.py | """LTL synthesis using the Transformer"""
import logging
import numpy as np
import tensorflow as tf
from ... import models
from ...data import ExprNotation, TPEFormat
from ...optimization import lr_schedules
from ..ltl_encoder import LTLTreeEncoder
from .ltl_sat_experiment import LTLSatExperiment
logging.basicConfig... | 9,138 | 39.799107 | 98 | py |
ml2 | ml2-main/ml2/prop/prop_sat_transformer_experiment.py | """Propositional satisfiability with the Transformer"""
import logging
import numpy as np
import tensorflow as tf
from .. import models
from ..data import ExprNotation, TPEFormat
from ..optimization import lr_schedules
from .prop_encoder import PropTreeEncoder
from .prop_sat_experiment import PropSatExperiment
loggi... | 9,156 | 39.879464 | 98 | py |
Detect-AnyShadow | Detect-AnyShadow-main/sam_test.py | import os
os.environ['CUDA_VISIBLE_DEVICES'] = '6'
import torch
import numpy as np
import cv2
import json
from tqdm import tqdm
from sam import sam_model_registry
from sam.utils.transforms import ResizeLongestSide
def main():
sam_checkpoint = "./checkpoints/chk_sam/finetune.pth"
model_type = "vit_b"
dev... | 3,483 | 37.711111 | 111 | py |
Detect-AnyShadow | Detect-AnyShadow-main/sam_finetune.py | # finetune the sam model on the visha dataset
import os
os.environ['CUDA_VISIBLE_DEVICES'] = '7'
import cv2
import json
import random
from tqdm import tqdm
from statistics import mean
import torch
import numpy as np
from sam import sam_model_registry
from sam.utils.transforms import ResizeLongestSide
def get_train... | 5,262 | 38.871212 | 115 | py |
Detect-AnyShadow | Detect-AnyShadow-main/demo_app.py | import os
os.environ['CUDA_VISIBLE_DEVICES'] = '6'
import sys
sys.path.append('./lstn')
import torch
import torchvision
import numpy as np
import cv2
from skimage import measure
import gradio as gr
from sam import sam_model_registry
from sam.utils.transforms import ResizeLongestSide
from tool.mask_tool import mask... | 10,572 | 33.327922 | 135 | py |
Detect-AnyShadow | Detect-AnyShadow-main/sam/automatic_mask_generator.py | # Copyright (c) Meta Platforms, Inc. and 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.
import numpy as np
import torch
from torchvision.ops.boxes import batched_nms, box_area # type: ignore
from typing impor... | 15,148 | 39.613941 | 92 | py |
Detect-AnyShadow | Detect-AnyShadow-main/sam/predictor.py | # Copyright (c) Meta Platforms, Inc. and 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.
import numpy as np
import torch
from sam.modeling import Sam
from typing import Optional, Tuple
from .utils.transforms ... | 11,636 | 42.1 | 100 | py |
Detect-AnyShadow | Detect-AnyShadow-main/sam/build_sam.py | # Copyright (c) Meta Platforms, Inc. and 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.
import torch
from functools import partial
from .modeling import ImageEncoderViT, MaskDecoder, PromptEncoder, Sam, TwoWa... | 2,941 | 26.240741 | 89 | py |
Detect-AnyShadow | Detect-AnyShadow-main/sam/utils/onnx.py | # Copyright (c) Meta Platforms, Inc. and 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.
import torch
import torch.nn as nn
from torch.nn import functional as F
from typing import Tuple
from ..modeling import ... | 5,812 | 39.089655 | 100 | py |
Detect-AnyShadow | Detect-AnyShadow-main/sam/utils/amg.py | # Copyright (c) Meta Platforms, Inc. and 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.
import numpy as np
import torch
import math
from copy import deepcopy
from itertools import product
from typing import An... | 12,712 | 35.636888 | 88 | py |
Detect-AnyShadow | Detect-AnyShadow-main/sam/utils/transforms.py | # Copyright (c) Meta Platforms, Inc. and 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.
import numpy as np
import torch
from torch.nn import functional as F
from torchvision.transforms.functional import resize,... | 3,972 | 37.572816 | 99 | py |
Detect-AnyShadow | Detect-AnyShadow-main/sam/modeling/mask_decoder.py | # Copyright (c) Meta Platforms, Inc. and 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.
import torch
from torch import nn
from torch.nn import functional as F
from typing import List, Tuple, Type
from .common... | 6,725 | 36.366667 | 123 | py |
Detect-AnyShadow | Detect-AnyShadow-main/sam/modeling/image_encoder.py | # Copyright (c) Meta Platforms, Inc. and 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.
import torch
import torch.nn as nn
import torch.nn.functional as F
from typing import Optional, Tuple, Type
from .common... | 14,420 | 35.416667 | 202 | py |
Detect-AnyShadow | Detect-AnyShadow-main/sam/modeling/prompt_encoder.py | # Copyright (c) Meta Platforms, Inc. and 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.
import numpy as np
import torch
from torch import nn
from typing import Any, Optional, Tuple, Type
from .common import L... | 8,594 | 38.976744 | 97 | py |
Detect-AnyShadow | Detect-AnyShadow-main/sam/modeling/transformer.py | # Copyright (c) Meta Platforms, Inc. and 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.
import torch
from torch import Tensor, nn
import math
from typing import Tuple, Type
from .common import MLPBlock
clas... | 8,397 | 33.846473 | 89 | py |
Detect-AnyShadow | Detect-AnyShadow-main/sam/modeling/common.py | # Copyright (c) Meta Platforms, Inc. and 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.
import torch
import torch.nn as nn
from typing import Type
class MLPBlock(nn.Module):
def __init__(
self,
... | 1,479 | 32.636364 | 136 | py |
Detect-AnyShadow | Detect-AnyShadow-main/sam/modeling/sam.py | # Copyright (c) Meta Platforms, Inc. and 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.
import torch
from torch import nn
from torch.nn import functional as F
from typing import Any, Dict, List, Tuple
from .i... | 8,518 | 38.995305 | 95 | py |
Detect-AnyShadow | Detect-AnyShadow-main/lstn/tools/train.py | import importlib
import sys
import os
sys.setrecursionlimit(10000)
dir_path = os.path.dirname(os.path.realpath(__file__))
parent_dir_path = os.path.abspath(os.path.join(dir_path, os.pardir))
sys.path.insert(0, parent_dir_path)
import random
import torch.multiprocessing as mp
from networks.managers.trainer import Trai... | 1,714 | 35.489362 | 98 | py |
Detect-AnyShadow | Detect-AnyShadow-main/lstn/networks/managers/evaluator.py | import os
import time
import datetime as datetime
import json
import numpy as np
import torch
import torch.nn.functional as F
from torch.utils.data import DataLoader
from torchvision import transforms
from lstn.dataloaders.eval_demo_data import VSDTest
from lstn.dataloaders.eval_datasets import ViSha_Test
import data... | 9,800 | 45.894737 | 148 | py |
Detect-AnyShadow | Detect-AnyShadow-main/lstn/networks/managers/eval_demo.py | import os
import time
import datetime as datetime
import torch
import torch.nn.functional as F
from torch.utils.data import DataLoader
from torchvision import transforms
from lstn.dataloaders.eval_demo_data import VSDTest
import dataloaders.video_transforms as tr
from utils.checkpoint import load_network
from networ... | 8,370 | 43.057895 | 144 | py |
Detect-AnyShadow | Detect-AnyShadow-main/lstn/networks/managers/trainer.py | import os
import time
import json
import datetime as datetime
import numpy as np
import torch
import torch.nn as nn
import torch.optim as optim
import torch.distributed as dist
from torch.utils.data import DataLoader
from torchvision import transforms
from dataloaders.train_datasets import ViSha
import dataloaders.v... | 16,740 | 46.29096 | 161 | py |
Detect-AnyShadow | Detect-AnyShadow-main/lstn/networks/models/lstn.py | import torch.nn as nn
from networks.encoders import build_encoder
from networks.layers.transformer import LongShortTermTransformer
from networks.decoders import build_decoder
from networks.layers.position import PositionEmbeddingSine
class LSTN(nn.Module):
def __init__(self, cfg, encoder='mobilenetv2', decoder='... | 4,805 | 51.23913 | 143 | py |
Detect-AnyShadow | Detect-AnyShadow-main/lstn/networks/decoders/fpn.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from networks.layers.basic import ConvGN
class FPNSegmentationHead(nn.Module):
def __init__(self,
in_dim,
out_dim,
decode_intermediate_input=True,
hidden_dim=256,
... | 1,912 | 31.982759 | 111 | py |
Detect-AnyShadow | Detect-AnyShadow-main/lstn/networks/layers/position.py | import math
import torch
import torch.nn as nn
import torch.nn.functional as F
from utils.math import truncated_normal_
class Downsample2D(nn.Module):
def __init__(self, mode='nearest', scale=4):
super().__init__()
self.mode = mode
self.scale = scale
def forward(self, x):
n,... | 2,587 | 32.179487 | 103 | py |
Detect-AnyShadow | Detect-AnyShadow-main/lstn/networks/layers/loss.py | import torch
import torch.nn as nn
import torch.nn.functional as F
try:
from itertools import ifilterfalse
except ImportError: # py3k
from itertools import filterfalse as ifilterfalse
def dice_loss(probas, labels, smooth=1):
C = probas.size(1)
losses = []
for c in list(range(C)):
fg = (... | 6,344 | 35.465517 | 135 | py |
Detect-AnyShadow | Detect-AnyShadow-main/lstn/networks/layers/transformer.py | import torch
import torch.nn.functional as F
from torch import nn
from networks.layers.basic import DropPath, GroupNorm1D, GNActDWConv2d, seq_to_2d, ScaleOffset, mask_out
from networks.layers.attention import silu, MultiheadAttention, MultiheadLocalAttentionV2, MultiheadLocalAttentionV3, GatedPropagation, LocalGatedPr... | 22,063 | 36.460102 | 157 | py |
Detect-AnyShadow | Detect-AnyShadow-main/lstn/networks/layers/normalization.py | import torch
import torch.nn as nn
import torch.nn.functional as F
class FrozenBatchNorm2d(nn.Module):
"""
BatchNorm2d where the batch statistics and the affine parameters
are fixed
"""
def __init__(self, n, epsilon=1e-5):
super(FrozenBatchNorm2d, self).__init__()
self.register_buf... | 1,700 | 37.659091 | 154 | py |
Detect-AnyShadow | Detect-AnyShadow-main/lstn/networks/layers/attention.py | import math
import torch
import torch.nn as nn
import torch.nn.functional as F
from networks.layers.basic import DropOutLogit, ScaleOffset, DWConv2d
def multiply_by_ychunks(x, y, chunks=1):
if chunks <= 1:
return x @ y
else:
return torch.cat([x @ _y for _y in y.chunk(chunks, dim=-1)], dim=-1)
... | 32,118 | 36.088915 | 143 | py |
Detect-AnyShadow | Detect-AnyShadow-main/lstn/networks/layers/basic.py | import torch
import torch.nn.functional as F
from torch import nn
class GroupNorm1D(nn.Module):
def __init__(self, indim, groups=8):
super().__init__()
self.gn = nn.GroupNorm(groups, indim)
def forward(self, x):
return self.gn(x.permute(1, 2, 0)).permute(2, 0, 1)
class GNActDWConv2d... | 4,495 | 31.114286 | 110 | py |
Detect-AnyShadow | Detect-AnyShadow-main/lstn/networks/encoders/resnet.py | import math
import torch.nn as nn
from utils.learning import freeze_params
class Bottleneck(nn.Module):
expansion = 4
def __init__(self,
inplanes,
planes,
stride=1,
dilation=1,
downsample=None,
BatchNorm=Non... | 6,688 | 31.004785 | 126 | py |
Detect-AnyShadow | Detect-AnyShadow-main/lstn/networks/encoders/mobilenetv2.py | from torch import nn
from torch import Tensor
from typing import Callable, Optional, List
from utils.learning import freeze_params
__all__ = ['MobileNetV2']
def _make_divisible(v: float,
divisor: int,
min_value: Optional[int] = None) -> int:
"""
This function is taken ... | 8,086 | 33.559829 | 142 | py |
Detect-AnyShadow | Detect-AnyShadow-main/lstn/networks/encoders/mobilenetv3.py | """
Creates a MobileNetV3 Model as defined in:
Andrew Howard, Mark Sandler, Grace Chu, Liang-Chieh Chen, Bo Chen, Mingxing Tan, Weijun Wang, Yukun Zhu, Ruoming Pang, Vijay Vasudevan, Quoc V. Le, Hartwig Adam. (2019).
Searching for MobileNetV3
arXiv preprint arXiv:1905.02244.
"""
import torch.nn as nn
import math
from ... | 7,895 | 31.9 | 169 | py |
Detect-AnyShadow | Detect-AnyShadow-main/lstn/networks/encoders/__init__.py | from networks.encoders.mobilenetv2 import MobileNetV2
from networks.encoders.mobilenetv3 import MobileNetV3Large
from networks.encoders.resnet import ResNet101, ResNet50
from networks.encoders.resnest import resnest
from networks.encoders.swin import build_swin_model
from networks.layers.normalization import FrozenBatc... | 1,381 | 37.388889 | 67 | py |
Detect-AnyShadow | Detect-AnyShadow-main/lstn/networks/encoders/swin/swin_transformer.py | # --------------------------------------------------------
# Swin Transformer
# Copyright (c) 2021 Microsoft
# Licensed under The MIT License [see LICENSE for details]
# Written by Ze Liu
# --------------------------------------------------------
from itertools import repeat
import collections.abc
import numpy as np
i... | 27,341 | 37.133891 | 104 | py |
Detect-AnyShadow | Detect-AnyShadow-main/lstn/networks/encoders/resnest/resnet.py | import math
import torch.nn as nn
from .splat import SplAtConv2d, DropBlock2D
from utils.learning import freeze_params
__all__ = ['ResNet', 'Bottleneck']
_url_format = 'https://s3.us-west-1.wasabisys.com/resnest/torch/{}-{}.pth'
_model_sha256 = {name: checksum for checksum, name in []}
def short_hash(name):
i... | 16,470 | 36.013483 | 162 | py |
Detect-AnyShadow | Detect-AnyShadow-main/lstn/networks/encoders/resnest/resnest.py | import torch
from .resnet import ResNet, Bottleneck
__all__ = ['resnest50', 'resnest101', 'resnest200', 'resnest269']
_url_format = 'https://s3.us-west-1.wasabisys.com/resnest/torch/{}-{}.pth'
_model_sha256 = {
name: checksum
for checksum, name in [
('528c19ca', 'resnest50'),
('22405ba7', 're... | 3,343 | 29.678899 | 79 | py |
Detect-AnyShadow | Detect-AnyShadow-main/lstn/networks/encoders/resnest/splat.py | import torch
from torch import nn
import torch.nn.functional as F
from torch.nn import Conv2d, Module, ReLU
from torch.nn.modules.utils import _pair
__all__ = ['SplAtConv2d', 'DropBlock2D']
class DropBlock2D(object):
def __init__(self, *args, **kwargs):
raise NotImplementedError
class SplAtConv2d(Modul... | 4,467 | 32.593985 | 79 | py |
Detect-AnyShadow | Detect-AnyShadow-main/lstn/networks/engines/lstn_engine.py | import torch
import torch.nn as nn
import torch.nn.functional as F
import numpy as np
from utils.math import generate_permute_matrix
from utils.image import one_hot_mask
from networks.layers.basic import seq_to_2d
class LSTNEngine(nn.Module):
def __init__(self, lstn_model, gpu_id=0, long_term_mem_gap=9999, sho... | 20,474 | 40.615854 | 178 | py |
Detect-AnyShadow | Detect-AnyShadow-main/lstn/eval/losses.py | import torch
from torch import nn
from torch.nn import functional as F
import numpy as np
from torch.autograd import Variable
try:
from itertools import ifilterfalse
except ImportError: # py3k
from itertools import filterfalse as ifilterfalse
def bce2d_new(input, target, reduction='mean'):
assert(inp... | 5,113 | 30.567901 | 105 | py |
Detect-AnyShadow | Detect-AnyShadow-main/lstn/eval/logger.py | # Copyright (c) OpenMMLab. All rights reserved.
import logging
import torch.distributed as dist
logger_initialized: dict = {}
def get_logger(name, log_file=None, log_level=logging.INFO, file_mode='w'):
"""Initialize and get a logger by name.
If the logger has not been initialized, this method will initializ... | 3,860 | 35.424528 | 79 | py |
Detect-AnyShadow | Detect-AnyShadow-main/lstn/eval/util.py | import os
import os.path as osp
from pathlib import Path
import torch
import numpy as np
from pathlib import Path
import torch.distributed as dist
# import yaml
import random
# import imageio as io
from collections import OrderedDict
''' initial seed '''
def init_seeds(seed=0):
random.seed(seed) # seed for mo... | 5,865 | 31.054645 | 104 | py |
Detect-AnyShadow | Detect-AnyShadow-main/lstn/eval/save_concat.py | # 从每个video中随机抽取
import sys
sys.path.append("../")
import os
import os.path as osp
import numpy as np
from PIL import Image
from util import *
import argparse
from torchvision import transforms
from torchvision import utils
res_path = r"../checkpoints/results"
save_path = r"../checkpoints/simple"
img_path = r'/data4/... | 3,430 | 53.460317 | 124 | py |
Detect-AnyShadow | Detect-AnyShadow-main/lstn/dataloaders/eval_demo_data.py | from __future__ import division
import os
import shutil
import json
import cv2
from PIL import Image
import numpy as np
from torch.utils.data import Dataset
class VSDTest(Dataset):
def __init__(self, image_list, mask_list, rgb=True, transform=None,):
self.image_list = image_list
self.label_list =... | 1,087 | 23.727273 | 77 | py |
Detect-AnyShadow | Detect-AnyShadow-main/lstn/dataloaders/video_transforms.py | import random
import cv2
import numpy as np
from PIL import Image
import torch
import torchvision.transforms as TF
import dataloaders.image_transforms as IT
cv2.setNumThreads(0)
class Resize(object):
"""Rescale the image in a sample to a given size.
Args:
output_size (tuple or int): Desired output ... | 22,692 | 32.519941 | 129 | py |
Detect-AnyShadow | Detect-AnyShadow-main/lstn/dataloaders/train_datasets.py | from __future__ import division
import os
import cv2
import numpy as np
from torch.utils.data import Dataset
cv2.setNumThreads(0)
class VSDTrain(Dataset):
def __init__(self,
image_root,
label_root,
imglistdic,
transform=None,
rg... | 8,244 | 34.538793 | 117 | py |
Detect-AnyShadow | Detect-AnyShadow-main/lstn/dataloaders/image_transforms.py | import math
import warnings
import random
import numbers
import numpy as np
from PIL import Image, ImageFilter
from collections.abc import Sequence
import torch
import torchvision.transforms.functional as TF
_pil_interpolation_to_str = {
Image.NEAREST: 'PIL.Image.NEAREST',
Image.BILINEAR: 'PIL.Image.BILINEAR'... | 19,828 | 36.34275 | 117 | py |
Detect-AnyShadow | Detect-AnyShadow-main/lstn/dataloaders/eval_datasets.py | from __future__ import division
import os
import shutil
import json
import cv2
from PIL import Image
import numpy as np
from torch.utils.data import Dataset
class VSDTest(Dataset):
def __init__(self, image_root, label_root, seq_name, images, labels, rgb=True, transform=None,):
self.image_root = image_roo... | 4,529 | 34.390625 | 100 | py |
Detect-AnyShadow | Detect-AnyShadow-main/lstn/utils/checkpoint.py | import torch
import os
import shutil
import numpy as np
def load_network_and_optimizer(net, opt, pretrained_dir, gpu, scaler=None):
pretrained = torch.load(pretrained_dir, map_location=torch.device("cuda:" + str(gpu)))
pretrained_dict = pretrained['state_dict']
model_dict = net.state_dict()
pretrained... | 6,014 | 37.806452 | 98 | py |
Detect-AnyShadow | Detect-AnyShadow-main/lstn/utils/image.py | import numpy as np
from PIL import Image
import torch
import threading
def label2colormap(label):
m = label.astype(np.uint8)
r, c = m.shape
cmap = np.zeros((r, c, 3), dtype=np.uint8)
cmap[:, :, 0] = (m & 1) << 7 | (m & 8) << 3 | (m & 64) >> 1
cmap[:, :, 1] = (m & 2) << 6 | (m & 16) << 2 | (m & 12... | 2,871 | 29.88172 | 85 | py |
Detect-AnyShadow | Detect-AnyShadow-main/lstn/utils/math.py | import torch
def generate_permute_matrix(dim, num, keep_first=True, gpu_id=0):
all_matrix = []
for idx in range(num):
random_matrix = torch.eye(dim, device=torch.device('cuda', gpu_id))
if keep_first:
fg = random_matrix[1:][torch.randperm(dim - 1)]
random_matrix = torch... | 829 | 32.2 | 75 | py |
Detect-AnyShadow | Detect-AnyShadow-main/lstn/utils/ema.py | from __future__ import division
from __future__ import unicode_literals
import torch
def get_param_buffer_for_ema(model, update_buffer=False, required_buffers=['running_mean', 'running_var']):
params = model.parameters()
all_param_buffer = [p for p in params if p.requires_grad]
if update_buffer:
... | 3,447 | 38.632184 | 122 | py |
Detect-AnyShadow | Detect-AnyShadow-main/lstn/utils/metric.py | import torch
def pytorch_iou(pred, target, obj_num, epsilon=1e-6):
'''
pred: [bs, h, w]
target: [bs, h, w]
obj_num: [bs]
'''
bs = pred.size(0)
all_iou = []
for idx in range(bs):
now_pred = pred[idx].unsqueeze(0)
now_target = target[idx].unsqueeze(0)
now_obj_num ... | 1,077 | 29.8 | 93 | py |
Detect-AnyShadow | Detect-AnyShadow-main/tool/mask_tool.py | # paint masks, contours, or points on images, with specified colors
import cv2
import torch
import numpy as np
from PIL import Image
import copy
import time
def colormap(rgb=True):
color_list = np.array(
[
0.000, 0.000, 0.000,
1.000, 1.000, 1.000,
1.000, 0.498, 0.313,
0.392, 0.581, 0.929,
0.000, 0.4... | 7,062 | 30.114537 | 129 | py |
Detect-AnyShadow | Detect-AnyShadow-main/tool/generate_video.py | import os
import torch
import torchvision
import numpy as np
import cv2
# generate video after vsd inference
def generate_video_from_frames(frames, output_path, fps=30):
"""
Generates a video from a list of frames.
Args:
frames (list of numpy arrays): The frames to include in the video.
... | 1,087 | 33 | 87 | py |
AutoToon | AutoToon-master/test.py | # Copyright 2020 Adobe. All rights reserved.
# This file is licensed to you 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 ... | 4,331 | 44.125 | 115 | py |
AutoToon | AutoToon-master/dataset.py | # Copyright 2020 Adobe. All rights reserved.
# This file is licensed to you 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 ... | 7,444 | 47.980263 | 248 | py |
AutoToon | AutoToon-master/train.py | # Copyright 2020 Adobe. All rights reserved.
# This file is licensed to you 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 ... | 10,460 | 52.646154 | 238 | py |
AutoToon | AutoToon-master/test_utils.py | # Copyright 2020 Adobe. All rights reserved.
# This file is licensed to you 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 ... | 7,593 | 43.151163 | 123 | py |
AutoToon | AutoToon-master/models/vggface2_senet.py | # Copyright 2020 Adobe. All rights reserved.
# This file is licensed to you 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 ... | 6,905 | 33.188119 | 107 | py |
AutoToon | AutoToon-master/models/AutoToon.py | # Copyright 2020 Adobe. All rights reserved.
# This file is licensed to you 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 ... | 8,347 | 48.988024 | 132 | py |
BigProject | BigProject-master/old_code/solver_pytorch.py | from __future__ import print_function, division
from builtins import range
from builtins import object
import os
import pickle as pickle
import numpy as np
import torch
import torch.utils.data
from torch.autograd import Variable
import torch.nn as nn
import torch.optim as optim
class Solver(object):
def __i... | 5,314 | 34.198675 | 82 | py |
BigProject | BigProject-master/finial_code/solver_pytorch.py | from __future__ import print_function, division
from builtins import range
from builtins import object
import os
import pickle as pickle
import numpy as np
import torch
import torch.utils.data
from torch.autograd import Variable
import torch.nn as nn
import torch.optim as optim
class Solver(object):
def __i... | 5,314 | 34.198675 | 82 | py |
AMP | AMP-main/src/pretrain_transgan.py | # coding=utf-8
# Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved.
#
# 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 re... | 5,573 | 32.578313 | 101 | py |
AMP | AMP-main/src/het_model.py | # Script to reproduce homogeneous setting results
import math
import time
from collections import defaultdict
import operator
import random
import os
import copy
from tqdm import tqdm
import numpy as np
import torch
from torch import optim as optim
import torch.nn as nn
import torch.nn.functional as F
from sa impo... | 4,173 | 30.383459 | 137 | py |
AMP | AMP-main/src/homogeneous.py | # Script to reproduce homogeneous setting results
import math
import time
from collections import defaultdict
import operator
import shutil
import random
import os
import copy
from tqdm import tqdm
import numpy as np
import torch
from torch import optim as optim
import torch.nn as nn
import torch.nn.functional as F... | 4,209 | 30.893939 | 137 | py |
AMP | AMP-main/src/het_cluster.py | # Script to reproduce homogeneous setting results
import math
import time
from collections import defaultdict
import operator
import random
import os
import copy
from tqdm import tqdm
import numpy as np
import torch
from torch import optim as optim
import torch.nn as nn
import torch.nn.functional as F
from sa impo... | 4,308 | 31.643939 | 137 | py |
AMP | AMP-main/src/pipe.py | import copy
import time
import torch
import numpy as np
def pipe_ast(L, cost_e, cost_c, k, B):
time_dp_s = time.time()
possible = [0]
for i in range(1, L+1):
ptr = 0
while ptr + i <= L:
possible.append(sum(cost_e[ptr:ptr+i]))
ptr += 1
possible = sorted... | 4,564 | 30.054422 | 97 | py |
AMP | AMP-main/src/amp_utils.py | import torch
import os
import subprocess
import json
import torch
import spur
# returns the rank to axis. If pp_deg=dp_deg=mp_deg=2, rank 3 gives (0,1,1).
# This is deepspeed method
def rank2axis(rank, mp_deg, dp_deg, pp_deg):
pp = rank // (mp_deg * dp_deg)
remainder = rank % (mp_deg * dp_deg)
dp = remain... | 6,218 | 34.537143 | 155 | py |
AMP | AMP-main/src/cost_homo.py | from collections import defaultdict
import time
import json
import copy
import subprocess
import sys
import os
import torch
import torch.nn as nn
import numpy as np
from amp_utils import rank2axis, axis2rank, get_host
from pipe import pipe_ds, pipe_ast, pipe_cost, pipe_uniform, pipe_gpt2
home_dir = os.environ['HOME... | 14,692 | 39.144809 | 135 | py |
AMP | AMP-main/src/pretrain_gpt2.py | # coding=utf-8
# Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved.
#
# 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 re... | 5,197 | 30.889571 | 102 | py |
AMP | AMP-main/src/cost_het_cluster.py | from collections import defaultdict
import time
import json
import copy
import subprocess
import sys
import os
import torch
import torch.nn as nn
import numpy as np
from amp_utils import rank2axis, axis2rank, get_host
from pipe import pipe_ds, pipe_ast, pipe_cost, pipe_uniform, pipe_gpt2
home_dir = os.environ['HOME... | 13,302 | 38.829341 | 131 | py |
AMP | AMP-main/src/cost_het_model.py | from collections import defaultdict
import time
import json
import copy
import subprocess
import sys
import os
import torch
import torch.nn as nn
import numpy as np
from amp_utils import rank2axis, axis2rank, get_host
from pipe import pipe_ds, pipe_ast, pipe_cost, pipe_uniform, pipe_gpt2
home_dir = os.environ['HOME... | 15,712 | 39.919271 | 131 | py |
AMP | AMP-main/src/sa.py | import copy
import time
import os
from collections import defaultdict
import torch
import numpy as np
from amp_utils import factor
class SymDict(dict):
def __getitem__(self, key):
return dict.__getitem__(self, key if key[0] < key[1] else (key[1],key[0]))
def __setitem__(self, key, value):
di... | 13,429 | 30.378505 | 121 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.