python_code
stringlengths
0
4.04M
repo_name
stringlengths
8
58
file_path
stringlengths
5
147
import argparse import collections import functools import itertools import json import multiprocessing as mp import os import pathlib import re import subprocess import warnings os.environ['NO_AT_BRIDGE'] = '1' # Hide X org false warning. import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt impor...
cascade-main
dreamerv2/common/plot.py
import json import pathlib import re class Config(dict): SEP = '.' IS_PATTERN = re.compile(r'.*[^A-Za-z0-9_.-].*') def __init__(self, *args, **kwargs): mapping = dict(*args, **kwargs) mapping = self._flatten(mapping) mapping = self._ensure_keys(mapping) mapping = self._ensure_values(mapping) ...
cascade-main
dreamerv2/common/config.py
import pathlib import pickle import re import numpy as np import tensorflow as tf from tensorflow.keras import mixed_precision as prec try: from tensorflow.python.distribute import values except Exception: from google3.third_party.tensorflow.python.distribute import values tf.tensor = tf.convert_to_tensor for ba...
cascade-main
dreamerv2/common/tfutils.py
import tensorflow as tf import tensorflow_probability as tfp from tensorflow_probability import distributions as tfd # Patch to ignore seed to avoid synchronization across GPUs. _orig_random_categorical = tf.random.categorical def random_categorical(*args, **kwargs): kwargs['seed'] = None return _orig_random_cate...
cascade-main
dreamerv2/common/dists.py
import re import sys class Flags: def __init__(self, *args, **kwargs): from .config import Config self._config = Config(*args, **kwargs) def parse(self, argv=None, known_only=False, help_exists=None): if help_exists is None: help_exists = not known_only if argv is None: argv = sys.ar...
cascade-main
dreamerv2/common/flags.py
import datetime import json import pathlib import imageio import numpy as np class Recorder: def __init__( self, env, directory, save_stats=True, save_video=True, save_episode=True, video_size=(512, 512)): if directory and save_stats: env = StatsRecorder(env, directory) if directory and ...
cascade-main
dreamerv2/common/recorder.py
# General tools. from .config import * from .counter import * from .flags import * from .logger import * from .when import * from .eval import * from .cdmc import * # RL tools. from .other import * from .driver import * from .envs import * from .replay import * # TensorFlow tools. from .tfutils import * from .dists i...
cascade-main
dreamerv2/common/__init__.py
import collections import contextlib import re import time import numpy as np import tensorflow as tf from tensorflow_probability import distributions as tfd from . import dists from . import tfutils class RandomAgent: def __init__(self, act_space, logprob=False): self.act_space = act_space['action'] sel...
cascade-main
dreamerv2/common/other.py
import json import os import pathlib import time import numpy as np class Logger: def __init__(self, step, outputs, multiplier=1): self._step = step self._outputs = outputs self._multiplier = multiplier self._last_step = None self._last_time = None self._metrics = [] def add(self, mappi...
cascade-main
dreamerv2/common/logger.py
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. import collections import datetime import io import pathlib import uuid import numpy as np import tensorflow as tf clas...
cascade-main
dreamerv2/common/replay.py
"""In gym, the RAM is represented as an 128-element array, where each element in the array can range from 0 to 255 The atari_dict below is organized as so: key: the name of the game value: the game dictionary Game dictionary is organized as: key: state variable name value: the element in the RAM array w...
cascade-main
dreamerv2/common/ram_annotations.py
class Every: def __init__(self, every): self._every = every self._last = None def __call__(self, step): step = int(step) if not self._every: return False if self._last is None: self._last = step return True if step >= self._last + self._every: self._last += self._ev...
cascade-main
dreamerv2/common/when.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. from collections import defaultdict from .cdmc import DMC_TASK_IDS import numpy as np from scipy.stats import gmean d...
cascade-main
dreamerv2/common/eval.py
import numpy as np class Driver: def __init__(self, envs, **kwargs): self._envs = envs self._kwargs = kwargs self._on_steps = [] self._on_resets = [] self._on_episodes = [] self._act_spaces = [env.act_space for env in envs] self.reset() def on_step(self, callback): self._on_steps...
cascade-main
dreamerv2/common/driver.py
import functools @functools.total_ordering class Counter: def __init__(self, initial=0): self.value = initial def __int__(self): return int(self.value) def __eq__(self, other): return int(self) == other def __ne__(self, other): return int(self) != other def __lt__(self, other): retu...
cascade-main
dreamerv2/common/counter.py
import re import numpy as np import tensorflow as tf from tensorflow.keras import layers as tfkl from tensorflow_probability import distributions as tfd from tensorflow.keras.mixed_precision import experimental as prec import common class EnsembleRSSM(common.Module): def __init__( self, ensemble=5, stoch=3...
cascade-main
dreamerv2/common/nets.py
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. import collections import os from dm_control import mujoco from dm_control.rl import control from dm_control.suite import...
cascade-main
dreamerv2/common/cdmc/walker.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. from .walker import make_walker from .cheetah import make_cheetah def make_dmc_all(domain, task, task_kwargs=Non...
cascade-main
dreamerv2/common/cdmc/__init__.py
# Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. import collections from dm_control import mujoco from dm_control.rl import control from dm_control.suite import base from...
cascade-main
dreamerv2/common/cdmc/cheetah.py
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved import torch import torchvision from transformers import BertForSequenceClassification, AdamW, get_scheduler class ToyNet(torch.nn.Module): def __init__(self, dim, gammas): super(ToyNet, self).__init__() # gammas is a list of ...
BalancingGroups-main
models.py
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved import argparse import os import re import tarfile from zipfile import ZipFile import logging logging.basicConfig(level=logging.INFO) import gdown import pandas as pd from six import remove_move def download_and_extract(url, dst, remove=True): ...
BalancingGroups-main
setup_datasets.py
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved import os import torch import submitit from itertools import product from train import run_experiment, parse_args def product_dict(**kwargs): keys = kwargs.keys() vals = kwargs.values() for instance in product(*vals): yield di...
BalancingGroups-main
train_toy.py
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved import os import torch import pandas as pd import numpy as np from PIL import Image from torchvision import transforms from transformers import BertTokenizer from torch.utils.data import DataLoader from sklearn.datasets import make_blobs import pa...
BalancingGroups-main
datasets.py
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved import matplotlib from matplotlib.colors import ListedColormap import numpy as np import torch import torch.utils.data from models import ToyNet from parse import parse_json_to_df from datasets import Toy import matplotlib.pyplot as plt from torch ...
BalancingGroups-main
plot_toy_scatter.py
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved #!/usr/bin/env python import os import sys import json import time import torch import submitit import argparse import numpy as np import models from datasets import get_loaders class Tee: def __init__(self, fname, stream, mode="a+"): ...
BalancingGroups-main
train.py
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved #!/usr/bin/env python import os import glob import json import argparse from typing import ContextManager import pandas as pd from pandas.core.indexes import multi import seaborn as sns import matplotlib.pyplot as plt import numpy as np from pathl...
BalancingGroups-main
parse.py
# Copyright (c) 2015-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the CC-by-NC license found in the # LICENSE file in the root directory of this source tree. # from utils.masks import generate_masks, evaluate_masks import torch def train(*args, **kwargs): return {} params =...
calibration_membership-main
api.py
# -*- coding: utf-8 -*- # Copyright (c) 2015-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the CC-by-NC license found in the # LICENSE file in the root directory of this source tree. # import argparse import json import os import sys import inspect currentdir = os.path.dirname(os...
calibration_membership-main
training/image_classification.py
# -*- coding: utf-8 -*- # Copyright (c) 2015-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the CC-by-NC license found in the # LICENSE file in the root directory of this source tree. # import argparse import json import os from models import build_model from datasets import get_...
calibration_membership-main
training/language_modeling.py
calibration_membership-main
training/__init__.py
# Copyright (c) 2015-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the CC-by-NC license found in the # LICENSE file in the root directory of this source tree. # import torch import torchvision import torchvision.transforms as transforms from torch.utils.data import Dataset, Tenso...
calibration_membership-main
datasets/__init__.py
# Copyright (c) 2015-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the CC-by-NC license found in the # LICENSE file in the root directory of this source tree. # import torch class TextIterator: def __init__(self, sequence, batch_size, seq_len): assert sequence.ndim =...
calibration_membership-main
datasets/text_data.py
# Copyright (c) 2015-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the CC-by-NC license found in the # LICENSE file in the root directory of this source tree. # # Taken from https://github.com/facebookresearch/XLM import argparse FALSY_STRINGS = {'off', 'false', '0'} TRUTHY_STRI...
calibration_membership-main
utils/misc.py
# Copyright (c) 2015-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the CC-by-NC license found in the # LICENSE file in the root directory of this source tree. # from datetime import timedelta import logging import re import sys import time class LogFormatter(): def __init_...
calibration_membership-main
utils/logger.py
# Copyright (c) 2015-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the CC-by-NC license found in the # LICENSE file in the root directory of this source tree. # import numpy as np import torch import operator def to_mask(n_data, indices): mask = torch.zeros(n_data, dtype=bo...
calibration_membership-main
utils/masks.py
# Copyright (c) 2015-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the CC-by-NC license found in the # LICENSE file in the root directory of this source tree. # import re import inspect import json import itertools from torch import optim import numpy as np from logging import ge...
calibration_membership-main
utils/optimizer.py
# Copyright (c) 2015-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the CC-by-NC license found in the # LICENSE file in the root directory of this source tree. # from collections import OrderedDict import functools import os import time import numpy as np import torch from torch....
calibration_membership-main
utils/trainer.py
# Copyright (c) 2015-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the CC-by-NC license found in the # LICENSE file in the root directory of this source tree. # from logging import getLogger from collections import OrderedDict import numpy as np import torch from torch.nn import ...
calibration_membership-main
utils/evaluator.py
# Copyright (c) 2015-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the CC-by-NC license found in the # LICENSE file in the root directory of this source tree. # import torch.nn as nn import torch.nn.functional as F class KLLeNet(nn.Module): def __init__(self, params): ...
calibration_membership-main
models/KLlenet.py
# Copyright (c) 2015-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the CC-by-NC license found in the # LICENSE file in the root directory of this source tree. # import torch.nn as nn import torch.nn.functional as F class LinearNet(nn.Module): def __init__(self, params): ...
calibration_membership-main
models/linear.py
# Copyright (c) 2015-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the CC-by-NC license found in the # LICENSE file in the root directory of this source tree. # import torch.nn as nn import torch.nn.functional as F from .lenet import LeNet from .KLlenet import KLLeNet from .lstml...
calibration_membership-main
models/__init__.py
# Copyright (c) 2015-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the CC-by-NC license found in the # LICENSE file in the root directory of this source tree. # import torch.nn as nn import torch.nn.functional as F class MLP(nn.Module): def __init__(self, params): su...
calibration_membership-main
models/mlp.py
# Copyright (c) 2015-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the CC-by-NC license found in the # LICENSE file in the root directory of this source tree. # import torch.nn as nn import torch.nn.functional as F class LeNet(nn.Module): def __init__(self, params): ...
calibration_membership-main
models/lenet.py
# Copyright (c) 2015-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the CC-by-NC license found in the # LICENSE file in the root directory of this source tree. # from opacus.layers import DPLSTM import torch import torch.nn as nn class LSTMLM(nn.Module): def __init__(self, p...
calibration_membership-main
models/lstmlm.py
# Copyright (c) 2015-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the CC-by-NC license found in the # LICENSE file in the root directory of this source tree. # import torch import torch.nn as nn class AlexNet(nn.Module): def __init__(self, params): super(AlexNet, s...
calibration_membership-main
models/alexnet.py
calibration_membership-main
attacks/__init__.py
# Copyright (c) 2015-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the CC-by-NC license found in the # LICENSE file in the root directory of this source tree. # import os from posixpath import join import sys import inspect import math from random import randrange import pickle ...
calibration_membership-main
attacks/privacy_attacks.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 hydra from hydra.utils import instantiate import logging from overlap.train_net import train_net from overlap.test_net import test_net ...
augmentation-corruption-fbr_main
experiments/closest_augs.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 hydra from hydra.utils import instantiate import logging from overlap.train_net import train_net from overlap.test_net import test_net ...
augmentation-corruption-fbr_main
experiments/test_imagenet.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 argparse import overlap.utils.logging as lu import decimal import simplejson import numpy as np import omegaconf from itertoo...
augmentation-corruption-fbr_main
experiments/sample_datasets.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 hydra from hydra.utils import instantiate import logging from overlap.train_net_jsd import train_net from overlap.test_net import test_...
augmentation-corruption-fbr_main
experiments/train_imagenet_jsd.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 argparse parser = argparse.ArgumentParser(description="Calculate corruptions distance "\ "to the ...
augmentation-corruption-fbr_main
experiments/calc_distance_shifts.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 hydra from hydra.utils import instantiate import logging from overlap.train_net import train_net from overlap.test_net import test_net ...
augmentation-corruption-fbr_main
experiments/severity_scan_imagenet.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 hydra from hydra.utils import instantiate import logging from overlap.train_net_jsd import train_net from overlap.test_net import test_...
augmentation-corruption-fbr_main
experiments/train_cifar10_jsd.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 hydra from hydra.utils import instantiate import logging from overlap.train_net import train_net from overlap.test_net import test_net ...
augmentation-corruption-fbr_main
experiments/feature_corrupt_error.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 hydra from hydra.utils import instantiate import logging from overlap.train_net import train_net from overlap.test_net import test_net ...
augmentation-corruption-fbr_main
experiments/severity_scan.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 hydra from hydra.utils import instantiate import logging from overlap.train_net import train_net from overlap.test_net import test_net ...
augmentation-corruption-fbr_main
experiments/test_cifar10.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 hydra from hydra.utils import instantiate import logging from overlap.train_net import train_net from overlap.test_net import test_net ...
augmentation-corruption-fbr_main
experiments/train_imagenet.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 hydra from hydra.utils import instantiate import logging from overlap.train_net import train_net from overlap.test_net import test_net ...
augmentation-corruption-fbr_main
experiments/train_cifar10.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 argparse import overlap.utils.logging as lu import decimal import simplejson import numpy as np import omegaconf from itertoo...
augmentation-corruption-fbr_main
experiments/tools/get_target_error.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 argparse import overlap.utils.logging as lu import decimal import simplejson import numpy as np import omegaconf parser = ar...
augmentation-corruption-fbr_main
experiments/tools/summarize.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 argparse parser = argparse.ArgumentParser(description="Generate random indicies '\ 'for sampling from the C...
augmentation-corruption-fbr_main
experiments/tools/sample_image_indices.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 torch import logging from .utils import logging as lu from omegaconf import open_dict from .augmentations.utils import aug_finder from...
augmentation-corruption-fbr_main
experiments/overlap/test_corrupt_net.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 torch import logging from .utils import logging as lu log = logging.getLogger(__name__) def test_net(model, test_dataset, batch_size,...
augmentation-corruption-fbr_main
experiments/overlap/test_net.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 import torch.nn as nn import torch.nn.functional as F class ResHead(nn.Module): """ResNet head.""" def __in...
augmentation-corruption-fbr_main
experiments/overlap/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 torch import logging from .utils import logging as lu import numpy as np import os log = logging.getLogger(__name__) def distributed_...
augmentation-corruption-fbr_main
experiments/overlap/extract_features.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 . import augmentations as aug from .augmentations.utils.converters import NumpyToTensor, PilToNumpy from .augmentations.utils.aug_finder ...
augmentation-corruption-fbr_main
experiments/overlap/datasets.py
augmentation-corruption-fbr_main
experiments/overlap/__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 torch import logging import os import time import datetime import torch.nn as nn import torch.nn.functional as F log = logging.getLogg...
augmentation-corruption-fbr_main
experiments/overlap/train_net_jsd.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 torch import numpy as np from hydra.utils import instantiate from .train_net import train_net class Network(object): def __in...
augmentation-corruption-fbr_main
experiments/overlap/feature_extractor.py
# This source code is adapted from code licensed under the MIT license # found in third_party/wideresnet_license from the root directory of # this source tree. """WideResNet implementation (https://arxiv.org/abs/1605.07146).""" import math import torch import torch.nn as nn import torch.nn.functional as F class Bas...
augmentation-corruption-fbr_main
experiments/overlap/wideresnet.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 torch import logging import os import time import datetime log = logging.getLogger(__name__) def eta_str(eta_td): """Converts an ...
augmentation-corruption-fbr_main
experiments/overlap/train_net.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 simplejson import decimal import logging log = logging.getLogger(__name__) _TAG = 'json_stats: ' def log_json_stats(stats): """Lo...
augmentation-corruption-fbr_main
experiments/overlap/utils/logging.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 class Cosine(object): def __init__(self, base_lr, max_epoch): self.base_lr = base_lr self.max_epoch = ...
augmentation-corruption-fbr_main
experiments/overlap/utils/lr_policy.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 .base import Augmentation from scipy.ndimage import gaussian_filter from .utils.severity import float_parameter, int_parameter, sample_le...
augmentation-corruption-fbr_main
experiments/overlap/augmentations/distortion.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 .base import Augmentation from .utils.image import bilinear_interpolation from .utils.severity import float_parameter, int_parameter, sam...
augmentation-corruption-fbr_main
experiments/overlap/augmentations/blurs.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 .base import Augmentation from math import floor, ceil import numpy as np class Gaussian(Augmentation): name = 'pg_gaussian' tag...
augmentation-corruption-fbr_main
experiments/overlap/augmentations/patch_gaussian.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 .base import Augmentation import numpy as np from .utils.severity import int_parameter, float_parameter, sample_level from .utils.image i...
augmentation-corruption-fbr_main
experiments/overlap/augmentations/color.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 . import identity from . import base from . import pil from . import obscure from . import additive_noise from . import color from . impo...
augmentation-corruption-fbr_main
experiments/overlap/augmentations/__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 .base import Augmentation from .utils.severity import float_parameter, int_parameter, sample_level from .utils.image import smoothstep fr...
augmentation-corruption-fbr_main
experiments/overlap/augmentations/additive_noise.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 .base import Augmentation import numpy as np class Cifar10CropAndFlip(Augmentation): def sample_parameters(self): crop_pos ...
augmentation-corruption-fbr_main
experiments/overlap/augmentations/standard_augmentations.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 .base import Augmentation from .utils.severity import float_parameter, int_parameter, sample_level from PIL import Image, ImageOps, Imag...
augmentation-corruption-fbr_main
experiments/overlap/augmentations/pil.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 math import floor, ceil import numpy as np from .base import Augmentation from .utils.severity import int_parameter, sample_level, float_...
augmentation-corruption-fbr_main
experiments/overlap/augmentations/obscure.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 .base import Augmentation class Identity(Augmentation): tags = ["identity"] name = ['identity'] def __init__(self, severit...
augmentation-corruption-fbr_main
experiments/overlap/augmentations/identity.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 .base import Augmentation from collections import namedtuple import numpy as np class Augmix(Augmentation): tags = ['compositor', '...
augmentation-corruption-fbr_main
experiments/overlap/augmentations/compositions.py
# This source code is adapted from code licensed under the license at # third_party/imagenetc_license from the root directory of the repository # Originally available: github.com/hendrycks/robustness # Modifications Copyright (c) Facebook, Inc. and its affiliates, # licensed under the MIT license found in the LICENSE...
augmentation-corruption-fbr_main
experiments/overlap/augmentations/imagenetc.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 abc import numpy as np def is_iterable(obj): try: iter(obj) except: return False else: return Tru...
augmentation-corruption-fbr_main
experiments/overlap/augmentations/base.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 def int_parameter(level, maxval): return int(level * maxval / 10) def float_parameter(level, maxval): return float(l...
augmentation-corruption-fbr_main
experiments/overlap/augmentations/utils/severity.py
augmentation-corruption-fbr_main
experiments/overlap/augmentations/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. from ... import augmentations as aug master_aug_list = [ aug.pil.AutoContrast, aug.pil.Equalize, aug.pil.Posterize, aug.pil.S...
augmentation-corruption-fbr_main
experiments/overlap/augmentations/utils/aug_finder.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 class PerlinNoiseGenerator(object): def __init__(self, random_state=None): self.rand = np.random if random_sta...
augmentation-corruption-fbr_main
experiments/overlap/augmentations/utils/noise.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 from PIL import Image import torch class PilToNumpy(object): def __init__(self, as_float=False, scaled_to_one=False): ...
augmentation-corruption-fbr_main
experiments/overlap/augmentations/utils/converters.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 def smoothstep(low, high, x): x = np.clip(x, low, high) x = (x - low) / (high - low) return np.clip(3 * (x ** ...
augmentation-corruption-fbr_main
experiments/overlap/augmentations/utils/image.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 transform_finder import build_transform import torch import torchvision as tv from utils.converters import PilToNumpy, NumpyToTensor CIF...
augmentation-corruption-fbr_main
imagenet_c_bar/test_c_bar.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 corrupt as corr transform_list = [ corr.ColorBalance, corr.QuadrilateralNoBars, corr.PerspectiveNoBars, corr.SingleFre...
augmentation-corruption-fbr_main
imagenet_c_bar/transform_finder.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 argparse import torchvision as tv from transform_finder import build_transform from utils.converters import PilToNumpy, NumpyToPil impo...
augmentation-corruption-fbr_main
imagenet_c_bar/make_imagenet_c_bar.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 from math import floor, ceil from PIL import Image from scipy.fftpack import ifft2 from scipy.ndimage import gaussian_filt...
augmentation-corruption-fbr_main
imagenet_c_bar/corrupt.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 argparse import torchvision as tv from transform_finder import build_transform from utils.converters import PilToNumpy, NumpyToPil impo...
augmentation-corruption-fbr_main
imagenet_c_bar/make_cifar10_c_bar.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 abc import numpy as np def is_iterable(obj): try: iter(obj) except: return False else: return Tru...
augmentation-corruption-fbr_main
imagenet_c_bar/base.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 from PIL import Image import torch class PilToNumpy(object): def __init__(self, as_float=False, scaled_to_one=False): ...
augmentation-corruption-fbr_main
imagenet_c_bar/utils/converters.py