id int64 0 190k | prompt stringlengths 21 13.4M | docstring stringlengths 1 12k ⌀ |
|---|---|---|
29,748 | import random
import numpy as np
from PIL import Image, ImageEnhance, ImageOps
LEVEL_DENOM = 10
def randomly_negate(value):
"""negate the value with 0.5 prob"""
return -value if random.random() > 0.5 else value
def enhance_increasing_level_to_arg(level):
# range [0.1, 1.9]
level = (level / LEVEL_DENOM)... | null |
29,771 | import sys
import os
import time
import argparse
import random
import math
import numpy as np
import paddle
from datasets import get_dataloader
from datasets import get_dataset
from config import get_config
from config import update_config
from utils import AverageMeter
from utils import get_logger
from utils import wr... | return argumeents, this will overwrite the config by (1) yaml file (2) argument values |
29,772 | import sys
import os
import time
import argparse
import random
import math
import numpy as np
import paddle
from datasets import get_dataloader
from datasets import get_dataset
from config import get_config
from config import update_config
from utils import AverageMeter
from utils import get_logger
from utils import wr... | main method for each process |
29,774 | import os
import math
from paddle.io import Dataset
from paddle.io import DataLoader
from paddle.io import DistributedBatchSampler
from paddle.vision import transforms
from paddle.vision import image_load
from augment import auto_augment_policy_original
from augment import AutoAugment
from augment import rand_augment_p... | Get dataset from config and mode (train/val) Returns the related dataset object according to configs and mode(train/val) Args: config: configs contains dataset related settings. see config.py for details is_train: bool, set True to use training set, otherwise val set. Default: True Returns: dataset: dataset object |
29,777 | import os
from yacs.config import CfgNode as CN
import yaml
_C = CN()
_C.BASE = ['']
_C.DATA = CN()
_C.DATA.BATCH_SIZE = 256
_C.DATA.BATCH_SIZE_EVAL = None
_C.DATA.DATA_PATH = '/dataset/imagenet/'
_C.DATA.DATASET = 'imagenet2012'
_C.DATA.IMAGE_SIZE = 224
_C.DATA.IMAGE_CHANNELS = 3
_C.DATA.CROP_PCT = 0.875
_C.DAT... | Return a clone of config and optionally overwrite it from yaml file |
29,778 | import os
import numpy as np
import paddle
import torch
import timm
from gmlp import build_gmlp as build_model
from config import get_config
def print_model_named_params(model):
print('----------------------------------')
for name, param in model.named_parameters():
print(name, param.shape)
print('... | null |
29,779 | import os
import numpy as np
import paddle
import torch
import timm
from gmlp import build_gmlp as build_model
from config import get_config
def print_model_named_buffers(model):
print('----------------------------------')
for name, param in model.named_buffers():
print(name, param.shape)
print('--... | null |
29,780 | import os
import numpy as np
import paddle
import torch
import timm
from gmlp import build_gmlp as build_model
from config import get_config
def torch_to_paddle_mapping(model_name, config):
mapping = [
('stem.proj', 'patch_embed.patch_embed'),
]
for stage_idx in range(config.MODEL.MIXER.DEPTH):
... | null |
29,818 | import math
import copy
from functools import partial
import paddle
import paddle.nn as nn
from droppath import DropPath
class GatedMlp(nn.Layer):
def __init__(self,
num_classes=1000,
image_size=224,
in_channels=3,
patch_size=16,
n... | null |
29,823 | import sys
import os
import time
import argparse
import random
import math
import numpy as np
import paddle
from datasets import get_dataloader
from datasets import get_dataset
from config import get_config
from config import update_config
from utils import AverageMeter
from utils import get_logger
from utils import wr... | return argumeents, this will overwrite the config by (1) yaml file (2) argument values |
29,824 | import sys
import os
import time
import argparse
import random
import math
import numpy as np
import paddle
from datasets import get_dataloader
from datasets import get_dataset
from config import get_config
from config import update_config
from utils import AverageMeter
from utils import get_logger
from utils import wr... | main method for each process |
29,829 | import os
from yacs.config import CfgNode as CN
import yaml
_C = CN()
_C.BASE = ['']
_C.DATA = CN()
_C.DATA.BATCH_SIZE = 256
_C.DATA.BATCH_SIZE_EVAL = None
_C.DATA.DATA_PATH = '/dataset/imagenet/'
_C.DATA.DATASET = 'imagenet2012'
_C.DATA.IMAGE_SIZE = 224
_C.DATA.IMAGE_CHANNELS = 3
_C.DATA.CROP_PCT = 0.875
_C.DAT... | Return a clone of config and optionally overwrite it from yaml file |
29,830 | import os
import numpy as np
import paddle
import torch
import timm
from resmlp import build_resmlp as build_model
from config import get_config
def print_model_named_params(model):
print('----------------------------------')
for name, param in model.named_parameters():
print(name, param.shape)
pri... | null |
29,831 | import os
import numpy as np
import paddle
import torch
import timm
from resmlp import build_resmlp as build_model
from config import get_config
def print_model_named_buffers(model):
print('----------------------------------')
for name, param in model.named_buffers():
print(name, param.shape)
print... | null |
29,832 | import os
import numpy as np
import paddle
import torch
import timm
from resmlp import build_resmlp as build_model
from config import get_config
def torch_to_paddle_mapping(model_name, config):
def convert(torch_model, paddle_model, model_name, config):
def _set_value(th_name, pd_name, transpose=True):
th_... | null |
29,870 | import math
import copy
import paddle
import paddle.nn as nn
from droppath import DropPath
class ResMlp(nn.Layer):
def __init__(self,
num_classes=1000,
image_size=224,
in_channels=3,
patch_size=16,
num_mixer_layers=24,
... | build resmlp model form config |
29,875 | import paddle
import paddle.nn as nn
import paddle.nn.functional as F
from droppath import DropPath
class GroupNorm(nn.GroupNorm):
"""
Group Normalization with 1 group.
Input: tensor in shape [B, C, H, W]
"""
def __init__(self, num_channels, **kwargs):
super().__init__(1, num_channels, **kwa... | generate PoolFormer blocks for a stage return: PoolFormer blocks |
29,876 | import paddle
import paddle.nn as nn
import paddle.nn.functional as F
from droppath import DropPath
class PoolFormer(nn.Layer):
"""
PoolFormer, the main class of our model
--layers: [x,x,x,x], number of blocks for the 4 stages
--embed_dims, --mlp_ratios, --pool_size: the embedding dims, mlp ratios and
... | PoolFormer-S12 model, Params: 12M --layers: [x,x,x,x], numbers of layers for the four stages --embed_dims, --mlp_ratios: embedding dims and mlp ratios for the four stages --downsamples: flags to apply downsampling or not in four blocks |
29,877 | import paddle
import paddle.nn as nn
import paddle.nn.functional as F
from droppath import DropPath
class PoolFormer(nn.Layer):
"""
PoolFormer, the main class of our model
--layers: [x,x,x,x], number of blocks for the 4 stages
--embed_dims, --mlp_ratios, --pool_size: the embedding dims, mlp ratios and
... | build poolformer model from config |
29,878 | import sys
import os
import time
import argparse
import random
import math
import numpy as np
import paddle
from datasets import get_dataloader
from datasets import get_dataset
from config import get_config
from config import update_config
from utils import AverageMeter
from utils import get_logger
from utils import wr... | return argumeents, this will overwrite the config by (1) yaml file (2) argument values |
29,879 | import sys
import os
import time
import argparse
import random
import math
import numpy as np
import paddle
from datasets import get_dataloader
from datasets import get_dataset
from config import get_config
from config import update_config
from utils import AverageMeter
from utils import get_logger
from utils import wr... | main method for each process |
29,884 | import os
from yacs.config import CfgNode as CN
import yaml
_C = CN()
_C.BASE = ['']
_C.DATA = CN()
_C.DATA.BATCH_SIZE = 256
_C.DATA.BATCH_SIZE_EVAL = None
_C.DATA.DATA_PATH = '/dataset/imagenet/'
_C.DATA.DATASET = 'imagenet2012'
_C.DATA.IMAGE_SIZE = 224
_C.DATA.IMAGE_CHANNELS = 3
_C.DATA.CROP_PCT = 0.875
_C.DAT... | Return a clone of config and optionally overwrite it from yaml file |
29,885 | import os
import numpy as np
import paddle
import torch
import timm
from poolformer import build_poolformer as build_model
from config import get_config
def print_model_named_params(model):
print('----------------------------------')
for name, param in model.named_parameters():
print(name, param.shape)... | null |
29,886 | import os
import numpy as np
import paddle
import torch
import timm
from poolformer import build_poolformer as build_model
from config import get_config
def print_model_named_buffers(model):
print('----------------------------------')
for name, param in model.named_buffers():
print(name, param.shape)
... | null |
29,887 | import os
import numpy as np
import paddle
import torch
import timm
from poolformer import build_poolformer as build_model
from config import get_config
def torch_to_paddle_mapping(model_name, config):
mapping = [
('patch_embed.proj', 'patch_embed.proj'),
]
layer_ids = [x for x in range(len(config.M... | null |
29,929 | import sys
import os
import time
import argparse
import random
import math
import numpy as np
import paddle
from datasets import get_dataloader
from datasets import get_dataset
from config import get_config
from config import update_config
from utils import AverageMeter
from utils import get_logger
from utils import wr... | return argumeents, this will overwrite the config by (1) yaml file (2) argument values |
29,930 | import sys
import os
import time
import argparse
import random
import math
import numpy as np
import paddle
from datasets import get_dataloader
from datasets import get_dataset
from config import get_config
from config import update_config
from utils import AverageMeter
from utils import get_logger
from utils import wr... | main method for each process |
29,935 | import os
from yacs.config import CfgNode as CN
import yaml
_C = CN()
_C.BASE = ['']
_C.DATA = CN()
_C.DATA.BATCH_SIZE = 256
_C.DATA.BATCH_SIZE_EVAL = None
_C.DATA.DATA_PATH = '/dataset/imagenet/'
_C.DATA.DATASET = 'imagenet2012'
_C.DATA.IMAGE_SIZE = 224
_C.DATA.IMAGE_CHANNELS = 3
_C.DATA.CROP_PCT = 0.875
_C.DAT... | Return a clone of config and optionally overwrite it from yaml file |
29,936 | from functools import partial
import paddle
import paddle.nn.functional as F
from paddle import nn
from droppath import DropPath
class LinearVisionTransformer(nn.Layer):
def __init__(
self,
*,
patch_size=16,
in_chans=3,
num_classes=1000,
embed... | null |
29,937 | import os
import numpy as np
import paddle
import torch
import timm
from ffonly import build_ffonly as build_model
from config import get_config
from ffonly_torch import linear_tiny
from ffonly_torch import linear_base
def print_model_named_params(model):
print('----------------------------------')
for name, p... | null |
29,938 | import os
import numpy as np
import paddle
import torch
import timm
from ffonly import build_ffonly as build_model
from config import get_config
from ffonly_torch import linear_tiny
from ffonly_torch import linear_base
def print_model_named_buffers(model):
print('----------------------------------')
for name, ... | null |
29,939 | import os
import numpy as np
import paddle
import torch
import timm
from ffonly import build_ffonly as build_model
from config import get_config
from ffonly_torch import linear_tiny
from ffonly_torch import linear_base
def torch_to_paddle_mapping(model_name, config):
mapping = [
('cls_token', 'cls_token'),
... | null |
29,981 | import paddle
import paddle.nn as nn
def ConvMixer(dim,
depth,
kernel_size=9,
patch_size=7,
num_classes=1000,
activation='GELU'):
if activation == 'ReLU':
convmixer_act = nn.ReLU()
else:
convmixer_act = nn.GELU()
return nn... | null |
29,982 | import sys
import os
import time
import argparse
import random
import math
import numpy as np
import paddle
from datasets import get_dataloader
from datasets import get_dataset
from config import get_config
from config import update_config
from utils import AverageMeter
from utils import get_logger
from utils import wr... | return argumeents, this will overwrite the config by (1) yaml file (2) argument values |
29,983 | import sys
import os
import time
import argparse
import random
import math
import numpy as np
import paddle
from datasets import get_dataloader
from datasets import get_dataset
from config import get_config
from config import update_config
from utils import AverageMeter
from utils import get_logger
from utils import wr... | main method for each process |
29,988 | import os
from yacs.config import CfgNode as CN
import yaml
_C = CN()
_C.BASE = ['']
_C.DATA = CN()
_C.DATA.BATCH_SIZE = 256
_C.DATA.BATCH_SIZE_EVAL = None
_C.DATA.DATA_PATH = '/dataset/imagenet/'
_C.DATA.DATASET = 'imagenet2012'
_C.DATA.IMAGE_SIZE = 224
_C.DATA.IMAGE_CHANNELS = 3
_C.DATA.CROP_PCT = 0.875
_C.DAT... | Return a clone of config and optionally overwrite it from yaml file |
29,989 | import os
import numpy as np
import paddle
import torch
import timm
from convmixer import build_convmixer as build_model
from config import get_config
from convmixer_torch import ConvMixer
def print_model_named_params(model):
print('----------------------------------')
for name, param in model.named_parameters... | null |
29,990 | import os
import numpy as np
import paddle
import torch
import timm
from convmixer import build_convmixer as build_model
from config import get_config
from convmixer_torch import ConvMixer
def print_model_named_buffers(model):
print('----------------------------------')
for name, param in model.named_buffers()... | null |
29,991 | import os
import numpy as np
import paddle
import torch
import timm
from convmixer import build_convmixer as build_model
from config import get_config
from convmixer_torch import ConvMixer
def torch_to_paddle_mapping(model_name, config):
mapping = [
('0', '0'),
('2', '2'),
]
for stage_idx in... | null |
30,029 | import collections.abc
import math
import warnings
from itertools import repeat
import paddle
import paddle.nn as nn
from scipy import special
def _ntuple(n):
def parse(x):
if isinstance(x, collections.abc.Iterable):
return x
return tuple(repeat(x, n))
return parse | null |
30,030 | import collections.abc
import math
import warnings
from itertools import repeat
import paddle
import paddle.nn as nn
from scipy import special
def _no_grad_trunc_normal_(tensor, mean, std, a, b):
# Cut & paste from PyTorch official master until it's in a few official releases - RW
# Method based on https://peop... | r"""Fills the input Tensor with values drawn from a truncated normal distribution. The values are effectively drawn from the normal distribution :math:`\mathcal{N}(\text{mean}, \text{std}^2)` with values outside :math:`[a, b]` redrawn until they are within the bounds. The method used for generating the random values wo... |
30,031 | import collections.abc
import math
import warnings
from itertools import repeat
import paddle
import paddle.nn as nn
from scipy import special
IMAGENET_INCEPTION_MEAN = (0.5, 0.5, 0.5)
IMAGENET_INCEPTION_STD = (0.5, 0.5, 0.5)
def _cfg(url='', **kwargs):
return {
'url': url,
'num_classes': 1000, 'in... | null |
30,036 | import math
import numpy as np
import paddle
import paddle.nn as nn
from crossvit_utils import DropPath, Identity, to_2tuple
The provided code snippet includes necessary dependencies for implementing the `get_sinusoid_encoding` function. Write a Python function `def get_sinusoid_encoding(n_position, d_hid)` to solve t... | Sinusoid position encoding table |
30,037 | import sys
import os
import time
import argparse
import random
import math
import numpy as np
import paddle
from datasets import get_dataloader
from datasets import get_dataset
from config import get_config
from config import update_config
from utils import AverageMeter
from utils import get_logger
from utils import wr... | return argumeents, this will overwrite the config by (1) yaml file (2) argument values |
30,038 | import sys
import os
import time
import argparse
import random
import math
import numpy as np
import paddle
from datasets import get_dataloader
from datasets import get_dataset
from config import get_config
from config import update_config
from utils import AverageMeter
from utils import get_logger
from utils import wr... | main method for each process |
30,043 | import os
from yacs.config import CfgNode as CN
import yaml
_C = CN()
_C.BASE = ['']
_C.DATA = CN()
_C.DATA.BATCH_SIZE = 256
_C.DATA.BATCH_SIZE_EVAL = None
_C.DATA.DATA_PATH = '/dataset/imagenet/'
_C.DATA.DATASET = 'imagenet2012'
_C.DATA.IMAGE_SIZE = 224
_C.DATA.IMAGE_CHANNELS = 3
_C.DATA.CROP_PCT = 0.875
_C.DAT... | Return a clone of config and optionally overwrite it from yaml file |
30,044 | import paddle
import paddle.nn as nn
import paddle.nn.functional as F
from functools import partial
from t2t import T2T, get_sinusoid_encoding
from crossvit_utils import *
def _compute_num_patches(img_size, patches):
return [i // p * i // p for i, p in zip(img_size, patches)] | null |
30,045 | import paddle
import paddle.nn as nn
import paddle.nn.functional as F
from functools import partial
from t2t import T2T, get_sinusoid_encoding
from crossvit_utils import *
class VisionTransformer(nn.Layer):
""" Vision Transformer with support for patch or hybrid CNN input stage
"""
def __init__(self,
... | build corssvit model using config |
30,046 | import os
import numpy as np
import paddle
import torch
import timm
from crossvit import build_crossvit as build_model
from config import get_config
from CrossViT_torch.models.crossvit import *
def print_model_named_params(model):
print('----------------------------------')
for name, param in model.named_param... | null |
30,047 | import os
import numpy as np
import paddle
import torch
import timm
from crossvit import build_crossvit as build_model
from config import get_config
from CrossViT_torch.models.crossvit import *
def print_model_named_buffers(model):
print('----------------------------------')
for name, param in model.named_buff... | null |
30,048 | import os
import numpy as np
import paddle
import torch
import timm
from crossvit import build_crossvit as build_model
from config import get_config
from CrossViT_torch.models.crossvit import *
def torch_to_paddle_mapping(model_name, config):
def convert(torch_model, paddle_model, model_name, config):
def _set_val... | null |
30,086 | import copy
import random
import numpy as np
import paddle
import paddle.nn as nn
import paddle.nn.functional as F
from droppath import DropPath
from config import get_config
The provided code snippet includes necessary dependencies for implementing the `get_position_encoding` function. Write a Python function `def ge... | sinusoid position encoding table |
30,087 | import copy
import random
import numpy as np
import paddle
import paddle.nn as nn
import paddle.nn.functional as F
from droppath import DropPath
from config import get_config
class MAEPretrainTransformer(nn.Layer):
"""ViT transformer
ViT Transformer, classifier is a single Linear layer for finetune,
For tra... | null |
30,088 | import copy
import random
import numpy as np
import paddle
import paddle.nn as nn
import paddle.nn.functional as F
from droppath import DropPath
from config import get_config
class MAEFinetuneTransformer(nn.Layer):
"""ViT transformer
ViT Transformer, classifier is a single Linear layer for finetune,
For tra... | null |
30,089 | import math
from paddle.optimizer.lr import LRScheduler
The provided code snippet includes necessary dependencies for implementing the `get_exclude_from_weight_decay_fn` function. Write a Python function `def get_exclude_from_weight_decay_fn(exclude_list=[])` to solve the following problem:
Set params with no weight d... | Set params with no weight decay during the training For certain params, e.g., positional encoding in ViT, weight decay may not needed during the learning, this method is used to find these params. Args: exclude_list: a list of params names which need to exclude from weight decay. Returns: exclude_from_weight_decay_fn: ... |
30,090 | import sys
import os
import time
import logging
import argparse
import random
import numpy as np
import paddle
import paddle.nn as nn
import paddle.nn.functional as F
from datasets import get_dataloader
from datasets import get_dataset
from transformer import build_mae_finetune as build_model
from utils import AverageM... | return argumeents, this will overwrite the config after loading yaml file |
30,091 | import sys
import os
import time
import logging
import argparse
import random
import numpy as np
import paddle
import paddle.nn as nn
import paddle.nn.functional as F
from datasets import get_dataloader
from datasets import get_dataset
from transformer import build_mae_finetune as build_model
from utils import AverageM... | set logging file and format Args: filename: str, full path of the logger file to write logger_name: str, the logger name, e.g., 'master_logger', 'local_logger' Return: logger: python logger |
30,092 | import sys
import os
import time
import logging
import argparse
import random
import numpy as np
import paddle
import paddle.nn as nn
import paddle.nn.functional as F
from datasets import get_dataloader
from datasets import get_dataset
from transformer import build_mae_finetune as build_model
from utils import AverageM... | Training for one epoch Args: dataloader: paddle.io.DataLoader, dataloader instance model: nn.Layer, a ViT model criterion: nn.criterion epoch: int, current epoch total_epochs: int, total num of epochs total_batch: int, total num of batches for one epoch debug_steps: int, num of iters to log info, default: 100 accum_ite... |
30,093 | import sys
import os
import time
import logging
import argparse
import random
import numpy as np
import paddle
import paddle.nn as nn
import paddle.nn.functional as F
from datasets import get_dataloader
from datasets import get_dataset
from transformer import build_mae_finetune as build_model
from utils import AverageM... | Validation for whole dataset Args: dataloader: paddle.io.DataLoader, dataloader instance model: nn.Layer, a ViT model criterion: nn.criterion total_batch: int, total num of batches for one epoch debug_steps: int, num of iters to log info, default: 100 logger: logger for logging, default: None Returns: val_loss_meter.av... |
30,094 | import os
import math
from PIL import Image
from paddle.io import Dataset
from paddle.io import DataLoader
from paddle.io import DistributedBatchSampler
from paddle.vision import transforms
from paddle.vision import datasets
from paddle.vision import image_load
from augment import auto_augment_policy_original
from augm... | Get dataset from config and mode (train/val) Returns the related dataset object according to configs and mode(train/val) Args: config: configs contains dataset related settings. see config.py for details Returns: dataset: dataset object |
30,095 | import os
import math
from PIL import Image
from paddle.io import Dataset
from paddle.io import DataLoader
from paddle.io import DistributedBatchSampler
from paddle.vision import transforms
from paddle.vision import datasets
from paddle.vision import image_load
from augment import auto_augment_policy_original
from augm... | Get dataloader with config, dataset, mode as input, allows multiGPU settings. Multi-GPU loader is implements as distributedBatchSampler. Args: config: see config.py for details dataset: paddle.io.dataset object mode: train/val multi_process: if True, use DistributedBatchSampler to support multi-processing Returns: data... |
30,096 | import os
from yacs.config import CfgNode as CN
import yaml
def _update_config_from_file(config, cfg_file):
config.defrost()
with open(cfg_file, 'r') as infile:
yaml_cfg = yaml.load(infile, Loader=yaml.FullLoader)
for cfg in yaml_cfg.setdefault('BASE', ['']):
if cfg:
_update_conf... | Update config by ArgumentParser Args: args: ArgumentParser contains options Return: config: updated config |
30,097 | import os
from yacs.config import CfgNode as CN
import yaml
_C = CN()
_C.BASE = ['']
_C.DATA = CN()
_C.DATA.BATCH_SIZE = 256
_C.DATA.BATCH_SIZE_EVAL = 8
_C.DATA.DATA_PATH = '/dataset/imagenet/'
_C.DATA.DATASET = 'imagenet2012'
_C.DATA.IMAGE_SIZE = 224
_C.DATA.CROP_PCT = 0.875
_C.DATA.NUM_WORKERS = 4
_C.DATA.IMAGE... | Return a clone of config or load from yaml file |
30,098 | import sys
import os
import time
import logging
import argparse
import random
import numpy as np
import paddle
import paddle.nn as nn
import paddle.nn.functional as F
import paddle.distributed as dist
from datasets import get_dataloader
from datasets import get_dataset
from transformer import build_mae_finetune as buil... | return argumeents, this will overwrite the config after loading yaml file |
30,099 | import sys
import os
import time
import logging
import argparse
import random
import numpy as np
import paddle
import paddle.nn as nn
import paddle.nn.functional as F
import paddle.distributed as dist
from datasets import get_dataloader
from datasets import get_dataset
from transformer import build_mae_finetune as buil... | null |
30,100 | import os
import glob
import paddle
from config import get_config
from transformer import build_mae_pretrain as build_model
def count_gelu(layer, inputs, output):
activation_flops = 8
x = inputs[0]
num = x.numel()
layer.total_ops += num * activation_flops | null |
30,101 | import os
import glob
import paddle
from config import get_config
from transformer import build_mae_pretrain as build_model
def count_softmax(layer, inputs, output):
softmax_flops = 5 # max/substract, exp, sum, divide
x = inputs[0]
num = x.numel()
layer.total_ops += num * softmax_flops | null |
30,102 | import os
import glob
import paddle
from config import get_config
from transformer import build_mae_pretrain as build_model
def count_layernorm(layer, inputs, output):
layer_norm_flops = 5 # get mean (sum), get variance (square and sum), scale(multiply)
x = inputs[0]
num = x.numel()
layer.total_ops += ... | null |
30,105 | import sys
import os
import time
import logging
import argparse
import random
import numpy as np
import paddle
import paddle.nn as nn
import paddle.nn.functional as F
import paddle.distributed as dist
from datasets import get_dataloader
from datasets import get_dataset
from transformer import build_mae_pretrain as buil... | return argumeents, this will overwrite the config after loading yaml file |
30,106 | import sys
import os
import time
import logging
import argparse
import random
import numpy as np
import paddle
import paddle.nn as nn
import paddle.nn.functional as F
import paddle.distributed as dist
from datasets import get_dataloader
from datasets import get_dataset
from transformer import build_mae_pretrain as buil... | null |
30,141 | import sys
import os
import time
import logging
import argparse
import random
import numpy as np
import paddle
import paddle.nn as nn
import paddle.nn.functional as F
from datasets import get_dataloader
from datasets import get_dataset
from transformer import build_mae_pretrain as build_model
from utils import AverageM... | return argumeents, this will overwrite the config after loading yaml file |
30,142 | import sys
import os
import time
import logging
import argparse
import random
import numpy as np
import paddle
import paddle.nn as nn
import paddle.nn.functional as F
from datasets import get_dataloader
from datasets import get_dataset
from transformer import build_mae_pretrain as build_model
from utils import AverageM... | set logging file and format Args: filename: str, full path of the logger file to write logger_name: str, the logger name, e.g., 'master_logger', 'local_logger' Return: logger: python logger |
30,143 | import sys
import os
import time
import logging
import argparse
import random
import numpy as np
import paddle
import paddle.nn as nn
import paddle.nn.functional as F
from datasets import get_dataloader
from datasets import get_dataset
from transformer import build_mae_pretrain as build_model
from utils import AverageM... | Training for one epoch Args: dataloader: paddle.io.DataLoader, dataloader instance model: nn.Layer, a ViT model criterion: nn.criterion epoch: int, current epoch total_epochs: int, total num of epochs total_batch: int, total num of batches for one epoch debug_steps: int, num of iters to log info, default: 100 accum_ite... |
30,144 | import logging
import sys
import os
import math
import numpy as np
import paddle
import paddle.distributed as dist
The provided code snippet includes necessary dependencies for implementing the `get_logger` function. Write a Python function `def get_logger(file_path)` to solve the following problem:
Set logging file a... | Set logging file and format, logs are written in 2 loggers, one local_logger records the information on its own gpu/process, one master_logger records the overall/average information over all gpus/processes. Args: file_path: str, folder path of the logger files to write Return: local_logger: python logger for each proc... |
30,145 | import logging
import sys
import os
import math
import numpy as np
import paddle
import paddle.distributed as dist
The provided code snippet includes necessary dependencies for implementing the `write_log` function. Write a Python function `def write_log(local_logger, master_logger, msg_local, msg_master=None, level='... | Write messages in loggers Args: local_logger: python logger, logs information on single gpu master_logger: python logger, logs information over all gpus msg_local: str, message to log on local_logger msg_master: str, message to log on master_logger, if None, use msg_local, default: None level: str, log level, in ['info... |
30,146 | import logging
import sys
import os
import math
import numpy as np
import paddle
import paddle.distributed as dist
The provided code snippet includes necessary dependencies for implementing the `all_reduce_mean` function. Write a Python function `def all_reduce_mean(x)` to solve the following problem:
perform all_redu... | perform all_reduce on Tensor for gathering results from multi-gpus |
30,147 | import logging
import sys
import os
import math
import numpy as np
import paddle
import paddle.distributed as dist
The provided code snippet includes necessary dependencies for implementing the `skip_weight_decay_fn` function. Write a Python function `def skip_weight_decay_fn(model, skip_list=[], filter_bias_and_bn=Tr... | Set params with no weight decay during the training For certain params, e.g., positional encoding in ViT, weight decay may not needed during the learning, this method is used to find these params. Args: model: nn.Layer, model skip_list: list, a list of params names which need to exclude from weight decay, default: [] f... |
30,148 | import logging
import sys
import os
import math
import numpy as np
import paddle
import paddle.distributed as dist
def orthogonal(t, gain=1.):
if t.ndim < 2:
raise ValueError("Only tensors with 2 or more dimensions are supported")
gain = paddle.to_tensor(gain)
rows = t.shape[0]
cols = np.... | null |
30,149 | import sys
import os
import time
import argparse
import random
import math
import numpy as np
import paddle
from datasets import get_dataloader
from datasets import get_dataset
from config import get_config
from config import update_config
from utils import AverageMeter
from utils import get_logger
from utils import wr... | return argumeents, this will overwrite the config by (1) yaml file (2) argument values |
30,150 | import sys
import os
import time
import argparse
import random
import math
import numpy as np
import paddle
from datasets import get_dataloader
from datasets import get_dataset
from config import get_config
from config import update_config
from utils import AverageMeter
from utils import get_logger
from utils import wr... | main method for each process |
30,155 | import os
from yacs.config import CfgNode as CN
import yaml
_C = CN()
_C.BASE = ['']
_C.DATA = CN()
_C.DATA.BATCH_SIZE = 256
_C.DATA.BATCH_SIZE_EVAL = None
_C.DATA.DATA_PATH = '/dataset/imagenet/'
_C.DATA.DATASET = 'imagenet2012'
_C.DATA.IMAGE_SIZE = 224
_C.DATA.IMAGE_CHANNELS = 3
_C.DATA.CROP_PCT = 0.875
_C.DAT... | Return a clone of config and optionally overwrite it from yaml file |
30,156 | import math
import numpy as np
import paddle
import paddle.nn as nn
from droppath import DropPath
from utils import orthogonal
class T2TViT(nn.Layer):
""" T2T-ViT model
Args:
image_size: int, input image size, default: 224
in_channels: int, input image channels, default: 3
num_classes: i... | build t2t-vit model using config |
30,157 | import os
import numpy as np
import paddle
import torch
import timm
from config import get_config
from t2t_vit import build_t2t_vit as build_model
from T2T_ViT_torch.models.t2t_vit import *
from T2T_ViT_torch.utils import load_for_transfer_learning
def print_model_named_params(model):
print('----------------------... | null |
30,158 | import os
import numpy as np
import paddle
import torch
import timm
from config import get_config
from t2t_vit import build_t2t_vit as build_model
from T2T_ViT_torch.models.t2t_vit import *
from T2T_ViT_torch.utils import load_for_transfer_learning
def print_model_named_buffers(model):
print('---------------------... | null |
30,159 | import os
import numpy as np
import paddle
import torch
import timm
from config import get_config
from t2t_vit import build_t2t_vit as build_model
from T2T_ViT_torch.models.t2t_vit import *
from T2T_ViT_torch.utils import load_for_transfer_learning
def torch_to_paddle_mapping(model_name, config):
# (torch_param_name,... | null |
30,204 | import sys
import os
import time
import argparse
import random
import math
import numpy as np
import paddle
from datasets import get_dataloader
from datasets import get_dataset
from config import get_config
from config import update_config
from utils import AverageMeter
from utils import get_logger
from utils import wr... | return argumeents, this will overwrite the config by (1) yaml file (2) argument values |
30,205 | import sys
import os
import time
import argparse
import random
import math
import numpy as np
import paddle
from datasets import get_dataloader
from datasets import get_dataset
from config import get_config
from config import update_config
from utils import AverageMeter
from utils import get_logger
from utils import wr... | main method for each process |
30,207 | import os
from yacs.config import CfgNode as CN
import yaml
_C = CN()
_C.BASE = ['']
_C.DATA = CN()
_C.DATA.BATCH_SIZE = 256
_C.DATA.BATCH_SIZE_EVAL = None
_C.DATA.DATA_PATH = '/dataset/imagenet/'
_C.DATA.DATASET = 'imagenet2012'
_C.DATA.IMAGE_SIZE = 224
_C.DATA.IMAGE_CHANNELS = 3
_C.DATA.CROP_PCT = 0.875
_C.DAT... | Return a clone of config and optionally overwrite it from yaml file |
30,208 | import math
from functools import partial
import paddle
import paddle.nn as nn
import paddle.nn.functional as F
from droppath import DropPath
The provided code snippet includes necessary dependencies for implementing the `conv3x3` function. Write a Python function `def conv3x3(in_planes, out_planes, stride=1)` to solv... | 3x3 convolution with padding |
30,209 | import math
from functools import partial
import paddle
import paddle.nn as nn
import paddle.nn.functional as F
from droppath import DropPath
class XCiT(nn.Layer):
"""
Based on timm and DeiT code bases
https://github.com/rwightman/pytorch-image-models/tree/master/timm
https://github.com/facebookresearch... | null |
30,210 | import os
import numpy as np
import paddle
import torch
import timm
from xcit_torch.xcit import *
from xcit import build_xcit as build_model
from config import get_config
def print_model_named_params(model):
print('----------------------------------')
for name, param in model.named_parameters():
print(... | null |
30,211 | import os
import numpy as np
import paddle
import torch
import timm
from xcit_torch.xcit import *
from xcit import build_xcit as build_model
from config import get_config
def print_model_named_buffers(model):
print('----------------------------------')
for name, param in model.named_buffers():
print(na... | null |
30,212 | import os
import numpy as np
import paddle
import torch
import timm
from xcit_torch.xcit import *
from xcit import build_xcit as build_model
from config import get_config
def torch_to_paddle_mapping(model_name, config):
mapping = [
('cls_token', 'cls_token'),
('pos_embeder.token_projection', 'pos_em... | null |
30,251 | import sys
import os
import time
import argparse
import random
import math
import numpy as np
import paddle
from datasets import get_dataloader
from datasets import get_dataset
from config import get_config
from config import update_config
from utils import AverageMeter
from utils import get_logger
from utils import wr... | return argumeents, this will overwrite the config by (1) yaml file (2) argument values |
30,252 | import sys
import os
import time
import argparse
import random
import math
import numpy as np
import paddle
from datasets import get_dataloader
from datasets import get_dataset
from config import get_config
from config import update_config
from utils import AverageMeter
from utils import get_logger
from utils import wr... | main method for each process |
30,257 | import paddle
import paddle.nn as nn
from resnet import resnet50
def expand_dim(t, dim, k):
"""
Expand dims for t at dim to k
"""
t = t.unsqueeze(axis=dim)
expand_shape = [-1] * len(t.shape)
expand_shape[dim] = k
return paddle.expand(t, expand_shape)
def rel_to_abs(x):
"""
x: [B, Nh ... | q: [B, Nh, H, W, d] rel_k: [2W - 1, d] Computes relative logits along one dimension. |
30,258 | import paddle
import paddle.nn as nn
from resnet import resnet50
def botnet50(pretrained=False,
image_size=224,
fmap_size=(14, 14),
num_classes=1000,
embed_dim=2048,
**kwargs):
"""
Bottleneck Transformers for Visual Recognition.
"""
resnet... | null |
30,259 | import sys
import os
import time
import argparse
import random
import math
import numpy as np
import paddle
from datasets import get_dataloader
from datasets import get_dataset
from config import get_config
from config import update_config
from utils import AverageMeter
from utils import get_logger
from utils import wr... | return argumeents, this will overwrite the config by (1) yaml file (2) argument values |
30,260 | import sys
import os
import time
import argparse
import random
import math
import numpy as np
import paddle
from datasets import get_dataloader
from datasets import get_dataset
from config import get_config
from config import update_config
from utils import AverageMeter
from utils import get_logger
from utils import wr... | main method for each process |
30,265 | import os
from yacs.config import CfgNode as CN
import yaml
_C = CN()
_C.BASE = ['']
_C.DATA = CN()
_C.DATA.BATCH_SIZE = 256
_C.DATA.BATCH_SIZE_EVAL = None
_C.DATA.DATA_PATH = '/dataset/imagenet/'
_C.DATA.DATASET = 'imagenet2012'
_C.DATA.IMAGE_SIZE = 256
_C.DATA.IMAGE_CHANNELS = 3
_C.DATA.FMAP_SIZE = (14, 14)
_C.... | Return a clone of config and optionally overwrite it from yaml file |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.