python_code
stringlengths
0
4.04M
repo_name
stringlengths
7
58
file_path
stringlengths
5
147
import sys from pathlib import Path project_root = Path(__file__).absolute().parent.parent.parent sys.path.insert(0, str(project_root)) import os import time import numpy as np import torch import torch.nn as nn from torch import optim import torch.nn.functional as F import torchvision.models as models from . import l...
butterfly-master
cnn/imagenet/training.py
import os, sys sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) import math import unittest import torch from butterfly.permutation_multiply import permutation_mult_torch, permutation_mult from butterfly.permutation_multiply import permutation_mult_single_factor_torch, permutation_mult...
butterfly-master
tests_old/test_permutation_multiply.py
import os, sys sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) import math import unittest import numpy as np import torch from butterfly import Butterfly from butterfly.butterfly import ButterflyBmm from butterfly.butterfly_multiply import butterfly_ortho_mult_tied class Butterfl...
butterfly-master
tests_old/test_butterfly.py
import os, sys sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) import math import unittest import torch from butterfly import Butterfly from butterfly.utils import twiddle_normal_to_fast_format from butterfly.butterfly_multiply import butterfly_mult_torch, butterfly_mult, butterfly_m...
butterfly-master
tests_old/test_butterfly_multiply.py
import os, sys sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) import math import unittest import numpy as np import torch from butterfly.permutation import Permutation, FixedPermutation, PermutationFactor class PermutationTest(unittest.TestCase): def test_permutation(self): ...
butterfly-master
tests_old/test_permutation.py
import math import numpy as np import torch from torch import nn from torch.utils.dlpack import to_dlpack, from_dlpack # Check if cupy is available if torch.cuda.is_available(): use_cupy = True try: import cupy as cp except: use_cupy = False # import warnings # warnings.war...
butterfly-master
torch_butterfly/complex_utils.py
import math import numbers import torch from torch import nn import torch.nn.functional as F import torch_butterfly from torch_butterfly.multiply import butterfly_multiply from torch_butterfly.multiply import butterfly_multiply_torch from torch_butterfly.complex_utils import real_dtype_to_complex, complex_reshape fro...
butterfly-master
torch_butterfly/butterfly.py
import copy import torch from torch import nn from torch.nn import functional as F from torch_butterfly import Butterfly from torch_butterfly.permutation import FixedPermutation, bitreversal_permutation def diagonal_butterfly(butterfly: Butterfly, diagonal: torch.Tensor, ...
butterfly-master
torch_butterfly/combine.py
import math from typing import Tuple, Optional import torch from torch.nn import functional as F @torch.jit.script def butterfly_multiply_fw(twiddle: torch.Tensor, input: torch.Tensor, increasing_stride: bool, output_size: Optional[int] = None) -> torch.Tensor: return torch.ops.torch_bu...
butterfly-master
torch_butterfly/multiply.py
import importlib from pathlib import Path import torch __version__ = '0.0.0' for library in ['_version', '_butterfly']: torch.ops.load_library(importlib.machinery.PathFinder().find_spec( # need str(Path) otherwise it can't find it library, [str(Path(__file__).absolute().parent)]).origin) def che...
butterfly-master
torch_butterfly/__init__.py
import math import torch import torch.nn.functional as F from torch_butterfly.multiply import butterfly_multiply from benchmark_utils import benchmark, benchmark_fw_bw batch_size = 2048 n = 512 log_n = int(math.log2(n)) assert n == 1 << log_n input_size = n - 7 output_size = n - 5 input = torch.randn(batch_size, ...
butterfly-master
torch_butterfly/input_padding_benchmark.py
import math import torch from torch.nn import functional as F def butterfly_multiply_base4_torch(twiddle4, twiddle2, input, increasing_stride=True, output_size=None): batch_size, nstacks, input_size = input.shape nblocks = twiddle4.shape[1] log_n = twiddle4.shape[2] * 2...
butterfly-master
torch_butterfly/multiply_base4.py
import math import numpy as np import torch from torch import nn from torch_butterfly.complex_utils import real_dtype_to_complex class Diagonal(nn.Module): def __init__(self, size=None, complex=False, diagonal_init=None): """Multiply by diagonal matrix Parameter: size: int ...
butterfly-master
torch_butterfly/diagonal.py
import math from typing import List, Tuple, Union import numpy as np import scipy.linalg import torch from torch import nn from torch_butterfly import Butterfly from torch_butterfly.complex_utils import index_last_dim, real2complex def bitreversal_permutation(n, pytorch_format=False): """Return the bit reversa...
butterfly-master
torch_butterfly/permutation.py
import math import numbers import torch from torch import nn import torch.nn.functional as F from torch_butterfly import Butterfly from torch_butterfly.multiply_base4 import butterfly_multiply_base4_torch from torch_butterfly.multiply_base4 import twiddle_base2_to_base4 from torch_butterfly.complex_utils import real_...
butterfly-master
torch_butterfly/butterfly_base4.py
from functools import partial import numpy as np import torch def benchmark(fn, nrepeats=7): res = [] for _ in range(nrepeats): start = torch.cuda.Event(enable_timing=True) end = torch.cuda.Event(enable_timing=True) start.record() fn() end.record() torch.cuda.s...
butterfly-master
torch_butterfly/benchmark_utils.py
import math from functools import reduce import torch from torch import nn from torch.nn import functional as F import torch.fft from torch_butterfly.butterfly import Butterfly, ButterflyUnitary from torch_butterfly.permutation import FixedPermutation, bitreversal_permutation, invert from torch_butterfly.permutation ...
butterfly-master
torch_butterfly/special.py
"""My torch implementation of permutations and sinkhorn balancing ops. A torch library of operations and sampling with permutations and their approximation with doubly-stochastic matrices, through Sinkhorn balancing """ import numpy as np from scipy.optimize import linear_sum_assignment from scipy.stats import kenda...
butterfly-master
gumbel-sinkhorn/my_sinkhorn_ops.py
"""Model class for sorting numbers.""" import torch.nn as nn class Features(nn.Module): def __init__(self, latent_dim, output_dim, dropout_prob): """ In the constructor we instantiate two nn.Linear modules and assign them as member variables. This Feature extractor class takes a...
butterfly-master
gumbel-sinkhorn/my_sorting_model.py
import torch import numpy import torch.nn as nn from torch.autograd import Variable import matplotlib.pyplot as plt import os import argh import my_sorting_model import my_sinkhorn_ops dir_path = os.path.dirname(os.path.realpath(__file__)) device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') def ...
butterfly-master
gumbel-sinkhorn/my_sorting_train.py
import torch import numpy import torch.nn as nn import os import argh import my_sorting_model import my_sinkhorn_ops from my_sorting_train import make_random_batch dir_path = os.path.dirname(os.path.realpath(__file__)) device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') # Test process def test_mo...
butterfly-master
gumbel-sinkhorn/my_sinkhorn_eval.py
import io import glob import os from shutil import move from os.path import join from os import listdir, rmdir target_folder = './val/' test_folder = './test/' os.mkdir(test_folder) val_dict = {} with open('./val/val_annotations.txt', 'r') as f: for line in f.readlines(): split_line = line.split('\t') ...
butterfly-master
data/tiny-imagenet-200/val_format.py
from pathlib import Path project_root = Path(__file__).parent.absolute() import os import random import math from collections.abc import Sequence from functools import partial import torch import pytorch_lightning as pl from pytorch_lightning.callbacks import Callback from munch import Munch import ray from ray im...
butterfly-master
convolution/ray_runner.py
# Adapted from https://github.com/algrebe/python-tee, ported to Python 3 import os import sys from abc import ABCMeta, abstractmethod class Tee(object): """ duplicates streams to a file. credits : http://stackoverflow.com/q/616645 """ def __init__(self, filename, mode="a", file_filters=None, strea...
butterfly-master
convolution/tee.py
import torch from torch import nn from torch.nn import functional as F class Task: @staticmethod def metrics(outs, y, len_batch=None): return {} @staticmethod def metrics_epoch(outs, y, len_batch=None): return {} class BinaryClassification(Task): @staticmethod def loss(logit...
butterfly-master
convolution/tasks.py
from pathlib import Path import torch import pytorch_lightning as pl from pytorch_lightning.callbacks import Callback def pl_train(cfg, pl_module_cls, **kwargs): trainer_args = dict( gpus=1, max_epochs=1 if cfg.smoke_test else cfg.train.epochs, checkpoint_callback=False, # Disable check...
butterfly-master
convolution/pl_runner.py
import torch def LeNetScheduler(optimizer, nepochs, **kwargs): def sched(epoch): if epoch < int(nepochs * 0.5): return 1.0 elif epoch < int(nepochs * 0.75): return 0.5 else: return 0.1 return torch.optim.lr_scheduler.LambdaLR(optimizer, lr_lambda=l...
butterfly-master
convolution/lr_schedulers.py
import torch from omegaconf.dictconfig import DictConfig from munch import Munch def remove_postfix(text, postfix): if text.endswith(postfix): return text[:-len(postfix)] return text # pytorch-lightning returns pytorch 0-dim tensor instead of python scalar def to_scalar(x): return x.item() if i...
butterfly-master
convolution/utils.py
from pathlib import Path PROJECT_ROOT = Path(__file__).parent.absolute() import os # Add to $PYTHONPATH so that ray workers can see os.environ['PYTHONPATH'] = str(PROJECT_ROOT) + ":" + os.environ.get('PYTHONPATH', '') import torch import pytorch_lightning as pl import hydra from omegaconf import OmegaConf import mod...
butterfly-master
convolution/train.py
from .cifar import *
butterfly-master
convolution/datamodules/__init__.py
from pathlib import Path current_dir = Path(__file__).parent.absolute() import torch from torch.utils.data import DataLoader, random_split from torchvision import transforms, datasets from pl_bolts.datamodules import CIFAR10DataModule class CIFAR10(CIFAR10DataModule): def __init__(self, data_dir=current_dir, e...
butterfly-master
convolution/datamodules/cifar.py
import torch.nn as nn import torch.nn.functional as F from .lenet import LeNetPadded from .kops import KOP2d from .lops import LOP2d class ButterfLeNet(LeNetPadded): name = 'butterflenet' def __init__(self, num_classes=10, pooling_mode='avg', butterfly=True, **kwargs): nn.Module.__init__(self) ...
butterfly-master
convolution/models/butterflenet.py
'''ResNet in PyTorch. Small variants for CIFAR Reference: [1] Kaiming He, Xiangyu Zhang, Shaoqing Ren, Jian Sun Deep Residual Learning for Image Recognition. arXiv:1512.03385 ''' import torch import torch.nn as nn import torch.nn.functional as F import torch.nn.init as init __all__ = ['ResNet8', 'ResNet14', 'Res...
butterfly-master
convolution/models/resnet_cifar.py
'''Baseline CNN in PyTorch.''' # Adapted from https://github.com/peterliht/knowledge-distillation-pytorch/blob/master/model/net.py import torch.nn as nn import torch.nn.functional as F from .cnn5 import CNN5 from .kops import KOP2d class CNN5Butterfly(CNN5): name = 'cnn5butterfly' def __init__(self, num_ch...
butterfly-master
convolution/models/cnn5_butterfly.py
from .lenet import * from .resnet import * from .resnet_cifar import * from .cnn5 import * from .butterflenet import * from .cnn5_butterfly import *
butterfly-master
convolution/models/__init__.py
'''Baseline CNN in PyTorch.''' # Adapted from https://github.com/peterliht/knowledge-distillation-pytorch/blob/master/model/net.py import torch.nn as nn import torch.nn.functional as F class CNN5(nn.Module): name = 'cnn5' def __init__(self, num_channels=32, num_classes=10): super().__init__() ...
butterfly-master
convolution/models/cnn5.py
'''LeNet in PyTorch.''' import torch.nn as nn import torch.nn.functional as F class LeNet(nn.Module): name = 'lenet' def __init__(self, num_classes=10): super().__init__() self.conv1 = nn.Conv2d(3, 6, 5) self.conv2 = nn.Conv2d(6, 16, 5) self.fc1 = nn.Linear(16*5*5, 120) ...
butterfly-master
convolution/models/lenet.py
'''ResNet in PyTorch. For Pre-activation ResNet, see 'preact_resnet.py'. Reference: [1] Kaiming He, Xiangyu Zhang, Shaoqing Ren, Jian Sun Deep Residual Learning for Image Recognition. arXiv:1512.03385 ''' import torch import torch.nn as nn import torch.nn.functional as F __all__ = ['ResNet', 'ResNet18', 'ResNet...
butterfly-master
convolution/models/resnet.py
import math import torch import torch.nn as nn import torch.nn.functional as F import torch.fft import torch_butterfly from torch_butterfly import Butterfly from torch_butterfly.complex_utils import ComplexLinear from torch_butterfly.complex_utils import Real2Complex, Complex2Real from torch_butterfly.complex_utils i...
butterfly-master
convolution/models/lops.py
import unittest import torch import torch.nn as nn from kops import KOP2d class KOP2dTest(unittest.TestCase): def setUp(self): self.rtol = 1e-4 self.atol = 1e-5 def test_fft_init(self): batch_size = 10 in_ch, out_ch = 3, 6 for in_size in [(32, 32), (16, 16), (32, 16...
butterfly-master
convolution/models/test_kops.py
import math import torch import torch.nn as nn import torch.nn.functional as F import torch_butterfly from torch_butterfly import Butterfly from torch_butterfly.complex_utils import Real2Complex, Complex2Real from torch_butterfly.complex_utils import complex_matmul from torch_butterfly.combine import TensorProduct fr...
butterfly-master
convolution/models/kops.py
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. from configs import Config ########### running ########### # torchrun --nproc_per_node=8 main.py <config> def eval_yfcc15m_in1k_mocob16(): return Config( output_dir="yfcc15m_in1k_mocob16", eval=True, resume="chec...
CiT-main
run_configs.py
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. import os import inspect from collections import OrderedDict class Config: dataset = "yfcc15m_tag" root = "data/yfcc15m" metadata = "data/yfcc15m/yfcc15m_w_tag.pkl" # data adaptation val_task = "imagenet" max_sample ...
CiT-main
configs.py
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. import torch from transformers import VisionTextDualEncoderModel class CiTCLIPVisionTextDualEncoderModel(VisionTextDualEncoderModel): '''a hf model wrapper to support forward with either or both image/text. note that HF impl. uses a...
CiT-main
models_citclip.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. # -------------------------------------------------------- # A script to run multinode training with submitit. # ----------...
CiT-main
submitit_citclip.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. # -------------------------------------------------------- # References: # DeiT: https://github.com/facebookresearch/deit #...
CiT-main
engine.py
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. """ pre-configed sweeps. """ import json class alltask_5k_mr005: batch_size = [1536], "bsz" max_update = [5000], "s" refilter = [100], "refilter" prefilter = [0.45], "" min_ratio = [0.05], "r" sublist = [True], "" ...
CiT-main
sweeps.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. # Copyright (c) Meta Platforms, Inc. All Rights Reserved import torch import torch.nn as nn import torch.nn.functional as ...
CiT-main
losses.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. # -------------------------------------------------------- # References: # DeiT: https://github.com/facebookresearch/deit #...
CiT-main
main.py
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. """ pre-configed trainable weights. """ pre_projection_weights = ['logit_scale', 'visual_projection.weight', 'text_projection.weight'] # TODO: unify layer selection for all models. pre_vision_trainable_weights = { "moco": { "hea...
CiT-main
weights.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. # -------------------------------------------------------- # References: # DeiT: https://github.com/facebookresearch/deit #...
CiT-main
util/misc.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. # Copyright (c) Meta Platforms, Inc. All Rights Reserved import math def adjust_step_learning_rate(optimizer, step, lr, ...
CiT-main
util/lr_sched.py
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. import torch from transformers import ( PreTrainedModel, PretrainedConfig, AutoConfig, AutoModel, ) from transformers.modeling_outputs import BaseModelOutputWithPooling import timm assert timm.__version__ >= "0.4.12", "make ...
CiT-main
hfmodels/augreg.py
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. import torch from transformers import ( PreTrainedModel, PretrainedConfig, AutoConfig, AutoModel, ) from transformers.modeling_outputs import BaseModelOutputWithPooling class SwagConfig(PretrainedConfig): model_type = "...
CiT-main
hfmodels/swag.py
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. from .moco import MoCoModel, MoCoConfig from .augreg import AugRegModel, AugRegConfig from .swag import SwagModel, SwagConfig
CiT-main
hfmodels/__init__.py
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. import torch import sys sys.path.append("moco-v3") # repo path to moco-v3 from transformers import ( PreTrainedModel, PretrainedConfig, AutoConfig, AutoModel, ) from torch import nn from transformers.modeling_outputs import ...
CiT-main
hfmodels/moco.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. # Copyright (c) Meta Platforms, Inc. All Rights Reserved import numpy as np import pickle import re import time import sq...
CiT-main
scripts/make_yfcc100m_dataset.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. # Copyright (c) Meta Platforms, Inc. All Rights Reserved import numpy as np import pickle import re from urllib.parse imp...
CiT-main
scripts/make_yfcc15m_dataset.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. # Copyright (c) Meta Platforms, Inc. All Rights Reserved import json import os import pickle import zipfile import numpy ...
CiT-main
clipeval/datasets.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. # Copyright (c) Meta Platforms, Inc. All Rights Reserved import torch import json import os from sklearn import metrics ...
CiT-main
clipeval/eval_zeroshot.py
# Copyright (c) Facebook, Inc. and its affiliates. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # import argparse import time import yaml import torch import utils.logger from utils import main_utils, eval_utils import...
AVID-CMA-main
eval-action-recg.py
# Copyright (c) Facebook, Inc. and its affiliates. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # import argparse import os import random import time import warnings import yaml import torch import torch.nn.parallel im...
AVID-CMA-main
main-avid.py
# Copyright (c) Facebook, Inc. and its affiliates. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # import argparse import time import yaml import torch from utils import main_utils, eval_utils import utils.logger import...
AVID-CMA-main
eval-action-recg-linear.py
# Copyright (c) Facebook, Inc. and its affiliates. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # import csv import numpy as np import glob from datasets.video_db import VideoDataset DATA_PATH = '/data/datasets/AS240/d...
AVID-CMA-main
datasets/audioset.py
# Copyright (c) Facebook, Inc. and its affiliates. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # from .audioset import AudioSet from .kinetics import Kinetics from .ucf import UCF from .hmdb import HMDB
AVID-CMA-main
datasets/__init__.py
# Copyright (c) Facebook, Inc. and its affiliates. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # import torch import numpy as np import random import librosa from utils.videotransforms import video_transforms, volume_t...
AVID-CMA-main
datasets/preprocessing.py
# Copyright (c) Facebook, Inc. and its affiliates. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # import random import torch import numpy as np import torch.utils.data as data from utils.ioutils import av_wrappers from ...
AVID-CMA-main
datasets/video_db.py
# Copyright (c) Facebook, Inc. and its affiliates. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # import os from datasets.video_db import VideoDataset DATA_PATH = '/data/datasets/hmdb/videos' ANNO_PATH = '/data/dataset...
AVID-CMA-main
datasets/hmdb.py
# Copyright (c) Facebook, Inc. and its affiliates. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # from datasets.video_db import VideoDataset DATA_PATH = '/data/datasets/UCF101/data' ANNO_PATH = '/data/datasets/UCF101/u...
AVID-CMA-main
datasets/ucf.py
# Copyright (c) Facebook, Inc. and its affiliates. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # import os import glob import numpy as np DATA_PATH = '/data/datasets/kinetics/' from datasets.video_db import VideoDa...
AVID-CMA-main
datasets/kinetics.py
# Copyright (c) Facebook, Inc. and its affiliates. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. #
AVID-CMA-main
utils/__init__.py
# Copyright (c) Facebook, Inc. and its affiliates. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # import datetime import sys import torch from torch import distributed as dist class Logger(object): def __init__(s...
AVID-CMA-main
utils/logger.py
# Copyright (c) Facebook, Inc. and its affiliates. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # import torch from torch import distributed as dist def _gather_from_all(tensor): """ Gather tensors from all gp...
AVID-CMA-main
utils/distributed_utils.py
# Copyright (c) Facebook, Inc. and its affiliates. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # import torch from collections import deque def accuracy(output, target, topk=(1,)): """Computes the accuracy over t...
AVID-CMA-main
utils/metrics_utils.py
# Copyright (c) Facebook, Inc. and its affiliates. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # import torch class AliasMethod(object): """ From: https://hips.seas.harvard.edu/blog/2013/03/03/the-alias-metho...
AVID-CMA-main
utils/alias_method.py
# Copyright (c) Facebook, Inc. and its affiliates. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # import os import shutil import torch import numpy as np import torch.distributed as dist import datetime from utils.logg...
AVID-CMA-main
utils/main_utils.py
# Copyright (c) Facebook, Inc. and its affiliates. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # import torch from torch import nn import torch.distributed as dist import utils.logger from utils import main_utils impo...
AVID-CMA-main
utils/eval_utils.py
# Copyright (c) Facebook, Inc. and its affiliates. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. #
AVID-CMA-main
utils/ioutils/__init__.py
# Copyright (c) Facebook, Inc. and its affiliates. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # import av import numpy as np from fractions import Fraction av.logging.set_level(0) def av_open(inpt): return av.ope...
AVID-CMA-main
utils/ioutils/av_wrappers.py
# Copyright (c) Facebook, Inc. and its affiliates. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # import random import torch from utils.videotransforms.utils import functional as F class Normalize(object): """Norm...
AVID-CMA-main
utils/videotransforms/tensor_transforms.py
# Copyright (c) Facebook, Inc. and its affiliates. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # import numpy as np from PIL import Image import torch from utils.videotransforms.utils import images as imageutils cla...
AVID-CMA-main
utils/videotransforms/volume_transforms.py
# Copyright (c) Facebook, Inc. and its affiliates. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # import numbers import numpy as np import PIL def crop_clip(clip, min_h, min_w, h, w): if isinstance(clip[0], np.nd...
AVID-CMA-main
utils/videotransforms/functional.py
# Copyright (c) Facebook, Inc. and its affiliates. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # import numpy as np import PIL import torch from utils.videotransforms.utils import images as imageutils class ToStacke...
AVID-CMA-main
utils/videotransforms/stack_transforms.py
# Copyright (c) Facebook, Inc. and its affiliates. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # import numbers import random import numpy as np import PIL import torchvision import warnings import math from utils.vid...
AVID-CMA-main
utils/videotransforms/video_transforms.py
# Copyright (c) Facebook, Inc. and its affiliates. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # def normalize(tensor, mean, std): """ Args: tensor (Tensor): Tensor to normalize Returns: Te...
AVID-CMA-main
utils/videotransforms/utils/functional.py
# Copyright (c) Facebook, Inc. and its affiliates. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # import numpy as np def convert_img(img): """Converts (H, W, C) numpy.ndarray to (C, W, H) format """ if len...
AVID-CMA-main
utils/videotransforms/utils/images.py
# Copyright (c) Facebook, Inc. and its affiliates. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # from .video import * from .audio import * from .av_wrapper import *
AVID-CMA-main
models/__init__.py
# Copyright (c) Facebook, Inc. and its affiliates. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # import torch import torch.nn as nn import numpy as np class Basic2DBlock(nn.Module): def __init__(self, in_planes, ...
AVID-CMA-main
models/network_blocks.py
# Copyright (c) Facebook, Inc. and its affiliates. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # import torch import torch.nn as nn __all__ = [ 'av_wrapper' ] class Head(nn.Module): def __init__(self, input...
AVID-CMA-main
models/av_wrapper.py
# Copyright (c) Facebook, Inc. and its affiliates. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # import torch.nn as nn from .network_blocks import Basic2DBlock __all__ = [ 'Conv2D' ] class Conv2D(nn.Module): ...
AVID-CMA-main
models/audio.py
# Copyright (c) Facebook, Inc. and its affiliates. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # import torch.nn as nn from models.network_blocks import BasicR2P1DBlock class R2Plus1D(nn.Module): """ Adapted ...
AVID-CMA-main
models/video.py
# Copyright (c) Facebook, Inc. and its affiliates. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # from .avid import * from .avid_cma import *
AVID-CMA-main
criterions/__init__.py
# Copyright (c) Facebook, Inc. and its affiliates. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # import torch from torch import nn from torch.nn import functional as F import torch.distributed as dist import pprint fro...
AVID-CMA-main
criterions/avid.py
# Copyright (c) Facebook, Inc. and its affiliates. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # import torch from torch import nn import torch.distributed as dist from utils.distributed_utils import _gather_from_all ...
AVID-CMA-main
criterions/nce.py
# Copyright (c) Facebook, Inc. and its affiliates. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # import multiprocessing as mp mp.set_start_method('spawn', force=True) import torch from torch import nn from torch.nn im...
AVID-CMA-main
criterions/avid_cma.py
"""Init."""
fm_data_tasks-main
fm_data_tasks/__init__.py
"""Run inference.""" import argparse import json import logging from pathlib import Path import numpy as np from manifest import Manifest import fm_data_tasks.utils.data_utils as data_utils import fm_data_tasks.utils.prompt_utils as prompt_utils from fm_data_tasks.utils import constants from fm_data_tasks.utils.utils...
fm_data_tasks-main
fm_data_tasks/run_inference.py
"""Constants.""" import os from pathlib import Path DATASET_PATH = os.environ.get("DATASET_PATH", Path("data/datasets").resolve()) DATA2TASK = { f"{DATASET_PATH}/entity_matching/structured/Amazon-Google": "entity_matching", f"{DATASET_PATH}/entity_matching/structured/Beer": "entity_matching", f"{DATASET_...
fm_data_tasks-main
fm_data_tasks/utils/constants.py
"""Init."""
fm_data_tasks-main
fm_data_tasks/utils/__init__.py
"""Data utils.""" import logging from functools import partial from pathlib import Path from typing import Dict, List import pandas as pd from fm_data_tasks.utils import constants logger = logging.getLogger(__name__) def sample_train_data(train: pd.DataFrame, n_rows: int): """ Sample train data. Used ...
fm_data_tasks-main
fm_data_tasks/utils/data_utils.py