python_code stringlengths 0 4.04M | repo_name stringlengths 7 58 | file_path stringlengths 5 147 |
|---|---|---|
from torchvision import transforms as transforms
from unagi.data.transforms.image.transform import UnagiTransform
class RandomResizedCrop(UnagiTransform):
def __init__(
self,
size,
name=None,
prob=1.0,
level=0,
scale=(0.08, 1.0),
ratio=(0.75, 1.333_333_333_... | thanos-code-main | unagi/data/transforms/image/random_resize_crop.py |
import random
from PIL import Image
from unagi.data.transforms.image.transform import UnagiTransform
from unagi.data.transforms.image.utils import categorize_value
class ShearX(UnagiTransform):
value_range = (0.0, 0.3)
def __init__(self, name=None, prob=1.0, level=0):
super().__init__(name, prob, ... | thanos-code-main | unagi/data/transforms/image/shear_x.py |
from torchvision import transforms as transforms
from unagi.data.transforms.image.transform import UnagiTransform
class RandomCrop(UnagiTransform):
def __init__(
self,
size,
padding=None,
pad_if_needed=False,
fill=0,
padding_mode="constant",
name=None,
... | thanos-code-main | unagi/data/transforms/image/random_crop.py |
from PIL import ImageEnhance
from unagi.data.transforms.image.transform import UnagiTransform
from unagi.data.transforms.image.utils import categorize_value
class Contrast(UnagiTransform):
value_range = (0.1, 1.9)
def __init__(self, name=None, prob=1.0, level=0):
super().__init__(name, prob, level)... | thanos-code-main | unagi/data/transforms/image/contrast.py |
from torchvision import transforms as transforms
from unagi.data.transforms.image.transform import UnagiTransform
class ToTensor(UnagiTransform):
def __init__(self, name=None, prob=1.0, level=0):
super().__init__(name, prob, level)
def transform(self, pil_img, label, **kwargs):
return transf... | thanos-code-main | unagi/data/transforms/image/to_tensor.py |
from torchvision import transforms as transforms
from unagi.data.transforms.image.transform import UnagiTransform
class RandomHorizontalFlip(UnagiTransform):
def __init__(self, p=0.5, name=None, prob=1.0, level=0):
self.p = p
self.transform_func = transforms.RandomHorizontalFlip(p)
super... | thanos-code-main | unagi/data/transforms/image/random_horizontal_flip.py |
from PIL import Image
from unagi.data.transforms.image.transform import UnagiTransform
class VerticalFlip(UnagiTransform):
def __init__(self, name=None, prob=1.0, level=0):
super().__init__(name, prob, level)
def transform(self, pil_img, label, **kwargs):
return pil_img.transpose(Image.FLIP_... | thanos-code-main | unagi/data/transforms/image/vertical_flip.py |
from unagi.data.transforms.task.transform import (
GroupTransform,
IdentityTransform,
MaskGen,
TupleTransform,
)
ALL_TRANSFORMS = {
"Contrastive": GroupTransform,
"MaskGenerator": MaskGen,
"Mask": TupleTransform,
"Identity": IdentityTransform,
}
| thanos-code-main | unagi/data/transforms/task/__init__.py |
import torch
from unagi.data.transforms.image.compose import Compose
class IdentityTransform:
def __init__(self):
pass
def __call__(self, x, label):
return x, label
class GroupTransform:
def __init__(self, transform, views=2):
self.t = transform
self.views = views
... | thanos-code-main | unagi/data/transforms/task/transform.py |
class Compose(object):
"""Composes several transforms together.
Originally from:
https://pytorch.org/docs/stable/_modules/torchvision/transforms/transforms.html#Compose
Args:
transforms (list of ``Transform`` objects): list of transforms to compose.
"""
def __init__(self, transforms... | thanos-code-main | unagi/data/transforms/text/compose.py |
from unagi.data.transforms.text.back_translate import BackTranslate
from unagi.data.transforms.text.identity import Identity
from unagi.data.transforms.text.pretrained_lm_tokenize import PretrainedLMTokenize
ALL_TRANSFORMS = {
"PretrainedLMTokenize": PretrainedLMTokenize,
"BackTranslate": BackTranslate,
"I... | thanos-code-main | unagi/data/transforms/text/__init__.py |
import torch
from transformers import AutoTokenizer
from unagi.data.transforms.text.transform import UnagiTransform
class PretrainedLMTokenize(UnagiTransform):
def __init__(
self,
name=None,
prob=1.0,
level=0,
model="bert-base-uncased",
padding="max_length",
... | thanos-code-main | unagi/data/transforms/text/pretrained_lm_tokenize.py |
import random
PRECISION = 3
class UnagiTransform(object):
"""Base UnagiTransform transfrom class.
Args:
name(str): Transformation name.
prob(float): Transformation probability.
level(int): Transformation level.
"""
def __init__(self, name=None, prob=1.0, level=0):
self.nam... | thanos-code-main | unagi/data/transforms/text/transform.py |
import math
import os
import pickle
from zipfile import ZipFile
import numpy as np
from unagi.data.transforms.text.transform import UnagiTransform
class BackTranslate(UnagiTransform):
def __init__(self, name=None, prob=1.0, level=0, select_prob=0.5):
super().__init__(name, prob, level)
self.sele... | thanos-code-main | unagi/data/transforms/text/back_translate.py |
from unagi.data.transforms.image.transform import UnagiTransform
class Identity(UnagiTransform):
def __init__(self, name=None, prob=1.0, level=0):
super().__init__(name, prob, level)
def transform(self, pil_img, label, **kwargs):
return pil_img, label
| thanos-code-main | unagi/data/transforms/text/identity.py |
import random
from typing import Tuple
import numpy as np
import torch
from unagi.data.transforms.image.transform import UnagiTransform
class Mixup(UnagiTransform):
def __init__(
self,
name=None,
prob=1.0,
level=0,
alpha=1.0,
same_class_ratio=-1.0,
prob_la... | thanos-code-main | unagi/data/augmentations/mixup.py |
import random
from unagi.data.transforms.image.cutout import Cutout as CutoutTransform
from unagi.data.transforms.image.transform import UnagiTransform
class Cutout(UnagiTransform):
def __init__(
self,
name=None,
prob=1.0,
level=0,
alpha=1.0,
same_class_ratio=-1.0,... | thanos-code-main | unagi/data/augmentations/cutout.py |
from unagi.data.augmentations.brightness import Brightness
from unagi.data.augmentations.cutout import Cutout
from unagi.data.augmentations.mixup import Mixup
AUGMENTATIONS = {
"mixup": Mixup,
# "invert": Invert,
"cutout": Cutout,
# "solarize": Solarize,
"brightness": Brightness,
# "rotate": Ro... | thanos-code-main | unagi/data/augmentations/__init__.py |
import random
from unagi.data.transforms.image.brightness import Brightness as BrightnessTransform
from unagi.data.transforms.image.transform import UnagiTransform
class Brightness(UnagiTransform):
def __init__(
self,
name=None,
prob=1.0,
level=0,
alpha=1.0,
same_c... | thanos-code-main | unagi/data/augmentations/brightness.py |
import math
import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
from einops import rearrange
def binary_cross_entropy(logits, y):
# BCE loss requires squeezing last dimension of logits so it has the same
# shape as y
# requires y to be float, since it's overloaded to rep... | thanos-code-main | unagi/trainer/metrics.py |
from dataclasses import dataclass
from typing import Dict, Union
import torchmetrics as tm
import unagi.trainer.callbacks as C
import unagi.trainer.metrics as M
@dataclass
class UnagiTask:
name: str
task_weight: Union[int, float]
task_flow: Dict
losses: Dict
metrics: Dict
torchmetrics: Dict
... | thanos-code-main | unagi/trainer/task.py |
from unagi.models import MODULE_DICTS
from unagi.tasks import LOSS_MODULE_REGISTRY, TASK_PREPROCESSING_LAYER
MODULE_REGISTRY = {
"preprocessors": TASK_PREPROCESSING_LAYER,
"losses": LOSS_MODULE_REGISTRY,
**MODULE_DICTS,
}
| thanos-code-main | unagi/trainer/__init__.py |
import logging
from typing import Any, Dict, List, Optional, Union
from torch import nn
from torch.nn import ModuleDict
from unagi.task import UnagiTask
logger = logging.getLogger(__name__)
class UnagiModel(nn.Module):
"""A class to build multi-task model.
Args:
name: Name of the model, defaults to ... | thanos-code-main | unagi/trainer/model.py |
import math
import matplotlib.pyplot as plt
import numpy as np
import torch
import wandb
from einops import rearrange
from sklearn.manifold import TSNE
class UnagiCallback:
def __init__(self):
self.train_batches = {}
self.val_batches = {}
self.test_batches = {}
def on_train_batch_end... | thanos-code-main | unagi/trainer/callbacks.py |
""" Scheduler Class -- Credit: Emmental"""
import random
from abc import ABC, abstractmethod
from typing import Iterator, List, Tuple, Union
import torch
from unagi.trainer.model import UnagiModel
class Scheduler(ABC):
"""Generate batch generator from dataloaders in designed order."""
def __init__(self) -... | thanos-code-main | unagi/trainer/scheduler.py |
from typing import List
import hydra
import pytorch_lightning as pl
import torch
from torch.backends import cudnn as cudnn
from unagi.task import create_tasks, instantiate_modules
from unagi.trainer.model import UnagiModel
from unagi.trainer.scheduler import SCHEDULERS
def process_inputs(inputs_list, output_dict, Y... | thanos-code-main | unagi/trainer/trainer.py |
""" Unagi DataLoader and default collate fn
code inspiration: emmental
"""
import copy
import logging
from collections import defaultdict
from functools import partial
from typing import Any, Callable, Dict, List, Optional, Tuple, Union
from torch import Tensor
from torch.utils.data import DataLoader
from unagi.... | thanos-code-main | unagi/trainer/data.py |
"""
Copyright (c) Facebook, Inc. and its affiliates.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
"""
import logging
import os
from functools import partial
from pathlib import Path
import matplotlib.pyplot as plt
import numpy as np
import pa... | decodable_information_bottleneck-main | aggregate.py |
"""
Copyright (c) Facebook, Inc. and its affiliates.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
Script to use to change directory structure in `tmp_results/*` in case you change the default
directory structure (i.e. you change `hyperparamete... | decodable_information_bottleneck-main | add_hyperparam.py |
"""
Copyright (c) Facebook, Inc. and its affiliates.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
"""
import logging
import os
import string
from copy import deepcopy
import hydra
import matplotlib.pyplot as plt
import numpy as np
import panda... | decodable_information_bottleneck-main | load_models.py |
"""
Copyright (c) Facebook, Inc. and its affiliates.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
"""
import contextlib
import copy
import logging
import math
import os
import subprocess
from functools import partial, partialmethod
from pathli... | decodable_information_bottleneck-main | main.py |
"""
Copyright (c) Facebook, Inc. and its affiliates.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
"""
# should be in a hydra file
UNLABELLED_CLASS = -1
| decodable_information_bottleneck-main | dib/__init__.py |
"""
Copyright (c) Facebook, Inc. and its affiliates.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
"""
from .trainer import *
| decodable_information_bottleneck-main | dib/training/__init__.py |
"""
Copyright (c) Facebook, Inc. and its affiliates.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
"""
import logging
import warnings
from contextlib import suppress
import numpy as np
import skorch
import torch
import torch.nn as nn
from scip... | decodable_information_bottleneck-main | dib/training/trainer.py |
"""
Copyright (c) Facebook, Inc. and its affiliates.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
"""
import copy
import random
import warnings
import numpy as np
import skorch
import torch
from skorch.callbacks import Callback
from dib.util... | decodable_information_bottleneck-main | dib/training/helpers.py |
"""
Copyright (c) Facebook, Inc. and its affiliates.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
Pruning methods modified from:
https://pytorch.org/docs/master/_modules/torch/nn/utils/prune.html
"""
import numbers
from abc import abstractmet... | decodable_information_bottleneck-main | dib/utils/pruning.py |
"""
Copyright (c) Facebook, Inc. and its affiliates.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
"""
| decodable_information_bottleneck-main | dib/utils/__init__.py |
"""
Copyright (c) Facebook, Inc. and its affiliates.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
"""
import functools
import random
import numpy as np
import torch
from .helpers import channels_to_last_dim, indep_shuffle_, prod, ratio_to_in... | decodable_information_bottleneck-main | dib/utils/datasplit.py |
"""
Copyright (c) Facebook, Inc. and its affiliates.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
"""
import logging
import math
import torch
from torch import nn
from torch.nn.init import _calculate_correct_fan
__all__ = ["weights_init"]
l... | decodable_information_bottleneck-main | dib/utils/initialization.py |
"""
Copyright (c) Facebook, Inc. and its affiliates.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
"""
import math
import torch
from torch.distributions import Categorical, Independent, Normal
def MultivariateNormalDiag(loc, scale_diag):
... | decodable_information_bottleneck-main | dib/utils/distributions.py |
"""
Copyright (c) Facebook, Inc. and its affiliates.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
"""
import contextlib
import math
import operator
import random
import warnings
from functools import reduce
from itertools import zip_longest
i... | decodable_information_bottleneck-main | dib/utils/helpers.py |
"""
Copyright (c) Facebook, Inc. and its affiliates.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
"""
from functools import partial
import torch.nn as nn
BATCHNORMS = [None, nn.BatchNorm1d, nn.BatchNorm2d, nn.BatchNorm3d]
def get_norm_laye... | decodable_information_bottleneck-main | dib/predefined/helper_layers.py |
"""
Copyright (c) Facebook, Inc. and its affiliates.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
"""
from functools import partial
import torch.nn as nn
from .cnn import get_Cnn
from .mlp import MLP
__all__ = ["get_predefined", "try_get_pr... | decodable_information_bottleneck-main | dib/predefined/predefined.py |
"""
Copyright (c) Facebook, Inc. and its affiliates.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
"""
from .cnn import *
from .imgs import *
from .mlp import *
from .predefined import *
| decodable_information_bottleneck-main | dib/predefined/__init__.py |
"""
Copyright (c) Facebook, Inc. and its affiliates.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
"""
import logging
import warnings
from functools import partial
import numpy as np
import torch
import torch.nn as nn
from torch.nn import func... | decodable_information_bottleneck-main | dib/predefined/cnn.py |
"""
Copyright (c) Facebook, Inc. and its affiliates.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
"""
import logging
import warnings
import numpy as np
import torch
import torch.nn as nn
from skorch.utils import to_numpy
from dib.utils.helpe... | decodable_information_bottleneck-main | dib/predefined/mlp.py |
"""
Copyright (c) Facebook, Inc. and its affiliates.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
"""
from .ib import *
from .img import *
| decodable_information_bottleneck-main | dib/transformers/__init__.py |
"""
Copyright (c) Facebook, Inc. and its affiliates.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
"""
import logging
from functools import partial
import numpy as np
import torch.nn as nn
import torch.nn.functional as F
import torchvision
fr... | decodable_information_bottleneck-main | dib/transformers/img.py |
"""
Copyright (c) Facebook, Inc. and its affiliates.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
"""
import logging
import math
import random
from itertools import zip_longest
import numpy as np
import torch
import torch.nn as nn
import torc... | decodable_information_bottleneck-main | dib/transformers/ib/erm.py |
"""
Copyright (c) Facebook, Inc. and its affiliates.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
"""
from .dib import *
from .erm import *
from .helpers import *
from .vib import *
| decodable_information_bottleneck-main | dib/transformers/ib/__init__.py |
"""
Copyright (c) Facebook, Inc. and its affiliates.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
"""
import copy
import logging
import math
import random
from functools import partial
from itertools import zip_longest
import numpy as np
impo... | decodable_information_bottleneck-main | dib/transformers/ib/dib.py |
"""
Copyright (c) Facebook, Inc. and its affiliates.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
"""
import logging
import math
import random
from itertools import zip_longest
import numpy as np
import torch
import torch.nn as nn
import torc... | decodable_information_bottleneck-main | dib/transformers/ib/vib.py |
"""
Copyright (c) Facebook, Inc. and its affiliates.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
"""
import logging
import numpy as np
import torch
from dib.utils.helpers import mean_p_logits
__all__ = ["BASE_LOG", "N_CORR"]
logger = loggi... | decodable_information_bottleneck-main | dib/transformers/ib/helpers.py |
"""
Copyright (c) Facebook, Inc. and its affiliates.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
"""
from .mcclf import *
| decodable_information_bottleneck-main | dib/classifiers/__init__.py |
"""
Copyright (c) Facebook, Inc. and its affiliates.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
"""
import numpy as np
import torch
import torch.nn as nn
from dib.utils.helpers import mean_p_logits
__all__ = ["MCTrnsfClassifier"]
class M... | decodable_information_bottleneck-main | dib/classifiers/mcclf.py |
"""
Copyright (c) Facebook, Inc. and its affiliates.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
"""
from .data import *
from .evaluate import *
from .train import *
from .visualize import *
| decodable_information_bottleneck-main | utils/__init__.py |
"""
Copyright (c) Facebook, Inc. and its affiliates.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
"""
import logging
import os
import shutil
import skorch
import torch
from skorch.callbacks import EarlyStopping, LoadInitState, ProgressBar
from... | decodable_information_bottleneck-main | utils/train.py |
"""
Copyright (c) Facebook, Inc. and its affiliates.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
"""
import copy
import glob
import logging
import math
import os
from functools import partial, partialmethod
import numpy as np
import pandas a... | decodable_information_bottleneck-main | utils/evaluate.py |
"""
Copyright (c) Facebook, Inc. and its affiliates.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
"""
import collections
import copy
import glob
import logging
import math
import os
import random
import shutil
import types
from collections imp... | decodable_information_bottleneck-main | utils/helpers.py |
"""
Copyright (c) Facebook, Inc. and its affiliates.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
"""
import logging
import sys
import warnings
from collections import defaultdict
import matplotlib.pyplot as plt
import numpy as np
from matplo... | decodable_information_bottleneck-main | utils/visualize/visualize_clf.py |
"""
Copyright (c) Facebook, Inc. and its affiliates.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
"""
from .visualize_clf import *
from .visualize_imgs import *
| decodable_information_bottleneck-main | utils/visualize/__init__.py |
"""
Copyright (c) Facebook, Inc. and its affiliates.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
"""
import numpy as np
# example : https://github.com/matplotlib/matplotlib/issues/7008
def kwargs_log_xscale(x_data, mode="equidistant", base=... | decodable_information_bottleneck-main | utils/visualize/helpers.py |
"""
Copyright (c) Facebook, Inc. and its affiliates.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
"""
import os
import random
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
import numpy as np
import seaborn as sns
import t... | decodable_information_bottleneck-main | utils/visualize/visualize_imgs.py |
"""
Copyright (c) Facebook, Inc. and its affiliates.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
"""
import glob
import logging
import os
import numpy as np
import torch
from PIL import Image
from torch.utils.data import Dataset
from torchvi... | decodable_information_bottleneck-main | utils/data/imgs.py |
"""
Copyright (c) Facebook, Inc. and its affiliates.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
"""
def get_train_dev_test_datasets(dataset, data_type, valid_size=0.1, **kwargs):
"""Return the correct instantiated train, validation, tes... | decodable_information_bottleneck-main | utils/data/__init__.py |
"""
Copyright (c) Facebook, Inc. and its affiliates.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
"""
import os
import numpy as np
import torch
from dib.utils.datasplit import RandomMasker
from dib.utils.helpers import tmp_seed, to_numpy
d... | decodable_information_bottleneck-main | utils/data/helpers.py |
"""
Copyright (c) Facebook, Inc. and its affiliates.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
"""
import copy
import logging
import os
import random
import numpy as np
import torch
from sklearn.model_selection import train_test_split
from... | decodable_information_bottleneck-main | utils/data/base.py |
AVT-main | __init__.py | |
# Copyright (c) Facebook, Inc. and its affiliates.
"""Launch script to run arguments stored in txt files."""
import argparse
import subprocess
import os
import socket
import glob
from omegaconf import OmegaConf
import inquirer
import pathlib
from hydra.core.override_parser.overrides_parser import OverridesParser
from... | AVT-main | launch.py |
# Copyright (c) Facebook, Inc. and its affiliates.
"""Main training entry."""
import os
import logging
import random
import subprocess
import torch
import hydra
from omegaconf import DictConfig, OmegaConf
import func
OmegaConf.register_new_resolver('minus', lambda x, y: x - y)
# Multiply and cast to integer
Omega... | AVT-main | train_net.py |
# Copyright (c) Facebook, Inc. and its affiliates.
"""The Epic Kitchens dataset loaders."""
from typing import List, Dict, Sequence, Tuple, Union
from datetime import datetime, date
from collections import OrderedDict
import pickle as pkl
import csv
import logging
from pathlib import Path
import lmdb
import pandas as... | AVT-main | datasets/epic_kitchens.py |
# Copyright (c) Facebook, Inc. and its affiliates.
"""The base dataset loader."""
from typing import Tuple, Union, Sequence, Dict
import logging
from pathlib import Path
from collections import OrderedDict
import operator
from multiprocessing import Manager
import math
import h5py
import pandas as pd
import numpy as... | AVT-main | datasets/base_video_dataset.py |
# Copyright (c) Facebook, Inc. and its affiliates.
"""Implementation of reader functions."""
import logging
from pathlib import Path
import torch
import torch.nn as nn
import torchvision
from common.utils import get_video_info
# An abstract class to keep track of all reader type classes
class Reader(nn.Module):
... | AVT-main | datasets/reader_fns.py |
AVT-main | datasets/__init__.py | |
# Copyright (c) Facebook, Inc. and its affiliates.
"""The Breakfast/50Salads dataset loader.
"""
from pathlib import Path
import logging
import pandas as pd
from tqdm import tqdm
import gzip
import numpy as np
import torch
import torch.nn as nn
import hydra
from hydra.types import TargetConf
from common.utils impor... | AVT-main | datasets/breakfast_50salads.py |
# Copyright (c) Facebook, Inc. and its affiliates.
import os
import torch
from importlib import import_module
from tqdm import tqdm
import omegaconf
import hydra
from common import utils
__all__ = [
"get_dataset",
]
def get_dataset(dataset_cfg, data_cfg, transform, logger):
# If there is _precomputed_meta... | AVT-main | datasets/data.py |
# Copyright (c) Facebook, Inc. and its affiliates.
"""
Implementation of the future features prediction models.
Input: (B, C)
Output: (B, C)
"""
import torch
import torch.nn as nn
import transformers
import logging
import hydra
from common.cluster import KmeansAssigner
class Identity(nn.Module):
"""Wrap... | AVT-main | models/future_prediction.py |
# Copyright (c) Facebook, Inc. and its affiliates.
"""
Implementation of the temporal aggregation algorithms.
Input: (B, C, T)
Output: (B, C)
"""
import math
import torch
import torch.nn as nn
import logging
import warnings
try:
from external.rulstm.RULSTM.models import RULSTM
except ImportError:
RULS... | AVT-main | models/temporal_aggregation.py |
AVT-main | models/__init__.py | |
# Copyright (c) Facebook, Inc. and its affiliates.
"""
Model architectures.
"""
import torch.nn as nn
from torchvision.models.video.resnet import (
BasicBlock,
Bottleneck,
R2Plus1dStem,
_video_resnet,
)
from pretrainedmodels import bninception
import timm
__all__ = [
'r2plus1d_34',
'r2plus1d_1... | AVT-main | models/video_classification.py |
# Copyright (c) Facebook, Inc. and its affiliates.
"""
The overall base model.
"""
from typing import Dict, Tuple
import operator
import torch
import torch.nn as nn
import hydra
from omegaconf import OmegaConf
CLS_MAP_PREFIX = 'cls_map_'
PAST_LOGITS_PREFIX = 'past_'
class BaseModel(nn.Module):
def __init__(self... | AVT-main | models/base_model.py |
# Copyright (c) Facebook, Inc. and its affiliates.
import torch.nn as nn
class MLP(nn.Module):
def __init__(self, in_features, out_features, nlayers, **kwargs):
super().__init__()
layers = [[nn.Linear(in_features, in_features, **kwargs),
nn.ReLU()] for _ in range(nlayers - 1)]
... | AVT-main | models/classifiers.py |
# Copyright (c) Facebook, Inc. and its affiliates.
import torch
import numbers
import random
from torchvision.transforms import (
RandomCrop,
RandomResizedCrop,
ColorJitter,
ToPILImage,
ToTensor,
)
__all__ = [
"RandomCropVideo",
"RandomResizedCropVideo",
"CenterCropVideo",
"Normal... | AVT-main | common/transforms.py |
# Copyright (c) Facebook, Inc. and its affiliates.
from collections import defaultdict, deque
import datetime
import time
import logging
import torch
import torch.distributed as dist
from common.utils import is_dist_avail_and_initialized, is_main_process
__all__ = [
'SmoothedValue', 'MetricLogger', 'get_default_... | AVT-main | common/log.py |
from .log import *
| AVT-main | common/__init__.py |
# Copyright (c) Facebook, Inc. and its affiliates.
from __future__ import print_function
from typing import List, Dict
import errno
import os
from pathlib import Path
import logging
import submitit
import cv2
import torch
import torch.distributed as dist
def accuracy(output, target, topk=(1, )):
"""Computes th... | AVT-main | common/utils.py |
# Copyright (c) Facebook, Inc. and its affiliates.
import torch
import torch.nn as nn
class KmeansAssigner(nn.Module):
def __init__(self, centroids_fpath, norm=False):
super().__init__()
# NxC dimension
# Not converting this to linear layer as then the weights get
# overwriten dur... | AVT-main | common/cluster.py |
# Copyright (c) Facebook, Inc. and its affiliates.
from typing import Sequence
import torch
from bisect import bisect_right
class WarmupMultiStepLR(torch.optim.lr_scheduler._LRScheduler):
def __init__(
self,
optimizer: torch.optim.Optimizer,
milestone_epochs: Sequence[int],
... | AVT-main | common/scheduler.py |
# Copyright (c) Facebook, Inc. and its affiliates.
import math
import torch
from torch.utils.data import Sampler
import torch.distributed as dist
import torchvision.datasets.video_utils
class DistributedSampler(Sampler):
"""
Extension of DistributedSampler, as discussed in
https://github.com/pytorch/pyto... | AVT-main | common/sampler.py |
AVT-main | external/__init__.py | |
# Copyright (c) Facebook, Inc. and its affiliates.
"""Variants of MSE loss."""
import torch.nn as nn
class NormedMSE(nn.MSELoss):
def forward(self, inp, tgt, *args, **kwargs):
"""
Args:
inp: (*, C)
tgt: (*, C)
Will normalize the input before the loss
""... | AVT-main | loss_fn/mse.py |
AVT-main | loss_fn/__init__.py | |
# Copyright (c) Facebook, Inc. and its affiliates.
"""Cross entropy loss, that works with multi-dim input."""
import torch
import torch.nn as nn
from common.cluster import KmeansAssigner
class MultiDimCrossEntropy(nn.CrossEntropyLoss):
def forward(self, inp, tgt, *args, **kwargs):
"""
Args:
... | AVT-main | loss_fn/multidim_xentropy.py |
# Copyright (c) Facebook, Inc. and its affiliates.
"""The SimCLR InfoNCE loss."""
import torch
import torch.nn as nn
from common import utils
LARGE_NUM = 1e9
class MILCrossEntropyLoss(nn.Module):
def __init__(self, mil_type='sum', reduction='mean'):
super().__init__()
self.mil_type = mil_type
... | AVT-main | loss_fn/simclr_infonce.py |
# Copyright (c) Facebook, Inc. and its affiliates.
"""Utils for notebook."""
import sys
import os
import os.path as osp
import glob
from collections import OrderedDict
from collections.abc import Iterable
import json
import subprocess
import pickle as pkl
import logging
import h5py
import math
import operator
import ... | AVT-main | notebooks/utils.py |
# Copyright (c) Facebook, Inc. and its affiliates.
"""
Modular implementation of the basic train ops
"""
from typing import Dict, Union, Tuple
import torch
import torch.nn as nn
import hydra
from hydra.types import TargetConf
from common import utils
from datasets.base_video_dataset import FUTURE_PREFIX
from models.... | AVT-main | func/train_eval_ops.py |
from . import train
| AVT-main | func/__init__.py |
# Copyright (c) Facebook, Inc. and its affiliates.
"""Training code."""
from typing import Union, Sequence
import datetime
import os
import time
import sys
import logging
import itertools
import operator
import psutil
import h5py
import subprocess
from tqdm import tqdm
import numpy as np
# Need to import this here, ... | AVT-main | func/train.py |
from functools import partial
from types import SimpleNamespace
from typing import Optional, List
import numpy as np
import scipy.optimize
import scipy.special
import sklearn.metrics.pairwise as skmetrics
def Phi(
D: np.ndarray,
edge_list: np.ndarray = None,
):
"""
Given an n x d matrix of (example,... | mandoline-main | mandoline.py |
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
"""
Useful links:
Streamlit cheatsheet:
https://docs.streamlit.io/library/cheatsheet
Also check the components we provide for demos in meta... | controllable_agent-main | demo/main.py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.